修改: 更新图像处理逻辑,移除不必要的urlToBase64函数调用,直接使用getImageBase64方法
This commit is contained in:
parent
2b6a185cf1
commit
7486c419f1
@ -5,7 +5,6 @@ import sharp from "sharp";
|
|||||||
import { success } from "@/lib/responseFormat";
|
import { success } from "@/lib/responseFormat";
|
||||||
import { validateFields } from "@/middleware/middleware";
|
import { validateFields } from "@/middleware/middleware";
|
||||||
import { Output } from "ai";
|
import { Output } from "ai";
|
||||||
import { urlToBase64 } from "@/utils/vm";
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
export default router.post(
|
export default router.post(
|
||||||
@ -28,14 +27,6 @@ export default router.post(
|
|||||||
.leftJoin("o_image", "o_assets.imageId", "o_image.id")
|
.leftJoin("o_image", "o_assets.imageId", "o_image.id")
|
||||||
.whereIn("o_assets.id", parentIds as number[])
|
.whereIn("o_assets.id", parentIds as number[])
|
||||||
.select("o_assets.id", "o_image.filePath", "o_assets.describe");
|
.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) => {
|
assetsDataArr.forEach((i: any) => {
|
||||||
const parent = parentAssetsData.find((item) => item.id === i.assetsId);
|
const parent = parentAssetsData.find((item) => item.id === i.assetsId);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@ -43,8 +34,8 @@ export default router.post(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const imageUrlRecord: Record<number, string> = {};
|
const imageUrlRecord: Record<number, string> = {};
|
||||||
assetsSrcArr.forEach((item) => {
|
parentAssetsData.forEach((item) => {
|
||||||
imageUrlRecord[item.id] = item.src;
|
if (item.filePath) imageUrlRecord[item.id] = item.filePath;
|
||||||
});
|
});
|
||||||
const rolePrompt = u.getArtPrompt(projectSettingData!.artStyle!, "art_skills", "art_character_derivative");
|
const rolePrompt = u.getArtPrompt(projectSettingData!.artStyle!, "art_skills", "art_character_derivative");
|
||||||
const toolPrompt = u.getArtPrompt(projectSettingData!.artStyle!, "art_skills", "art_prop_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 {
|
try {
|
||||||
const repeloadObj = {
|
const repeloadObj = {
|
||||||
prompt: text,
|
prompt: text,
|
||||||
|
|||||||
@ -7,6 +7,9 @@ import axios from "axios";
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
async function urlToBase64(imageUrl: string): Promise<string> {
|
async function urlToBase64(imageUrl: string): Promise<string> {
|
||||||
|
if (imageUrl.startsWith("/oss/")) {
|
||||||
|
return await u.oss.getImageBase64(u.replaceUrl(imageUrl));
|
||||||
|
}
|
||||||
const response = await axios.get(imageUrl, { responseType: "arraybuffer" });
|
const response = await axios.get(imageUrl, { responseType: "arraybuffer" });
|
||||||
const contentType = response.headers["content-type"] || "image/png";
|
const contentType = response.headers["content-type"] || "image/png";
|
||||||
const base64 = Buffer.from(response.data, "binary").toString("base64");
|
const base64 = Buffer.from(response.data, "binary").toString("base64");
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import sharp from "sharp";
|
|||||||
import { error, success } from "@/lib/responseFormat";
|
import { error, success } from "@/lib/responseFormat";
|
||||||
import { validateFields } from "@/middleware/middleware";
|
import { validateFields } from "@/middleware/middleware";
|
||||||
import { Output, tool } from "ai";
|
import { Output, tool } from "ai";
|
||||||
import { urlToBase64 } from "@/utils/vm";
|
|
||||||
import { assetItemSchema } from "@/agents/productionAgent/tools";
|
import { assetItemSchema } from "@/agents/productionAgent/tools";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
export type AssetData = z.infer<typeof assetItemSchema>;
|
export type AssetData = z.infer<typeof assetItemSchema>;
|
||||||
@ -143,7 +142,7 @@ async function getAssetsImageBase64(imageIds: number[]) {
|
|||||||
const filePath = id2Path.get(id);
|
const filePath = id2Path.get(id);
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
try {
|
try {
|
||||||
return await urlToBase64(await u.oss.getFileUrl(filePath));
|
return await u.oss.getImageBase64(filePath);
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user