mirror of https://github.com/halo-dev/halo
fix: fail to delete multiple files if the files are removed from upstream storage (#2317)
#### What type of PR is this? /kind bug #### What this PR does / why we need it: 修复了在云端删除文件后,在Halo同时删除多个附件失败的bug。 Halo数据库里的附件并不会和云端文件实时同步,如果在云端删除文件多个后又在Halo删除,在删除第一个文件后则会抛出异常导致其它文件无法在halo的数据库中正常删除。这个PR通过删除在删除又拍云和七牛云的附件后判断返回状态和抛出异常的代码来解决这个问题。 #### Which issue(s) this PR fixes: Fixes #2283 #### Special notes for your reviewer: 该bug只在七牛云和又拍云存在,其它云储存没有判断返回状态和抛出异常的代码,因此不存在这个问题。 #### Does this PR introduce a user-facing change? ```release-note NONE ```pull/2331/head^2
parent
f8bd4febb9
commit
13268cb5f8
|
@ -190,7 +190,9 @@ public class QiniuOssFileHandler implements FileHandler {
|
|||
}
|
||||
} catch (QiniuException e) {
|
||||
log.error("Qiniu oss error response: [{}]", e.response);
|
||||
throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e);
|
||||
if (e.response.statusCode != 612) {
|
||||
throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import run.halo.app.model.support.UploadResult;
|
|||
import run.halo.app.repository.AttachmentRepository;
|
||||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.utils.ImageUtils;
|
||||
import run.halo.app.utils.JsonUtils;
|
||||
|
||||
/**
|
||||
* Up oss file handler.
|
||||
|
@ -137,7 +138,9 @@ public class UpOssFileHandler implements FileHandler {
|
|||
|
||||
try {
|
||||
Response result = manager.deleteFile(key, null);
|
||||
if (!result.isSuccessful()) {
|
||||
HashMap respondBody = JsonUtils.jsonToObject(result.body().string(), HashMap.class);
|
||||
if (!result.isSuccessful()
|
||||
&& !(result.code() == 404 && respondBody.get("code").equals(40400001))) {
|
||||
log.warn("附件 " + key + " 从又拍云删除失败");
|
||||
throw new FileOperationException("附件 " + key + " 从又拍云删除失败");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue