diff --git a/src/types/database.d.ts b/src/types/database.d.ts index 735f17d..4544078 100644 --- a/src/types/database.d.ts +++ b/src/types/database.d.ts @@ -1,18 +1,12 @@ -// @db-hash e24c7c99757472b92af11f26a2b2b8c7 +// @db-hash f7bc2fdb80756d5536929eb47155578b //该文件由脚本自动生成,请勿手动修改 -export interface _o_project_old_20260328 { - 'artStyle'?: string | null; +export interface _o_script_old_20260327 { + 'content'?: string | null; 'createTime'?: number | null; - 'id'?: number | null; - 'imageModel'?: string | null; - 'intro'?: string | null; + 'id'?: number; 'name'?: string | null; - 'projectType'?: string | null; - 'type'?: string | null; - 'userId'?: number | null; - 'videoModel'?: string | null; - 'videoRatio'?: string | null; + 'projectId'?: number | null; } export interface memories { 'content': string; @@ -60,7 +54,6 @@ export interface o_assets { 'name'?: string | null; 'projectId'?: number | null; 'prompt'?: string | null; - 'promptState'?: string | null; 'remark'?: string | null; 'scriptId'?: number | null; 'startTime'?: number | null; @@ -180,7 +173,7 @@ export interface o_storyboard { 'filePath'?: string | null; 'frameMode'?: string | null; 'id'?: number; - 'index'?: number | null; + 'index'?: string | null; 'lines'?: string | null; 'mode'?: string | null; 'model'?: string | null; @@ -245,7 +238,7 @@ export interface o_videoConfig { } export interface DB { - "_o_project_old_20260328": _o_project_old_20260328; + "_o_script_old_20260327": _o_script_old_20260327; "memories": memories; "o_agentDeploy": o_agentDeploy; "o_agentWorkData": o_agentWorkData; diff --git a/src/utils.ts b/src/utils.ts index da89cc9..c7a584d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,6 +9,7 @@ import vm from "@/utils/vm"; import task from "@/utils/taskRecord"; import Ai from "@/utils/ai"; import { getPrompts } from "@/utils/getPrompts"; +import { getArtPrompt } from "@/utils/getArtPrompt"; export default { db, @@ -22,4 +23,5 @@ export default { Ai, task, getPrompts, + getArtPrompt, }; diff --git a/src/utils/getArtPrompt.ts b/src/utils/getArtPrompt.ts new file mode 100644 index 0000000..08b0782 --- /dev/null +++ b/src/utils/getArtPrompt.ts @@ -0,0 +1,84 @@ +import fs from "fs"; +import path from "path"; +import getPath from "./getPath"; + +/** + * 传入一个指定路径参数(风格名称),以及一个指定文件名,递归获取该文件并返回其内容 + * @param styleName - 风格目录名,例如 "chinese_sweet_romance" + * @param fileName - 目标文件名(不含 .md 后缀),例如 "art_character"、"prefix" + * @returns 文件内容字符串,未找到时返回空字符串 + */ +export function getArtPrompt(styleName: string, fileName: string): string { + const baseDir = getPath(["skills", "art_prompts", styleName]); + + if (!fs.existsSync(baseDir)) { + return ""; + } + + const target = fileName.endsWith(".md") ? fileName : `${fileName}.md`; + const found = findFileRecursive(baseDir, target); + + if (!found) { + return ""; + } + + return fs.readFileSync(found, "utf-8"); +} +/** + * 传入风格目录名,获取该风格下所有 .md 文件内容,按文件名映射返回 + * @param styleName - 风格目录名,例如 "chinese_sweet_romance" + * @returns Record<文件名(不含后缀), 文件内容> + */ +export function getAllArtPrompts(styleName: string): Record { + const baseDir = getPath(["skills", "art_prompts", styleName]); + + if (!fs.existsSync(baseDir)) { + return {}; + } + + const result: Record = {}; + collectMdFiles(baseDir, result); + return result; +} + +/** + * 递归查找指定文件名的文件,返回第一个匹配的完整路径 + */ +function findFileRecursive(dir: string, targetName: string): string | null { + const entries = fs.readdirSync(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + + if (entry.isFile() && entry.name === targetName) { + return fullPath; + } + + if (entry.isDirectory()) { + const found = findFileRecursive(fullPath, targetName); + if (found) return found; + } + } + + return null; +} + +/** + * 递归收集目录下所有 .md 文件内容 + */ +function collectMdFiles(dir: string, result: Record): void { + const entries = fs.readdirSync(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + + if (entry.isFile() && entry.name.endsWith(".md")) { + const key = entry.name.replace(/\.md$/, ""); + result[key] = fs.readFileSync(fullPath, "utf-8"); + } + + if (entry.isDirectory()) { + collectMdFiles(fullPath, result); + } + } +}