浏览代码

fix(server): Do not change file ext case on upload (#2056)

bo0tzz 2 年之前
父节点
当前提交
8adf1231a3

+ 13 - 0
server/apps/immich/src/config/asset-upload.config.spec.ts

@@ -179,5 +179,18 @@ describe('assetUploadOption', () => {
       expect(error).toBeNull();
       expect(error).toBeNull();
       expect(name.endsWith(mock.userRequest.body.fileExtension)).toBeTruthy();
       expect(name.endsWith(mock.userRequest.body.fileExtension)).toBeTruthy();
     });
     });
+
+    it('should not change the casing of the extension', () => {
+      // Case is deliberately mixed to cover both .upper() and .lower()
+      const body = { ...mock.userRequest.body, fileExtension: '.JpEg' };
+      const request = { ...mock.userRequest, body } as Request;
+
+      filename(request, mock.file, callback);
+
+      expect(callback).toHaveBeenCalled();
+      const [error, name] = callback.mock.calls[0];
+      expect(error).toBeNull();
+      expect(name.endsWith(body.fileExtension)).toBeTruthy();
+    });
   });
   });
 });
 });

+ 1 - 1
server/apps/immich/src/config/asset-upload.config.ts

@@ -97,6 +97,6 @@ function filename(req: Request, file: Express.Multer.File, cb: any) {
     return cb(null, sanitize(livePhotoFileName));
     return cb(null, sanitize(livePhotoFileName));
   }
   }
 
 
-  const fileName = `${fileNameUUID}${req.body['fileExtension'].toLowerCase()}`;
+  const fileName = `${fileNameUUID}${req.body['fileExtension']}`;
   return cb(null, sanitize(fileName));
   return cb(null, sanitize(fileName));
 }
 }