Merge branch '108' of https://github.com/HBAI-Ltd/Toonflow-app into 108
# Conflicts: # src/types/database.d.ts
This commit is contained in:
commit
57e65160dd
BIN
data/assets/ending.mp4
Normal file
BIN
data/assets/ending.mp4
Normal file
Binary file not shown.
BIN
data/latest.zip
BIN
data/latest.zip
Binary file not shown.
@ -38,7 +38,6 @@ export default async function startServe(randomPort: Boolean = false) {
|
|||||||
console.log("文件目录:", ossDir);
|
console.log("文件目录:", ossDir);
|
||||||
app.use("/oss", express.static(ossDir));
|
app.use("/oss", express.static(ossDir));
|
||||||
// skills 静态资源
|
// skills 静态资源
|
||||||
|
|
||||||
const skillsDir = u.getPath("skills");
|
const skillsDir = u.getPath("skills");
|
||||||
if (!fs.existsSync(skillsDir)) {
|
if (!fs.existsSync(skillsDir)) {
|
||||||
fs.mkdirSync(skillsDir, { recursive: true });
|
fs.mkdirSync(skillsDir, { recursive: true });
|
||||||
@ -53,6 +52,14 @@ export default async function startServe(randomPort: Boolean = false) {
|
|||||||
express.static(skillsDir),
|
express.static(skillsDir),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// assets 静态资源
|
||||||
|
const assetsDir = u.getPath("assets");
|
||||||
|
if (!fs.existsSync(assetsDir)) {
|
||||||
|
fs.mkdirSync(assetsDir, { recursive: true });
|
||||||
|
}
|
||||||
|
console.log("文件目录:", assetsDir);
|
||||||
|
app.use("/assets", express.static(assetsDir));
|
||||||
|
|
||||||
// data/web 静态网站
|
// data/web 静态网站
|
||||||
const webDir = u.getPath("web");
|
const webDir = u.getPath("web");
|
||||||
if (fs.existsSync(webDir)) {
|
if (fs.existsSync(webDir)) {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export default router.post(
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
//拿到本地片尾视频并插入到data中
|
//拿到本地片尾视频并插入到data中
|
||||||
const ending = await u.oss.getFileUrl("/ending/1d7a2dfdd0c057823797fdf97677a7a0.mp4");
|
const ending = await u.oss.getFileUrl("/ending.mp4", "assets");
|
||||||
data.push({
|
data.push({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "片尾",
|
name: "片尾",
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export default router.post(
|
|||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { id, url, flowId } = req.body;
|
const { id, url, flowId } = req.body;
|
||||||
const [imageId] = await u.db("o_image").insert({
|
const [imageId] = await u.db("o_image").insert({
|
||||||
filePath: new URL(url).pathname,
|
filePath: u.replaceUrl(url),
|
||||||
state: "已完成",
|
state: "已完成",
|
||||||
assetsId: id,
|
assetsId: id,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,7 +13,15 @@ export default router.post(
|
|||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { edges, nodes } = req.body;
|
const { edges, nodes } = req.body;
|
||||||
|
nodes.forEach((node: any) => {
|
||||||
|
if (node.type == "upload") {
|
||||||
|
node.data.image = node.data.image ? u.replaceUrl(node.data.image) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type == "generated") {
|
||||||
|
node.data.generatedImage = node.data.generatedImage ? u.replaceUrl(node.data.generatedImage) : "";
|
||||||
|
}
|
||||||
|
});
|
||||||
const [insertFlowId] = await u.db("o_imageFlow").insert({
|
const [insertFlowId] = await u.db("o_imageFlow").insert({
|
||||||
flowData: JSON.stringify({ edges, nodes }),
|
flowData: JSON.stringify({ edges, nodes }),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,39 +10,19 @@ export default router.post(
|
|||||||
validateFields({
|
validateFields({
|
||||||
edges: z.any(),
|
edges: z.any(),
|
||||||
nodes: z.any(),
|
nodes: z.any(),
|
||||||
id: z.number(),
|
|
||||||
imageUrl: z.string(),
|
|
||||||
flowId: z.number(),
|
flowId: z.number(),
|
||||||
episodesId: z.number(),
|
|
||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { edges, nodes, flowId } = req.body;
|
const { edges, nodes, flowId } = req.body;
|
||||||
nodes.forEach((node: any) => {
|
nodes.forEach((node: any) => {
|
||||||
if (node.type == "upload") {
|
if (node.type == "upload") {
|
||||||
node.data.image = node.data.image ? new URL(node.data.image).pathname : "";
|
node.data.image = node.data.image ? u.replaceUrl(node.data.image) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.type == "generated") {
|
if (node.type == "generated") {
|
||||||
node.data.generatedImage = node.data.generatedImage ? new URL(node.data.generatedImage).pathname : "";
|
node.data.generatedImage = node.data.generatedImage ? u.replaceUrl(node.data.generatedImage) : "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// let imagePath = "";
|
|
||||||
// try {
|
|
||||||
// imagePath = new URL(imageUrl).pathname;
|
|
||||||
// } catch (e) {}
|
|
||||||
// if (imagePath) {
|
|
||||||
// if (type == "storyboard") {
|
|
||||||
// await u.db("o_storyboard").where("id", id).update({
|
|
||||||
// filePath: imagePath,
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// const [imageId] = await u.db("o_image").insert({
|
|
||||||
// filePath: imagePath,
|
|
||||||
// assetsId: id,
|
|
||||||
// state: "已完成",
|
|
||||||
// });
|
|
||||||
// await u.db("o_assets").where("id", id).update({ imageId });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
await u
|
await u
|
||||||
.db("o_imageFlow")
|
.db("o_imageFlow")
|
||||||
|
|||||||
@ -116,6 +116,7 @@ export default router.post(
|
|||||||
prompt: item.prompt ?? "",
|
prompt: item.prompt ?? "",
|
||||||
desc: item.describe ?? "",
|
desc: item.describe ?? "",
|
||||||
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
||||||
|
flowId: item.flowId,
|
||||||
derive: await Promise.all(
|
derive: await Promise.all(
|
||||||
childAssetsData
|
childAssetsData
|
||||||
.filter((child) => child.assetsId === item.id)
|
.filter((child) => child.assetsId === item.id)
|
||||||
@ -129,6 +130,7 @@ export default router.post(
|
|||||||
src: child.filePath && (await u.oss.getFileUrl(child.filePath!)),
|
src: child.filePath && (await u.oss.getFileUrl(child.filePath!)),
|
||||||
state: child.state ?? "未生成",
|
state: child.state ?? "未生成",
|
||||||
errorReason: child?.errorReason ?? "",
|
errorReason: child?.errorReason ?? "",
|
||||||
|
flowId: child.flowId,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
@ -145,6 +147,7 @@ export default router.post(
|
|||||||
videoDesc: i.videoDesc,
|
videoDesc: i.videoDesc,
|
||||||
shouldGenerateImage: i.shouldGenerateImage,
|
shouldGenerateImage: i.shouldGenerateImage,
|
||||||
reason: i?.reason ?? "",
|
reason: i?.reason ?? "",
|
||||||
|
flowId: i.flowId,
|
||||||
}))
|
}))
|
||||||
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
||||||
res.status(200).send(success(flowData));
|
res.status(200).send(success(flowData));
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export default router.post(
|
|||||||
prompt,
|
prompt,
|
||||||
duration,
|
duration,
|
||||||
state,
|
state,
|
||||||
filePath: new URL(src).pathname,
|
filePath: u.replaceUrl(src),
|
||||||
trackId,
|
trackId,
|
||||||
videoDesc,
|
videoDesc,
|
||||||
shouldGenerateImage: src ? 1 : 0,
|
shouldGenerateImage: src ? 1 : 0,
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export default router.post(
|
|||||||
.db("o_storyboard")
|
.db("o_storyboard")
|
||||||
.where({ id })
|
.where({ id })
|
||||||
.update({
|
.update({
|
||||||
filePath: new URL(url).pathname,
|
filePath: u.replaceUrl(url),
|
||||||
flowId,
|
flowId,
|
||||||
state: "已完成",
|
state: "已完成",
|
||||||
shouldGenerateImage:url ? 1 : 0
|
shouldGenerateImage:url ? 1 : 0
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import task from "@/utils/taskRecord";
|
|||||||
import Ai from "@/utils/ai";
|
import Ai from "@/utils/ai";
|
||||||
import { getPrompts } from "@/utils/getPrompts";
|
import { getPrompts } from "@/utils/getPrompts";
|
||||||
import { getArtPrompt } from "@/utils/getArtPrompt";
|
import { getArtPrompt } from "@/utils/getArtPrompt";
|
||||||
|
import replaceUrl from "@/utils/replaceUrl";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
db,
|
db,
|
||||||
@ -24,4 +25,5 @@ export default {
|
|||||||
task,
|
task,
|
||||||
getPrompts,
|
getPrompts,
|
||||||
getArtPrompt,
|
getArtPrompt,
|
||||||
|
replaceUrl
|
||||||
};
|
};
|
||||||
|
|||||||
12
src/utils/replaceUrl.ts
Normal file
12
src/utils/replaceUrl.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export default function replaceUrl(url: string): string {
|
||||||
|
if (typeof url !== 'string' || !url.trim()) return '';
|
||||||
|
let cleanedPath = '';
|
||||||
|
try {
|
||||||
|
const pathname = new URL(url).pathname;
|
||||||
|
cleanedPath = pathname.replace(/^\/oss/, '');
|
||||||
|
} catch (e) {
|
||||||
|
// 如果不是有效的URL,则直接返回原字符串
|
||||||
|
cleanedPath = url;
|
||||||
|
}
|
||||||
|
return cleanedPath;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user