Skip to content

Commit 42ac278

Browse files
authored
Merge pull request #255 from import-ai/refactor/file
refactor(open-api): check if file is present
2 parents 46baf6d + f1ea7af commit 42ac278

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/i18n/en/resource.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"cannotDuplicateRoot": "Cannot duplicate root resource",
1111
"cannotRestoreRoot": "Cannot restore root resource",
1212
"contentRequired": "Content is required for the resource",
13+
"fileRequired": "File is required for upload",
1314
"fileResourceNotFound": "File resource not found",
1415
"cycleDetected": "Cycle detected in the resource tree",
1516
"cannotSetParentToSubResource": "Cannot set parent to a sub-resource",

src/i18n/zh/resource.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"cannotDuplicateRoot": "无法复制根资源",
1111
"cannotRestoreRoot": "无法恢复根资源",
1212
"contentRequired": "资源需要内容",
13+
"fileRequired": "需要上传文件",
1314
"fileResourceNotFound": "文件资源未找到",
1415
"cycleDetected": "资源树中检测到循环引用",
1516
"cannotSetParentToSubResource": "无法将父资源设置为子资源",

src/namespace-resources/open.resource.controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,21 @@ export class OpenResourcesController {
177177
},
178178
},
179179
})
180+
@ApiResponse({ status: 400, description: 'File required' })
180181
@ApiResponse({ status: 401, description: 'Invalid or missing API key' })
181182
@ApiResponse({ status: 403, description: 'Insufficient permissions' })
182183
async uploadFile(
183184
@APIKey() apiKey: APIKeyEntity,
184185
@UserId() userId: string,
185-
@UploadedFile() file: Express.Multer.File,
186+
@I18n() i18n: I18nContext,
187+
@UploadedFile() file?: Express.Multer.File,
186188
@Body('parsed_content') parsedContent?: string,
187189
) {
190+
if (!file) {
191+
const message = i18n.t('resource.errors.fileRequired');
192+
throw new AppException(message, 'FILE_REQUIRED', HttpStatus.BAD_REQUEST);
193+
}
194+
188195
const newResource = await this.namespaceResourcesService.uploadFile(
189196
userId,
190197
apiKey.namespaceId,

0 commit comments

Comments
 (0)