diff --git a/src/routes/production/assets/batchGenerateAssetsImage.ts b/src/routes/production/assets/batchGenerateAssetsImage.ts index ef1a32e..6728dab 100644 --- a/src/routes/production/assets/batchGenerateAssetsImage.ts +++ b/src/routes/production/assets/batchGenerateAssetsImage.ts @@ -5,7 +5,6 @@ import sharp from "sharp"; import { success } from "@/lib/responseFormat"; import { validateFields } from "@/middleware/middleware"; import { Output } from "ai"; -import { urlToBase64 } from "@/utils/vm"; const router = express.Router(); export default router.post( @@ -28,14 +27,6 @@ export default router.post( .leftJoin("o_image", "o_assets.imageId", "o_image.id") .whereIn("o_assets.id", parentIds as number[]) .select("o_assets.id", "o_image.filePath", "o_assets.describe"); - const assetsSrcArr = await Promise.all( - parentAssetsData.map(async (item) => { - return { - src: await u.oss.getFileUrl(item.filePath), - id: item.id, - }; - }), - ); assetsDataArr.forEach((i: any) => { const parent = parentAssetsData.find((item) => item.id === i.assetsId); if (parent) { @@ -43,8 +34,8 @@ export default router.post( } }); const imageUrlRecord: Record = {}; - assetsSrcArr.forEach((item) => { - imageUrlRecord[item.id] = item.src; + parentAssetsData.forEach((item) => { + if (item.filePath) imageUrlRecord[item.id] = item.filePath; }); const rolePrompt = u.getArtPrompt(projectSettingData!.artStyle!, "art_skills", "art_character_derivative"); const toolPrompt = u.getArtPrompt(projectSettingData!.artStyle!, "art_skills", "art_prop_derivative"); @@ -92,7 +83,7 @@ export default router.post( ], }); - const imageBase64 = imageUrlRecord[item.assetsId!] ? await urlToBase64(imageUrlRecord[item.assetsId!]) : null; + const imageBase64 = imageUrlRecord[item.assetsId!] ? await u.oss.getImageBase64(imageUrlRecord[item.assetsId!]) : null; try { const repeloadObj = { prompt: text, diff --git a/src/routes/production/editImage/generateFlowImage.ts b/src/routes/production/editImage/generateFlowImage.ts index 4fa90c8..d20511c 100644 --- a/src/routes/production/editImage/generateFlowImage.ts +++ b/src/routes/production/editImage/generateFlowImage.ts @@ -7,6 +7,9 @@ import axios from "axios"; const router = express.Router(); async function urlToBase64(imageUrl: string): Promise { + if (imageUrl.startsWith("/oss/")) { + return await u.oss.getImageBase64(u.replaceUrl(imageUrl)); + } const response = await axios.get(imageUrl, { responseType: "arraybuffer" }); const contentType = response.headers["content-type"] || "image/png"; const base64 = Buffer.from(response.data, "binary").toString("base64"); diff --git a/src/routes/production/storyboard/batchGenerateImage.ts b/src/routes/production/storyboard/batchGenerateImage.ts index 743e1a3..c9569d2 100644 --- a/src/routes/production/storyboard/batchGenerateImage.ts +++ b/src/routes/production/storyboard/batchGenerateImage.ts @@ -5,7 +5,6 @@ import sharp from "sharp"; import { error, success } from "@/lib/responseFormat"; import { validateFields } from "@/middleware/middleware"; import { Output, tool } from "ai"; -import { urlToBase64 } from "@/utils/vm"; import { assetItemSchema } from "@/agents/productionAgent/tools"; const router = express.Router(); export type AssetData = z.infer; @@ -142,7 +141,7 @@ async function getAssetsImageBase64(imageIds: number[]) { const filePath = id2Path.get(id); if (filePath) { try { - return await urlToBase64(await u.oss.getFileUrl(filePath)); + return await u.oss.getImageBase64(filePath); } catch { return null; } diff --git a/src/routes/production/workbench/getGenerateData.ts b/src/routes/production/workbench/getGenerateData.ts index abce73f..f8ed952 100644 --- a/src/routes/production/workbench/getGenerateData.ts +++ b/src/routes/production/workbench/getGenerateData.ts @@ -37,14 +37,18 @@ export default router.post( }), async (req, res) => { const { projectId, scriptId } = req.body; - const projectData = await u.db("o_project").where("id", projectId).select("id", "videoModel").first(); + const projectData = await u.db("o_project").where("id", projectId).select("id", "videoModel","mode").first(); + if (!projectData?.videoModel) { return res.status(400).json(success("项目未配置视频模型")); } - const [videoId, videoModelName] = projectData.videoModel.split(":"); - const models = await u.vendor.getModelList(videoId); - const findData = models.find((i: any) => i.modelName == videoModelName); - const isRef = findData.mode.every((i: any) => Array.isArray(i)); + let videoMode = "" + try{ + videoMode = JSON.parse(projectData?.mode ?? "") + }catch(e){ + videoMode = projectData?.mode ?? "" + } + const isRef = Array.isArray(videoMode) ? true : false; const storyboardList = await u.db("o_storyboard").where({ scriptId, projectId }).orderBy("index", "asc"); await Promise.all( @@ -105,7 +109,6 @@ export default router.post( ); } - const id = await u.db("o_project").where({ id: projectId }).select("id").first(); const trackData = await u.db("o_videoTrack").where({ projectId, scriptId }); const videoList = await u.db("o_video").whereIn( "videoTrackId", diff --git a/src/types/database.d.ts b/src/types/database.d.ts index 551db81..0c85ca3 100644 --- a/src/types/database.d.ts +++ b/src/types/database.d.ts @@ -1,4 +1,4 @@ -// @db-hash 9248d7bcfe0a1bc57e5b9bc33d8c7d83 +// @db-hash 3296433eb24314b094ac5d3839c049c5 //该文件由脚本自动生成,请勿手动修改 export interface memories { diff --git a/src/utils/oss.ts b/src/utils/oss.ts index a5088f5..e95ed21 100644 --- a/src/utils/oss.ts +++ b/src/utils/oss.ts @@ -50,7 +50,9 @@ class OSS { await this.ensureInit(); const safePath = normalizeUserPath(userRelPath); // URL 始终使用 /,所以这里需要将系统分隔符转回 / - let url = `http://127.0.0.1:10588/${prefix}/`; + let url = `/${prefix}/`; + if (process.env.ossURL && process.env.ossURL !== "") url = process.env.ossURL + `/${prefix}/`; + if (process.env.NODE_ENV == "dev") url = `http://localhost:10588/${prefix}/`; if (isEletron()) url = `http://localhost:${process.env.PORT}/${prefix}/`; return `${url}${safePath.split(path.sep).join("/")}`; }