修复bug
This commit is contained in:
parent
b7ae5a5423
commit
74a11a02c7
|
|
@ -18,6 +18,7 @@ import com.mdd.common.entity.file.File;
|
|||
import com.mdd.common.entity.file.FileCate;
|
||||
import com.mdd.common.mapper.album.FileCateMapper;
|
||||
import com.mdd.common.mapper.album.FileMapper;
|
||||
import com.mdd.common.plugin.storage.StorageDriver;
|
||||
import com.mdd.common.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -182,13 +183,14 @@ public class FileServiceImpl implements IFileService {
|
|||
@Override
|
||||
public void fileDel(List<Integer> ids) {
|
||||
List<File> files = fileMapper.selectList(new QueryWrapper<File>()
|
||||
.select("id", "name")
|
||||
.in("id", ids)
|
||||
.isNull("delete_time"));
|
||||
|
||||
Assert.notNull(files, "文件丢失!");
|
||||
|
||||
for (File file : files) {
|
||||
StorageDriver driver = new StorageDriver();
|
||||
driver.deleteFile(file.getUri());
|
||||
file.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
fileMapper.updateById(file);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,4 +128,26 @@ public class StorageDriver {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteFile(String filePath) {
|
||||
switch (this.engine) {
|
||||
case "local":
|
||||
LocalStorage local = new LocalStorage();
|
||||
local.delete(filePath);
|
||||
break;
|
||||
case "qiniu":
|
||||
QiniuStorage qiniu = new QiniuStorage(this.config);
|
||||
qiniu.delete(filePath);
|
||||
break;
|
||||
case "aliyun":
|
||||
AliyunStorage aliyun = new AliyunStorage(this.config);
|
||||
aliyun.delete(filePath);
|
||||
break;
|
||||
case "qcloud":
|
||||
QcloudStorage qcloud = new QcloudStorage(this.config);
|
||||
qcloud.delete(filePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.mdd.common.plugin.storage.engine;
|
|||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.OSSException;
|
||||
import com.aliyun.oss.model.DeleteObjectsRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -64,4 +65,8 @@ public class AliyunStorage {
|
|||
}
|
||||
}
|
||||
|
||||
public void delete(String key) {
|
||||
this.ossClient().deleteObject(this.config.get("bucket"), key);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,10 @@ public class LocalStorage {
|
|||
|
||||
}
|
||||
|
||||
public void delete(String filePath) {
|
||||
String directory = YmlUtils.get("like.upload-directory");
|
||||
File file = new File(directory + filePath);
|
||||
file.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.qcloud.cos.auth.BasicCOSCredentials;
|
|||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.exception.CosClientException;
|
||||
import com.qcloud.cos.http.HttpProtocol;
|
||||
import com.qcloud.cos.model.DeleteObjectsRequest;
|
||||
import com.qcloud.cos.model.ObjectMetadata;
|
||||
import com.qcloud.cos.model.PutObjectRequest;
|
||||
import com.qcloud.cos.region.Region;
|
||||
|
|
@ -70,6 +71,8 @@ public class QcloudStorage {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void delete(String filePath) {
|
||||
this.cosClient().deleteObject(this.config.get("bucket"), filePath);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.mdd.common.plugin.storage.engine;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.Region;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
|
|
@ -57,10 +59,27 @@ public class QiniuStorage {
|
|||
|
||||
try {
|
||||
Response response = uploadManager.put(multipartFile.getBytes(), key, this.upToken());
|
||||
new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
DefaultPutRet ret = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
System.out.println(ret);
|
||||
} catch (IOException ex) {
|
||||
throw new OperateException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String filePath) {
|
||||
|
||||
|
||||
String accessKey = this.config.getOrDefault("access_key", "");
|
||||
String secretKey = this.config.getOrDefault("secret_key", "");
|
||||
String bucket = this.config.getOrDefault("bucket", "");
|
||||
Auth auth = Auth.create(accessKey, secretKey);
|
||||
Configuration cfg = new Configuration(Region.region2());
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
Response response = bucketManager.delete(bucket, filePath);
|
||||
System.out.println(response);
|
||||
} catch (QiniuException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue