修正获取skill
This commit is contained in:
parent
b32017d669
commit
78f085709b
@ -28,43 +28,55 @@ export default router.post(
|
|||||||
if (search) {
|
if (search) {
|
||||||
const searchPattern = `%${search}%`;
|
const searchPattern = `%${search}%`;
|
||||||
const whereBuilder = (builder: any) => {
|
const whereBuilder = (builder: any) => {
|
||||||
builder.where("name", "like", searchPattern).orWhere("path", "like", searchPattern).orWhere("description", "like", searchPattern);
|
builder
|
||||||
|
.where("name", "like", searchPattern)
|
||||||
|
.orWhere("path", "like", searchPattern)
|
||||||
|
.orWhere("description", "like", searchPattern);
|
||||||
};
|
};
|
||||||
query = query.where(whereBuilder);
|
query = query.where(whereBuilder);
|
||||||
countQuery = countQuery.where(whereBuilder);
|
countQuery = countQuery.where(whereBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询总数
|
// type 筛选条件
|
||||||
const [{ count }]: any = await countQuery.count("* as count");
|
|
||||||
|
|
||||||
// 查询列表
|
|
||||||
if (type) {
|
if (type) {
|
||||||
query = query.where("type", type);
|
query = query.where("type", type);
|
||||||
countQuery = countQuery.where("type", type);
|
countQuery = countQuery.where("type", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attributions 筛选条件
|
||||||
if (attributions && attributions.length > 0) {
|
if (attributions && attributions.length > 0) {
|
||||||
query = query.whereIn("id", function () {
|
const attributionSubQuery = function (this: any) {
|
||||||
this.select("skillId").from("o_skillAttribution").whereIn("attribution", attributions);
|
this.select("skillId")
|
||||||
});
|
.from("o_skillAttribution")
|
||||||
countQuery = countQuery.whereIn("id", function () {
|
.whereIn("attribution", attributions);
|
||||||
this.select("skillId").from("o_skillAttribution").whereIn("attribution", attributions);
|
};
|
||||||
});
|
query = query.whereIn("id", attributionSubQuery);
|
||||||
|
countQuery = countQuery.whereIn("id", attributionSubQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询总数(在所有筛选条件应用后)
|
||||||
|
const [{ count }]: any = await countQuery.count("* as count");
|
||||||
|
|
||||||
|
// 查询列表
|
||||||
const list = await query
|
const list = await query
|
||||||
.select("*")
|
.select("*")
|
||||||
.orderByRaw(`
|
.orderByRaw(
|
||||||
|
`
|
||||||
CASE type WHEN 'main' THEN 1 ELSE 0 END ASC,
|
CASE type WHEN 'main' THEN 1 ELSE 0 END ASC,
|
||||||
CASE WHEN id NOT IN (SELECT skillId FROM o_skillAttribution) THEN 0 ELSE 1 END ASC,
|
CASE WHEN id NOT IN (SELECT skillId FROM o_skillAttribution) THEN 0 ELSE 1 END ASC,
|
||||||
CASE WHEN state = 1 THEN 1 ELSE 0 END ASC,
|
CASE WHEN state = 1 THEN 1 ELSE 0 END ASC,
|
||||||
updateTime DESC
|
updateTime DESC
|
||||||
`)
|
`
|
||||||
|
)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset);
|
.offset(offset);
|
||||||
|
|
||||||
// 查询每个技能的归属
|
// 查询每个技能的归属
|
||||||
const skillIds = list.map((item: any) => item.id);
|
const skillIds = list.map((item: any) => item.id);
|
||||||
const attributionsList = await u.db("o_skillAttribution").whereIn("skillId", skillIds).select("skillId", "attribution");
|
const attributionsList = await u
|
||||||
|
.db("o_skillAttribution")
|
||||||
|
.whereIn("skillId", skillIds)
|
||||||
|
.select("skillId", "attribution");
|
||||||
|
|
||||||
// 将归属信息合并到列表中
|
// 将归属信息合并到列表中
|
||||||
const attributionMap = new Map<string, string[]>();
|
const attributionMap = new Map<string, string[]>();
|
||||||
@ -75,6 +87,9 @@ export default router.post(
|
|||||||
attributionMap.get(attr.skillId!)!.push(attr.attribution!);
|
attributionMap.get(attr.skillId!)!.push(attr.attribution!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录需要更新state的技能id
|
||||||
|
const missingFileIds: string[] = [];
|
||||||
|
|
||||||
const listWithAttributions = list.map((item: any) => {
|
const listWithAttributions = list.map((item: any) => {
|
||||||
const normalizedPath = (item.path || "").replace(/\\/g, "/");
|
const normalizedPath = (item.path || "").replace(/\\/g, "/");
|
||||||
const isPrefixedReferencePath = normalizedPath.startsWith("references/");
|
const isPrefixedReferencePath = normalizedPath.startsWith("references/");
|
||||||
@ -83,19 +98,41 @@ export default router.post(
|
|||||||
? path.join(u.getPath(["skills", "references"]), item.path!)
|
? path.join(u.getPath(["skills", "references"]), item.path!)
|
||||||
: path.join(u.getPath("skills"), item.path!);
|
: path.join(u.getPath("skills"), item.path!);
|
||||||
|
|
||||||
|
let content = "";
|
||||||
|
let state = item.state;
|
||||||
|
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (fs.existsSync(skillFilePath)) {
|
||||||
|
content = fs.readFileSync(skillFilePath, "utf-8");
|
||||||
|
} else {
|
||||||
|
state = -1;
|
||||||
|
if (item.state !== -1) {
|
||||||
|
missingFileIds.push(item.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
|
state,
|
||||||
attributions: attributionMap.get(item.id) || [],
|
attributions: attributionMap.get(item.id) || [],
|
||||||
content: fs.readFileSync(skillFilePath, "utf-8"),
|
content,
|
||||||
embedding: item.embedding ? true : false,
|
embedding: item.embedding ? true : false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 批量更新文件不存在的技能状态
|
||||||
|
if (missingFileIds.length > 0) {
|
||||||
|
await u
|
||||||
|
.db("o_skillList")
|
||||||
|
.whereIn("id", missingFileIds)
|
||||||
|
.update({ state: -1 });
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).send(
|
res.status(200).send(
|
||||||
success({
|
success({
|
||||||
list: listWithAttributions,
|
list: listWithAttributions,
|
||||||
total: Number(count),
|
total: Number(count),
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
24
src/types/database.d.ts
vendored
24
src/types/database.d.ts
vendored
@ -1,25 +1,6 @@
|
|||||||
// @db-hash ce28b6d566911952421c2661e14bfde5
|
// @db-hash d807205fbb27fc5ddb04cae060fb4430
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
export interface _o_storyboard_old_20260325 {
|
|
||||||
'camera'?: string | null;
|
|
||||||
'createTime'?: number | null;
|
|
||||||
'description'?: string | null;
|
|
||||||
'duration'?: string | null;
|
|
||||||
'filePath'?: string | null;
|
|
||||||
'frameMode'?: string | null;
|
|
||||||
'id'?: number;
|
|
||||||
'lines'?: string | null;
|
|
||||||
'mode'?: string | null;
|
|
||||||
'model'?: string | null;
|
|
||||||
'prompt'?: string | null;
|
|
||||||
'reason'?: string | null;
|
|
||||||
'resolution'?: string | null;
|
|
||||||
'scriptId'?: number | null;
|
|
||||||
'sound'?: string | null;
|
|
||||||
'state'?: string | null;
|
|
||||||
'title'?: string | null;
|
|
||||||
}
|
|
||||||
export interface memories {
|
export interface memories {
|
||||||
'content': string;
|
'content': string;
|
||||||
'createTime': number;
|
'createTime': number;
|
||||||
@ -127,11 +108,13 @@ export interface o_project {
|
|||||||
'artStyle'?: string | null;
|
'artStyle'?: string | null;
|
||||||
'createTime'?: number | null;
|
'createTime'?: number | null;
|
||||||
'id'?: number | null;
|
'id'?: number | null;
|
||||||
|
'imageModel'?: string | null;
|
||||||
'intro'?: string | null;
|
'intro'?: string | null;
|
||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'projectType'?: string | null;
|
'projectType'?: string | null;
|
||||||
'type'?: string | null;
|
'type'?: string | null;
|
||||||
'userId'?: number | null;
|
'userId'?: number | null;
|
||||||
|
'videoModel'?: string | null;
|
||||||
'videoRatio'?: string | null;
|
'videoRatio'?: string | null;
|
||||||
}
|
}
|
||||||
export interface o_script {
|
export interface o_script {
|
||||||
@ -237,7 +220,6 @@ export interface o_videoConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DB {
|
export interface DB {
|
||||||
"_o_storyboard_old_20260325": _o_storyboard_old_20260325;
|
|
||||||
"memories": memories;
|
"memories": memories;
|
||||||
"o_agentDeploy": o_agentDeploy;
|
"o_agentDeploy": o_agentDeploy;
|
||||||
"o_agentWorkData": o_agentWorkData;
|
"o_agentWorkData": o_agentWorkData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user