diff --git a/package.json b/package.json index 60e5cf8..33dd485 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "typescript": "4.9", "vite": "4.3.1", "vite-plugin-html": "3.2.0", - "vite-plugin-progress": "^0.0.6" + "vite-plugin-progress": "^0.0.6", + "xlsx-js-style": "^1.2.0" }, "dependencies": { "@fontsource/fira-code": "4.5.13", diff --git a/src/Compoents/PromptEditor/Lib/DatabaseServer/DatabaseServer.ts b/src/Compoents/PromptEditor/Lib/DatabaseServer/DatabaseServer.ts index 87273d3..b998581 100644 --- a/src/Compoents/PromptEditor/Lib/DatabaseServer/DatabaseServer.ts +++ b/src/Compoents/PromptEditor/Lib/DatabaseServer/DatabaseServer.ts @@ -1,4 +1,5 @@ import { fetchFromNotion } from "./lib/fetchFromNotion" +import XLSX from "xlsx-js-style" export interface IPromptDefineItem { text: string @@ -22,10 +23,42 @@ export class DatabaseServer { return this.isReady } async init() { - // localJson - let localPromptDescMap = await (await fetch("./localPromptDefineMap.json")).json() - // console.log('localPromptDescMap',localPromptDescMap) - this.localPromptDefineMap = localPromptDescMap + let buffer = await (await fetch("./prompt.xlsx")).arrayBuffer() + let workbook = XLSX.read(new Uint8Array(buffer), { type: "array" }), + subTypeMap:any = { + 角色: "character", + 风格: "style", + 质量: "quality", + 命令: "command", + 负面: "eg", + }, + sheetNameList = workbook.SheetNames, + mapDict:any = {} + + sheetNameList.forEach((sheetName) => { + let subTypeName = sheetName.replace(/[-\.].*/, ""), + subType = subTypeMap[subTypeName]; + if (!subType) { + console.log(`遇到无对应 subType 的 Sheet: "${sheetName}", 跳过`) + return; //如果sheet不是以subType名字开头的话,就跳过 + } + console.log(`已经读入 ${sheetName}" 对应 ${subType} 类型`) + let ws:any = workbook.Sheets[sheetName], + lenth = XLSX.utils.decode_range(ws["!ref"]).e.r //How much lines of this sheet + Array.from(Array(lenth), (_, i) => i + 2).forEach((id) => { + if (ws[`A${id}`]) { + let prompt:any = { text: ws[`A${id}`].v, dir: `${subTypeName}/未知` } //text + ws[`B${id}`] && (prompt.lang_zh = ws[`B${id}`].v) //lang_zh + prompt.subType = subType //subType + ws[`E${id}`] && (prompt.desc = ws[`E${id}`].v) //desc + ws[`D${id}`] && (prompt.sampleCmds = JSON.parse(ws[`D${id}`].v)) //sampleCmds + ws[`C${id}`] && (prompt.dir = `${subTypeName}/${ws[`C${id}`].v}`) //dir + mapDict[ws[`A${id}`].v.toLowerCase()] = prompt + } + }) + }) + + this.localPromptDefineMap = mapDict return true } async queryPromptsDefine(prompts: string[]): Promise { diff --git a/web/public/prompt.xlsx b/web/public/prompt.xlsx new file mode 100644 index 0000000..21ef050 Binary files /dev/null and b/web/public/prompt.xlsx differ