添加获取风格文件内容 方法

This commit is contained in:
zhishi 2026-03-29 20:23:00 +08:00
parent 915bb4688f
commit 676f205c6c
3 changed files with 97 additions and 4 deletions

View File

@ -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;

View File

@ -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
View 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);
}
}
}