Merge branch 'develop' of https://github.com/HBAI-Ltd/Toonflow-app into develop
# Conflicts: # src/router.ts
This commit is contained in:
commit
cb6557c2d7
@ -227,6 +227,16 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
table.unique(["id"]);
|
table.unique(["id"]);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "t_aiModelMap",
|
||||||
|
builder: (table) => {
|
||||||
|
table.integer("id").notNullable();
|
||||||
|
table.integer("promptsId"); // 提示词表ID
|
||||||
|
table.integer("configId"); // 模型列表id
|
||||||
|
table.primary(["id"]);
|
||||||
|
table.unique(["id"]);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "t_prompts",
|
name: "t_prompts",
|
||||||
builder: (table) => {
|
builder: (table) => {
|
||||||
|
|||||||
33
src/routes/setting/addModel.ts
Normal file
33
src/routes/setting/addModel.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
type: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
model: z.string(),
|
||||||
|
baseUrl: z.string(),
|
||||||
|
apiKey: z.string(),
|
||||||
|
manufacturer: z.string(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { type, name, model, baseUrl, apiKey, manufacturer } = req.body;
|
||||||
|
|
||||||
|
await u.db("t_config").insert({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
model,
|
||||||
|
baseUrl,
|
||||||
|
apiKey,
|
||||||
|
manufacturer,
|
||||||
|
createTime: Date.now(),
|
||||||
|
userId: 1,
|
||||||
|
});
|
||||||
|
res.status(200).send(success("新增成功"));
|
||||||
|
},
|
||||||
|
);
|
||||||
30
src/routes/setting/configurationModel.ts
Normal file
30
src/routes/setting/configurationModel.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
id: z.number().optional(),
|
||||||
|
promptsId: z.number(),
|
||||||
|
configId: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { id, promptsId, configId } = req.body;
|
||||||
|
if (id) {
|
||||||
|
await u.db("t_aiModelMap").where("id", id).update({
|
||||||
|
promptsId,
|
||||||
|
configId,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await u.db("t_aiModelMap").insert({
|
||||||
|
promptsId,
|
||||||
|
configId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200).send(success("配置成功"));
|
||||||
|
},
|
||||||
|
);
|
||||||
19
src/routes/setting/delModel.ts
Normal file
19
src/routes/setting/delModel.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
id: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { id } = req.body;
|
||||||
|
await u.db("t_config").where("id", id).delete();
|
||||||
|
await u.db("t_aiModelMap").where("configId", id).delete();
|
||||||
|
res.status(200).send(success("删除成功"));
|
||||||
|
},
|
||||||
|
);
|
||||||
13
src/routes/setting/getAiModelMap.ts
Normal file
13
src/routes/setting/getAiModelMap.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post("/", async (req, res) => {
|
||||||
|
const configData = await u
|
||||||
|
.db("t_prompts")
|
||||||
|
.leftJoin("t_aiModelMap", "t_prompts.id", "t_aiModelMap.promptsId")
|
||||||
|
.leftJoin("t_config", "t_config.id", "t_aiModelMap.configId")
|
||||||
|
.select("t_prompts.id as promptsId", "t_prompts.code", "t_prompts.name", "t_config.model", "t_aiModelMap.id");
|
||||||
|
res.status(200).send(success(configData));
|
||||||
|
});
|
||||||
@ -1,29 +1,11 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import u from "@/utils";
|
import u from "@/utils";
|
||||||
import { z } from "zod";
|
|
||||||
import { success } from "@/lib/responseFormat";
|
import { success } from "@/lib/responseFormat";
|
||||||
import { validateFields } from "@/middleware/middleware";
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
export default router.post(
|
export default router.post("/", async (req, res) => {
|
||||||
"/",
|
const userId = 1;
|
||||||
validateFields({
|
|
||||||
userId: z.number(),
|
|
||||||
}),
|
|
||||||
async (req, res) => {
|
|
||||||
const { userId } = req.body;
|
|
||||||
|
|
||||||
const settingData = await u.db("t_setting").select("*");
|
|
||||||
|
|
||||||
const configData = await u.db("t_config").where("userId", userId).select("*");
|
const configData = await u.db("t_config").where("userId", userId).select("*");
|
||||||
|
|
||||||
const parsedData = settingData.map((item) => ({
|
res.status(200).send(success(configData));
|
||||||
...item,
|
});
|
||||||
imageModel: configData.find((i) => i.type == "image"),
|
|
||||||
languageModel: configData.find((i) => i.type == "text"),
|
|
||||||
videoModel: configData.filter((i) => i.type == "video").filter(Boolean),
|
|
||||||
}));
|
|
||||||
|
|
||||||
res.status(200).send(success(parsedData));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|||||||
@ -1,79 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
import u from "@/utils";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { success } from "@/lib/responseFormat";
|
|
||||||
import { validateFields } from "@/middleware/middleware";
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
// 修改全局配置
|
|
||||||
export default router.post(
|
|
||||||
"/",
|
|
||||||
validateFields({
|
|
||||||
userId: z.number(),
|
|
||||||
imageModel: z.object().optional(),
|
|
||||||
videoModel: z.array(z.object()).optional(),
|
|
||||||
languageModel: z.object().optional(),
|
|
||||||
name: z.string().optional(),
|
|
||||||
password: z.string().optional(),
|
|
||||||
}),
|
|
||||||
async (req, res) => {
|
|
||||||
const { userId, imageModel, videoModel, languageModel, name, password } = req.body;
|
|
||||||
|
|
||||||
await u
|
|
||||||
.db("t_setting")
|
|
||||||
.where("userId", userId)
|
|
||||||
.update({
|
|
||||||
imageModel: JSON.stringify(imageModel),
|
|
||||||
languageModel: JSON.stringify(languageModel),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (videoModel) {
|
|
||||||
await u.db("t_config").where("type", "video").delete();
|
|
||||||
|
|
||||||
for (const item of videoModel) {
|
|
||||||
await u.db("t_config").insert({
|
|
||||||
type: "video",
|
|
||||||
name: item.model,
|
|
||||||
model: item.model,
|
|
||||||
apiKey: item.apiKey,
|
|
||||||
baseUrl: item.baseUrl,
|
|
||||||
createTime: Date.now(),
|
|
||||||
userId,
|
|
||||||
manufacturer: item.manufacturer,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (languageModel) {
|
|
||||||
await u.db("t_config").where("type", "text").delete();
|
|
||||||
await u.db("t_config").insert({
|
|
||||||
type: "text",
|
|
||||||
name: languageModel.model,
|
|
||||||
model: languageModel.model,
|
|
||||||
apiKey: languageModel.apiKey,
|
|
||||||
baseUrl: languageModel.baseUrl,
|
|
||||||
createTime: Date.now(),
|
|
||||||
userId,
|
|
||||||
manufacturer: languageModel.manufacturer,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (imageModel) {
|
|
||||||
await u.db("t_config").where("type", "image").delete();
|
|
||||||
await u.db("t_config").insert({
|
|
||||||
type: "image",
|
|
||||||
name: imageModel.model,
|
|
||||||
model: imageModel.model,
|
|
||||||
apiKey: imageModel.apiKey,
|
|
||||||
baseUrl: imageModel.baseUrl,
|
|
||||||
createTime: Date.now(),
|
|
||||||
userId,
|
|
||||||
manufacturer: imageModel.manufacturer,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
await u.db("t_user").where("id", userId).update({
|
|
||||||
name,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).send(success({ message: "修改全局配置成功" }));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
32
src/routes/setting/updeteModel.ts
Normal file
32
src/routes/setting/updeteModel.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
id: z.number(),
|
||||||
|
type: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
model: z.string(),
|
||||||
|
baseUrl: z.string(),
|
||||||
|
apiKey: z.string(),
|
||||||
|
manufacturer: z.string(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { id, type, name, model, baseUrl, apiKey, manufacturer } = req.body;
|
||||||
|
|
||||||
|
await u.db("t_config").where("id", id).update({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
model,
|
||||||
|
baseUrl,
|
||||||
|
apiKey,
|
||||||
|
manufacturer,
|
||||||
|
});
|
||||||
|
res.status(200).send(success("编辑成功"));
|
||||||
|
},
|
||||||
|
);
|
||||||
Loading…
x
Reference in New Issue
Block a user