Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(文件管理): 优化文件管理 #558

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetlinks.community.io.file;

import com.alibaba.excel.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
Expand All @@ -24,6 +25,7 @@
import org.springframework.http.codec.multipart.FilePart;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import java.io.File;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -168,6 +170,9 @@ public Mono<FileInfo> saveFile(String name, Flux<DataBuffer> stream, FileOption.

@Override
public Mono<FileInfo> saveFile(String name, String folder, Flux<DataBuffer> stream, FileOption... options) {
if (folder.contains("/")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不够严谨,文件路径的方式可能有很多,以及非法字符等。

return Mono.error(new BusinessException("error.folder_cannot_contains:/"));
}
return doSaveFile(name, folder, stream, options);
}

Expand Down Expand Up @@ -277,6 +282,7 @@ public void handleDeleteEvent(EntityDeletedEvent<FileEntity> event) {
.map(entity -> Paths.get(properties.getStorageBasePath(), entity.getStoragePath()).toFile())
.filter(File::exists)
.map(File::delete)
zhou-hao marked this conversation as resolved.
Show resolved Hide resolved
.subscribeOn(Schedulers.boundedElastic())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Mono<Void> read(@PathVariable String fileId,
.getHeaders()
.getRange();
long position = 0;
if (ranges.size() != 0) {
if (!ranges.isEmpty()) {
position = ranges.get(0).getRangeStart(ctx.info().getLength());
}
ctx.position(position);
Expand Down
Loading