|
@@ -963,17 +963,22 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
String cacheFormat = "downloads/scene/%s/caches/";
|
|
|
String cacheImageFormat = "downloads/scene/%s/caches/images/";
|
|
|
|
|
|
+ String url = null;
|
|
|
+ String downloadName = null;
|
|
|
//删除本地文件
|
|
|
FileUtils.deleteDirectory(localImagesPath);
|
|
|
//如果入参文件名不为空,则是单个文件下载,不需要打包
|
|
|
+ boolean single = true;
|
|
|
if(StrUtil.isNotEmpty(fileName)){
|
|
|
- //先下载到本地
|
|
|
- if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
|
|
|
+ //如果是单张图片,直接提供oss url
|
|
|
+ if (!StorageType.LOCAL.code().equals(this.type)) {
|
|
|
String filePath = imgCachePath + fileName;
|
|
|
- String imageUrl = ossUrlPrefix + filePath + "?t=" + System.currentTimeMillis();
|
|
|
- FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
|
|
|
+ url = ossUrlPrefix + filePath;
|
|
|
+// FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
|
|
|
}
|
|
|
+ downloadName = fileName;
|
|
|
}else{
|
|
|
+ single = false;
|
|
|
//先下载到本地
|
|
|
List<String> keyList = uploadToOssUtil.listKeys(imgCachePath);
|
|
|
if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
|
|
@@ -985,22 +990,23 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //打包
|
|
|
- String zipName = num + "_images.zip";
|
|
|
- String zipPath = cachePath + zipName;
|
|
|
- FileUtils.zipFile(zipPath, localImagesPath);
|
|
|
- //上传压缩包
|
|
|
- uploadToOssUtil.upload(zipPath, String.format(cacheFormat, num) + zipName);
|
|
|
- String url = ossUrlPrefix + String.format(cacheFormat, num) + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
-
|
|
|
- //删除本地压缩包
|
|
|
- FileUtils.deleteFile(zipPath);
|
|
|
- //删除本地目录
|
|
|
- FileUtils.deleteDirectory(localImagesPath);
|
|
|
+ if(!single){
|
|
|
+ downloadName = num + "_images.zip";
|
|
|
+ //打包
|
|
|
+ String zipPath = cachePath + downloadName;
|
|
|
+ FileUtils.zipFile(zipPath, localImagesPath);
|
|
|
+ //上传压缩包
|
|
|
+ uploadToOssUtil.upload(zipPath, String.format(cacheFormat, num) + downloadName);
|
|
|
+ url = ossUrlPrefix + String.format(cacheFormat, num) + downloadName;
|
|
|
+ //删除本地压缩包
|
|
|
+ FileUtils.deleteFile(zipPath);
|
|
|
+ //删除本地目录
|
|
|
+ FileUtils.deleteDirectory(localImagesPath);
|
|
|
+ }
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
|
|
|
- map.put("fileName", zipName);
|
|
|
+ map.put("fileName", downloadName);
|
|
|
return ResultData.ok(map);
|
|
|
}
|
|
|
|