去除 oss前缀
This commit is contained in:
parent
b97901c446
commit
39d3a631f0
@ -16,7 +16,7 @@ export default router.post(
|
||||
async (req, res) => {
|
||||
const { id, url, flowId } = req.body;
|
||||
const [imageId] = await u.db("o_image").insert({
|
||||
filePath: new URL(url).pathname,
|
||||
filePath: u.replaceUrl(url),
|
||||
state: "已完成",
|
||||
assetsId: id,
|
||||
});
|
||||
|
||||
@ -19,10 +19,11 @@ export default router.post(
|
||||
const { edges, nodes, flowId } = req.body;
|
||||
nodes.forEach((node: any) => {
|
||||
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") {
|
||||
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 = "";
|
||||
|
||||
@ -35,7 +35,7 @@ export default router.post(
|
||||
prompt,
|
||||
duration,
|
||||
state,
|
||||
filePath: new URL(src).pathname,
|
||||
filePath: u.replaceUrl(src),
|
||||
trackId,
|
||||
videoDesc,
|
||||
shouldGenerateImage: src ? 1 : 0,
|
||||
|
||||
@ -19,7 +19,7 @@ export default router.post(
|
||||
.db("o_storyboard")
|
||||
.where({ id })
|
||||
.update({
|
||||
filePath: new URL(url).pathname,
|
||||
filePath: u.replaceUrl(url),
|
||||
flowId,
|
||||
state: "已完成",
|
||||
shouldGenerateImage:url ? 1 : 0
|
||||
|
||||
@ -10,6 +10,7 @@ import task from "@/utils/taskRecord";
|
||||
import Ai from "@/utils/ai";
|
||||
import { getPrompts } from "@/utils/getPrompts";
|
||||
import { getArtPrompt } from "@/utils/getArtPrompt";
|
||||
import replaceUrl from "@/utils/replaceUrl";
|
||||
|
||||
export default {
|
||||
db,
|
||||
@ -24,4 +25,5 @@ export default {
|
||||
task,
|
||||
getPrompts,
|
||||
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