Skip to content

Commit

Permalink
Merge pull request #19 from erik1110/feature/api
Browse files Browse the repository at this point in the history
[feat & fix] add file extension checking and fix updateCulinary
  • Loading branch information
erik1110 committed Jan 24, 2024
2 parents 298485d + 28eab30 commit 327a738
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/features/culinary/culinary.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CulinaryService {
title: updateCulinaryDto.title,
description: updateCulinaryDto.description,
diningTime: updateCulinaryDto.diningTime,
image: updateCulinaryDto.description,
image: updateCulinaryDto.image,
creator: req['user']._id,
},
{
Expand Down
5 changes: 5 additions & 0 deletions src/features/image/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export class ImageService {

async uploadImage(file): Promise<string> {
const maxSize = 3 * 1024 * 1024; // 3 MB in bytes
const allowedExtensions = ['png', 'jpg', 'jpeg', 'webp'];
if (file.size > maxSize) {
throw new AppError(HttpStatus.BAD_REQUEST, 'UserError', '超過 3 MB');
}
const fileExtension = file.name.split('.').pop()?.toLowerCase();
if (!fileExtension || !allowedExtensions.includes(fileExtension)) {
throw new AppError(HttpStatus.BAD_REQUEST, 'UserError', '不支援的檔案格式');
}
const storage = this.firebaseService.getStorageInstance();
const bucket = storage.bucket();
const encodedOriginalName = encodeURIComponent(file.originalname);
Expand Down

0 comments on commit 327a738

Please sign in to comment.