Skip to content

Commit 66d5dad

Browse files
committed
refactor(resources): detect mimetypes
1 parent c85ea75 commit 66d5dad

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@types/cookie-parser": "^1.4.10",
3030
"@types/express": "^5.0.5",
3131
"@types/jest": "^29.5.14",
32+
"@types/mime-types": "^3.0.1",
3233
"@types/multer": "^1.4.13",
3334
"@types/node": "^22.19.0",
3435
"@types/nodemailer": "^6.4.21",
@@ -92,6 +93,7 @@
9293
"keyv": "^5.5.3",
9394
"lodash": "^4.17.21",
9495
"meilisearch": "^0.50.0",
96+
"mime-types": "^3.0.1",
9597
"nanoid": "^5.1.6",
9698
"nestjs-i18n": "^10.5.1",
9799
"nestjs-otel": "^7.0.1",

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/namespace-resources/dto/create-file-req.dto.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ export class CreateFileReqDto {
2222
@IsString({
2323
message: i18nValidationMessage('validation.errors.mimetype.isString'),
2424
})
25-
@IsNotEmpty({
26-
message: i18nValidationMessage('validation.errors.mimetype.isNotEmpty'),
27-
})
28-
mimetype: string;
25+
@IsOptional()
26+
mimetype?: string;
2927

3028
@Expose()
3129
@IsNumber(

src/namespace-resources/namespace-resources.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { InjectRepository } from '@nestjs/typeorm';
22
import duplicateName from 'omniboxd/utils/duplicate-name';
3+
import * as mime from 'mime-types';
34
import {
45
DataSource,
56
EntityManager,
@@ -706,11 +707,15 @@ export class NamespaceResourcesService {
706707
const message = this.i18n.t('auth.errors.notAuthorized');
707708
throw new AppException(message, 'NOT_AUTHORIZED', HttpStatus.FORBIDDEN);
708709
}
710+
const mimetype =
711+
createReq.mimetype ||
712+
mime.lookup(createReq.name) ||
713+
'application/octet-stream';
709714
const file = await this.filesService.createFile(
710715
userId,
711716
namespaceId,
712717
createReq.name,
713-
createReq.mimetype,
718+
mimetype,
714719
);
715720
const url = await this.filesService.generateUploadUrl(file.id);
716721
const postReq = await this.filesService.generatePostForm(

0 commit comments

Comments
 (0)