0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 00:50:23 -05:00

fix(server) utf8 original filename (#1147)

This commit is contained in:
Jason Rasmussen 2022-12-20 22:46:57 -05:00 committed by GitHub
parent 354593a70d
commit 21d6874e54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import { existsSync, mkdirSync } from 'fs';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
import sanitize from 'sanitize-filename';
import { patchFormData } from '../utils/path-form-data.util';
export const assetUploadOption: MulterOptions = {
fileFilter,
@ -55,6 +56,8 @@ function filename(req: Request, file: Express.Multer.File, cb: any) {
return cb(new UnauthorizedException());
}
file.originalname = patchFormData(file.originalname);
const fileNameUUID = randomUUID();
if (file.fieldname === 'livePhotoData') {

View file

@ -6,6 +6,7 @@ import { existsSync, mkdirSync } from 'fs';
import { diskStorage } from 'multer';
import { extname } from 'path';
import sanitize from 'sanitize-filename';
import { patchFormData } from '../utils/path-form-data.util';
export const profileImageUploadOption: MulterOptions = {
fileFilter,
@ -49,6 +50,8 @@ function filename(req: Request, file: Express.Multer.File, cb: any) {
return cb(new UnauthorizedException());
}
file.originalname = patchFormData(file.originalname);
const userId = req.user.id;
const fileName = `${userId}${extname(file.originalname)}`;

View file

@ -0,0 +1,3 @@
export function patchFormData(latin1: string) {
return Buffer.from(latin1, 'latin1').toString('utf8');
}