添加获取风格文件内容 方法
This commit is contained in:
parent
915bb4688f
commit
676f205c6c
15
src/types/database.d.ts
vendored
15
src/types/database.d.ts
vendored
@ -1,6 +1,13 @@
|
||||
// @db-hash 93b2462070c45c2b449e9a18c4e88763
|
||||
// @db-hash f7bc2fdb80756d5536929eb47155578b
|
||||
//该文件由脚本自动生成,请勿手动修改
|
||||
|
||||
export interface _o_script_old_20260327 {
|
||||
'content'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
}
|
||||
export interface memories {
|
||||
'content': string;
|
||||
'createTime': number;
|
||||
@ -21,7 +28,7 @@ export interface o_agentDeploy {
|
||||
'model'?: string | null;
|
||||
'modelName'?: string | null;
|
||||
'name'?: string | null;
|
||||
'vendorId'?: string | null;
|
||||
'vendorId'?: number | null;
|
||||
}
|
||||
export interface o_agentWorkData {
|
||||
'createTime'?: number | null;
|
||||
@ -47,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;
|
||||
@ -167,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;
|
||||
@ -232,6 +238,7 @@ export interface o_videoConfig {
|
||||
}
|
||||
|
||||
export interface DB {
|
||||
"_o_script_old_20260327": _o_script_old_20260327;
|
||||
"memories": memories;
|
||||
"o_agentDeploy": o_agentDeploy;
|
||||
"o_agentWorkData": o_agentWorkData;
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
84
src/utils/getArtPrompt.ts
Normal file
84
src/utils/getArtPrompt.ts
Normal file
@ -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<string, string> {
|
||||
const baseDir = getPath(["skills", "art_prompts", styleName]);
|
||||
|
||||
if (!fs.existsSync(baseDir)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const result: Record<string, string> = {};
|
||||
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<string, string>): 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user