Explorar el Código

fix: 单素材上传使用图片 multer(special不可手动替换)

- 新增 uploadImage multer 实例,接受 image/* 类型
- special 从可手动替换列表中排除(仅 ZIP 导入)
guoziyun hace 3 semanas
padre
commit
950a3a6a04

+ 3 - 2
platform/client/src/components/AssetUploader.tsx

@@ -114,9 +114,10 @@ export default function AssetUploader({ creativeId, assets, assetDefs, onUpdated
     assets.some((a) => a.key === def.key)
   );
 
-  // 哪些 key 是可手动替换的(optional + 图片文件)
+  // 哪些 key 是可手动替换的(optional + 图片文件,排除 special)
+  const EXCLUDE_MANUAL = new Set(["special"]);
   const replaceableKeys = new Set(
-    assetDefs.optional.filter((d) => isImageFile(d.file)).map((d) => d.key)
+    assetDefs.optional.filter((d) => isImageFile(d.file) && !EXCLUDE_MANUAL.has(d.key)).map((d) => d.key)
   );
 
   return (

+ 14 - 1
platform/server/src/routes/assets.ts

@@ -26,6 +26,19 @@ const upload = multer({
   },
 });
 
+// 单图片上传(logo/slogon 等手动替换)
+const uploadImage = multer({
+  storage: multer.memoryStorage(),
+  limits: { fileSize: 5 * 1024 * 1024 },
+  fileFilter: (_req, file, cb) => {
+    if (file.mimetype.startsWith("image/")) {
+      cb(null, true);
+    } else {
+      cb(new Error("Only image files are allowed"));
+    }
+  },
+});
+
 /**
  * 从 zip buffer 中提取素材文件、校验、写入磁盘、更新 DB。
  * 文件上传和 URL 导入共用此逻辑。
@@ -212,7 +225,7 @@ export function assetsRouter(db: Database.Database, storageDir: string): Router
   });
 
   // POST /api/v1/creatives/:id/assets/:key — 上传单个素材文件(手动替换)
-  router.post("/creatives/:id/assets/:key", upload.single("file"), (req, res) => {
+  router.post("/creatives/:id/assets/:key", uploadImage.single("file"), (req, res) => {
     try {
       const creativeId = req.params.id as string;
       const fileKey = req.params.key as string;