Compare commits
No commits in common. "2fc7032a795e8c22ead71a776fbe3ea38d312b9c" and "7f7cee2453bc8912c91e757dfd5017fbd2baf532" have entirely different histories.
2fc7032a79
...
7f7cee2453
|
|
@ -65,12 +65,7 @@
|
||||||
<groupId>com.bonus</groupId>
|
<groupId>com.bonus</groupId>
|
||||||
<artifactId>bonus-common-swagger</artifactId>
|
<artifactId>bonus-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-net</groupId>
|
|
||||||
<artifactId>commons-net</artifactId>
|
|
||||||
<version>3.9.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
package com.bonus.file.controller;
|
package com.bonus.file.controller;
|
||||||
|
|
||||||
import com.bonus.common.core.utils.Base64Utils;
|
|
||||||
import com.bonus.file.utils.FileDownloadUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.bonus.common.core.domain.R;
|
import com.bonus.common.core.domain.R;
|
||||||
|
|
@ -15,8 +11,6 @@ import com.bonus.common.core.utils.file.FileUtils;
|
||||||
import com.bonus.file.service.ISysFileService;
|
import com.bonus.file.service.ISysFileService;
|
||||||
import com.bonus.system.api.domain.SysFile;
|
import com.bonus.system.api.domain.SysFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件请求处理
|
* 文件请求处理
|
||||||
*
|
*
|
||||||
|
|
@ -51,35 +45,4 @@ public class SysFileController
|
||||||
return R.fail(e.getMessage());
|
return R.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/download")
|
|
||||||
public R<Boolean> downloadFile(String url, String destination) {
|
|
||||||
try {
|
|
||||||
String fileUrl = Base64Utils.decodeUrl(url);
|
|
||||||
if (fileUrl != null) {
|
|
||||||
String fileName = Base64Utils.getFileNameFromURL(fileUrl);
|
|
||||||
sysFileService.downloadFile(fileUrl, destination + "/" + fileName);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("下载文件失败", e);
|
|
||||||
return R.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
return R.fail("下载文件失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/delete")
|
|
||||||
public R<Boolean> deleteFile(String url) {
|
|
||||||
try {
|
|
||||||
String fileUrl = Base64Utils.decodeUrl(url);
|
|
||||||
if (fileUrl != null) {
|
|
||||||
sysFileService.deleteFile(fileUrl);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("delete文件失败", e);
|
|
||||||
return R.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
return R.fail("传入参数不满足要求");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -43,17 +43,4 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
IoUtils.closeQuietly(inputStream);
|
IoUtils.closeQuietly(inputStream);
|
||||||
return domain + "/" + storePath.getFullPath();
|
return domain + "/" + storePath.getFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean downloadFile(String urlStr, String destination) throws Exception
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteFile(String urlStr) throws Exception
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,4 @@ public interface ISysFileService
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public String uploadFile(MultipartFile file) throws Exception;
|
public String uploadFile(MultipartFile file) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
public boolean downloadFile(String urlStr, String destination) throws Exception;
|
|
||||||
|
|
||||||
|
|
||||||
public boolean deleteFile(String urlStr) throws Exception;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,11 @@
|
||||||
package com.bonus.file.service;
|
package com.bonus.file.service;
|
||||||
|
|
||||||
import com.bonus.file.utils.FileDownloadUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.bonus.file.utils.FileUploadUtils;
|
import com.bonus.file.utils.FileUploadUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件存储
|
* 本地文件存储
|
||||||
*
|
*
|
||||||
|
|
@ -53,29 +47,4 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
String url = domain + localFilePrefix + name;
|
String url = domain + localFilePrefix + name;
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean downloadFile(String urlStr, String destination) throws Exception
|
|
||||||
{
|
|
||||||
return FileDownloadUtils.downloadFile(urlStr, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteFile(String urlStr) throws Exception
|
|
||||||
{
|
|
||||||
String regex = String.format("^(.*?%s)", localFilePrefix);
|
|
||||||
String updatePath = urlStr.replaceFirst(regex, localFilePath);
|
|
||||||
Path path = Paths.get(updatePath);
|
|
||||||
if (Files.exists(path)){
|
|
||||||
try {
|
|
||||||
Files.deleteIfExists(path);
|
|
||||||
}catch (IOException e){
|
|
||||||
throw new Exception(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
throw new Exception("删除文件时文件不存在");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,17 +46,4 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
IoUtils.closeQuietly(inputStream);
|
IoUtils.closeQuietly(inputStream);
|
||||||
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean downloadFile(String urlStr, String destination) throws Exception
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteFile(String urlStr) throws Exception
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue