mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
feat:添加强制删除,优化七牛云对接
This commit is contained in:
@@ -196,7 +196,7 @@
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>7.2.22</version>
|
||||
<version>7.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.TokenExpiredException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -24,7 +23,7 @@ public class JWTUtil {
|
||||
|
||||
public static String createToken(User user){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.SECOND,604800 );//单位秒,604800 为7天
|
||||
calendar.add(Calendar.SECOND,2592000 );//单位秒
|
||||
Algorithm algorithm = Algorithm.HMAC256(SECRET);
|
||||
String token = JWT.create()
|
||||
.withClaim("email", user.getEmail())
|
||||
|
||||
@@ -467,6 +467,7 @@ public class AdminController {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String images = jsonObj.getString("images");
|
||||
String uuid = jsonObj.getString("uuid");
|
||||
Boolean forceDel = jsonObj.getBoolean("forceDel")==null?false:jsonObj.getBoolean("forceDel");
|
||||
if (images == null) {
|
||||
msg.setCode("404");
|
||||
msg.setInfo("为获取到图像信息");
|
||||
@@ -499,7 +500,7 @@ public class AdminController {
|
||||
if (imgIds.size() == 0) {
|
||||
msg.setCode("110404");
|
||||
} else {
|
||||
deleimages.dele(uuid, imgIds.stream().toArray(Long[]::new));
|
||||
deleimages.dele(forceDel,uuid, imgIds.stream().toArray(Long[]::new));
|
||||
msg.setCode("200");
|
||||
}
|
||||
return msg;
|
||||
|
||||
@@ -44,10 +44,11 @@ public class IndexController {
|
||||
@Autowired private IRedisService iRedisService;
|
||||
@Autowired private AppClientService appClientService;
|
||||
|
||||
public static String version = "20230925";
|
||||
@RequestMapping(value = "/")
|
||||
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
|
||||
model.addAttribute("name", "服务端程序(开源版)");
|
||||
model.addAttribute("version", "20230925");
|
||||
model.addAttribute("version", version);
|
||||
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
|
||||
model.addAttribute("links", "https://github.com/Hello-hao/tbed");
|
||||
return "welcome";
|
||||
@@ -64,6 +65,7 @@ public class IndexController {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
AppClient appClient = appClientService.getAppClientData("app");
|
||||
jsonObject.put("webname", cd.getString("webname"));
|
||||
jsonObject.put("version",version);
|
||||
jsonObject.put("websubtitle", cd.getString("websubtitle"));
|
||||
jsonObject.put("keywords", cd.getString("keywords"));
|
||||
jsonObject.put("webms", cd.getString("webms"));
|
||||
@@ -79,6 +81,7 @@ public class IndexController {
|
||||
jsonObject.put("clientname", appClient.getAppname());
|
||||
jsonObject.put("clientlogo", appClient.getApplogo());
|
||||
jsonObject.put("appupdate", appClient.getAppupdate());
|
||||
jsonObject.put("serverVersion",version);
|
||||
msg.setData(jsonObject);
|
||||
return msg;
|
||||
}
|
||||
@@ -380,7 +383,7 @@ public class IndexController {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
msg = deleimages.dele(null, image.getId());
|
||||
msg = deleimages.dele(false,null, image.getId());
|
||||
List<Long> Delids = (List<Long>) msg.getData();
|
||||
if (!Delids.contains(image.getId())) {
|
||||
msg.setCode("500");
|
||||
|
||||
@@ -5,10 +5,10 @@ import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import com.google.gson.Gson;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
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;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
@@ -28,18 +28,7 @@ public class KODOImageupload {
|
||||
public ReturnImage ImageuploadKODO(
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
Configuration cfg;
|
||||
if (key.getEndpoint().equals("1")) {
|
||||
cfg = new Configuration(Zone.zone0());
|
||||
} else if (key.getEndpoint().equals("2")) {
|
||||
cfg = new Configuration(Zone.zone1());
|
||||
} else if (key.getEndpoint().equals("3")) {
|
||||
cfg = new Configuration(Zone.zone2());
|
||||
} else if (key.getEndpoint().equals("4")) {
|
||||
cfg = new Configuration(Zone.zoneNa0());
|
||||
} else {
|
||||
cfg = new Configuration(Zone.zoneAs0());
|
||||
}
|
||||
Configuration cfg = new Configuration(Region.autoRegion());
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(key.getAccessKey(), key.getAccessSecret());
|
||||
String upToken = auth.uploadToken(key.getBucketname(), null, 7200, null);
|
||||
@@ -76,41 +65,25 @@ public class KODOImageupload {
|
||||
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(k.getAccessKey())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getAccessSecret())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getEndpoint())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getBucketname())
|
||||
if (StringUtils.isBlank(k.getAccessKey())
|
||||
|| StringUtils.isBlank(k.getAccessSecret())
|
||||
|| StringUtils.isBlank(k.getEndpoint())
|
||||
|| StringUtils.isBlank(k.getBucketname())
|
||||
|| StringUtils.isBlank(k.getRequestAddress())) {
|
||||
return -1;
|
||||
}
|
||||
Configuration cfg;
|
||||
if (k.getEndpoint().equals("1")) {
|
||||
cfg = new Configuration(Zone.zone0());
|
||||
} else if (k.getEndpoint().equals("2")) {
|
||||
cfg = new Configuration(Zone.zone1());
|
||||
} else if (k.getEndpoint().equals("3")) {
|
||||
cfg = new Configuration(Zone.zone2());
|
||||
} else if (k.getEndpoint().equals("4")) {
|
||||
cfg = new Configuration(Zone.zoneNa0());
|
||||
} else {
|
||||
cfg = new Configuration(Zone.zoneAs0());
|
||||
}
|
||||
Configuration cfg = new Configuration(Region.autoRegion());
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
|
||||
String upToken =
|
||||
auth.uploadToken(
|
||||
k.getBucketname(),
|
||||
null,
|
||||
7200,
|
||||
null); // auth.uploadToken(k.getBucketname());
|
||||
BucketManager bmObj = new BucketManager(auth, cfg);
|
||||
String upToken = auth.uploadToken(k.getBucketname(), null, 7200, null);
|
||||
BucketManager BM = new BucketManager(auth, cfg);
|
||||
BucketManager.FileListIterator fileListIterator = null;
|
||||
try {
|
||||
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
|
||||
fileListIterator = BM.createFileListIterator(k.getBucketname(), "", 1, "/");
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
if (items != null) {
|
||||
ret = 1;
|
||||
bucketManager = bmObj;
|
||||
bucketManager = BM;
|
||||
key = k;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class deleImages {
|
||||
@Autowired private KeysServiceImpl keysService;
|
||||
@Autowired private IRedisService iRedisService;
|
||||
|
||||
public Msg dele(String uuid, Long... imgIds) {
|
||||
public Msg dele(boolean forceDel,String uuid, Long... imgIds) {
|
||||
Msg msg = new Msg();
|
||||
MyProgress myProgress = new MyProgress();
|
||||
myProgress.InitializeDelImg();
|
||||
@@ -44,6 +44,20 @@ public class deleImages {
|
||||
boolean isDele = false;
|
||||
try {
|
||||
Images image = imgService.selectByPrimaryKey(imgIds[i]);
|
||||
if (!forceDel) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
}
|
||||
}
|
||||
Keys key = keysService.selectKeys(image.getSource());
|
||||
if (key.getStorageType() == 1) {
|
||||
isDele = nosImageupload.delNOS(key.getId(), image);
|
||||
@@ -64,20 +78,21 @@ public class deleImages {
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
// if (isDele) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
if (!forceDel) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
if(uuid!=null){
|
||||
myProgress.setDelSuccessCount(successCount);
|
||||
myProgress.setDelSuccessImgList(ids);
|
||||
|
||||
Reference in New Issue
Block a user