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

add(文件管理): 增加删除文件接口 #466

Merged
merged 5 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Expand Up @@ -248,6 +248,16 @@ public Flux<DataBuffer> read(String id, Function<ReaderContext, Mono<Void>> befo
});
}

@Override
public Mono<Integer> delete(String id) {
return doDelete(id);
}

public Mono<Integer> doDelete(String id) {
return repository
.deleteById(id);
}

@EventListener
public void handleDeleteEvent(EntityDeletedEvent<FileEntity> event) {
for (FileEntity fileEntity : event.getEntity()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface FileManager {
Flux<DataBuffer> read(String id,
Function<ReaderContext, Mono<Void>> beforeRead);

Mono<Integer> delete(String id);

interface ReaderContext {
FileInfo info();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.AllArgsConstructor;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.DeleteAction;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.authorization.exception.AccessDenyException;
import org.jetlinks.community.io.file.FileInfo;
import org.jetlinks.community.io.file.FileManager;
Expand Down Expand Up @@ -100,4 +102,15 @@ public Mono<Void> read(@PathVariable String fileId,

}));
}

@DeleteMapping("/{fileId}")
@Authorize()
@Resource(id= "delete-file",name = "删除文件")
zhou-hao marked this conversation as resolved.
Show resolved Hide resolved
@DeleteAction
@Operation(summary = "删除文件")
public Mono<Integer> delete(@PathVariable String fileId) {
zhou-hao marked this conversation as resolved.
Show resolved Hide resolved
return fileManager
.delete(fileId);
}

}
Loading