Restrict file extension when importing markdown (#2104)

* fix #2090

* pass the check style

* Revision

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* revision

* fix

* Revision

* revision
pull/2120/head
ETLAN666 2022-05-26 16:40:09 +08:00 committed by GitHub
parent c2e477fcab
commit 3dda1a9f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -141,7 +141,9 @@ public class BackupController {
backupService.deleteWorkDirBackup(filename);
}
@PostMapping("markdown/import")
@PostMapping(value = "markdown/import", consumes = {
MediaType.TEXT_PLAIN_VALUE,
MediaType.TEXT_MARKDOWN_VALUE})
@ApiOperation("Imports markdown")
public BasePostDetailDTO backupMarkdowns(@RequestPart("file") MultipartFile file)
throws IOException {

View File

@ -230,12 +230,16 @@ public class BackupServiceImpl implements BackupService {
@Override
public BasePostDetailDTO importMarkdown(MultipartFile file) throws IOException {
try {
// Read markdown content.
String markdown = FileUtils.readString(file.getInputStream());
// TODO sheet import
return postService.importMarkdown(markdown, file.getOriginalFilename());
} catch (OutOfMemoryError error) {
throw new ServiceException(
"文件内容过大,无法导入。", error);
}
// Read markdown content.
String markdown = FileUtils.readString(file.getInputStream());
// TODO sheet import
return postService.importMarkdown(markdown, file.getOriginalFilename());
}
@Override