Merge pull request #103 from a12110/develop
修改: web/docker环境下资源返回路径从原本的固定地址修改为相对路径地址
This commit is contained in:
commit
8934fee879
@ -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>;
|
||||||
@ -142,7 +141,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;
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/types/database.d.ts
vendored
2
src/types/database.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// @db-hash 9248d7bcfe0a1bc57e5b9bc33d8c7d83
|
// @db-hash 3296433eb24314b094ac5d3839c049c5
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
export interface memories {
|
export interface memories {
|
||||||
|
|||||||
@ -50,7 +50,9 @@ class OSS {
|
|||||||
await this.ensureInit();
|
await this.ensureInit();
|
||||||
const safePath = normalizeUserPath(userRelPath);
|
const safePath = normalizeUserPath(userRelPath);
|
||||||
// URL 始终使用 /,所以这里需要将系统分隔符转回 /
|
// 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}/`;
|
if (isEletron()) url = `http://localhost:${process.env.PORT}/${prefix}/`;
|
||||||
return `${url}${safePath.split(path.sep).join("/")}`;
|
return `${url}${safePath.split(path.sep).join("/")}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user