修改bug
This commit is contained in:
parent
df1938f556
commit
c6358646f7
|
@ -499,6 +499,7 @@ public class CommonController {
|
|||
if (imgPath.endsWith(SymbolConstant.COMMA)) {
|
||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||
}
|
||||
|
||||
//update-begin---author:liusq ---date:20230912 for:检查下载文件类型--------------
|
||||
SsrfFileTypeFilter.checkDownloadFileType(imgPath);
|
||||
//update-end---author:liusq ---date:20230912 for:检查下载文件类型--------------
|
||||
|
@ -511,6 +512,7 @@ public class CommonController {
|
|||
if(index != -1){
|
||||
path = imgPath.substring(0,index);
|
||||
}
|
||||
System.out.println("------------------------path:"+path);
|
||||
//TODO 不确定是否有问题,
|
||||
Map<String,String> map = SFTPUtil.download(sftpConfig,imgPath,getDownloadPath(path));
|
||||
System.out.println("msg-->"+map.get("msg"));
|
||||
|
@ -518,23 +520,6 @@ public class CommonController {
|
|||
response.setStatus(404);
|
||||
throw new RuntimeException(map.get("msg"));
|
||||
}
|
||||
// String localFilePath = map.get("fileName");
|
||||
// File file = new File(localFilePath);
|
||||
// if(!file.exists()){
|
||||
// response.setStatus(404);
|
||||
// throw new RuntimeException("文件["+imgPath+"]不存在..");
|
||||
// }
|
||||
// // 设置强制下载不打开
|
||||
//// response.setContentType("application/force-download");
|
||||
// response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
|
||||
// inputStream = new BufferedInputStream(new FileInputStream(localFilePath));
|
||||
// outputStream = response.getOutputStream();
|
||||
// byte[] buf = new byte[1024];
|
||||
// int len;
|
||||
// while ((len = inputStream.read(buf)) > 0) {
|
||||
// outputStream.write(buf, 0, len);
|
||||
// }
|
||||
// response.flushBuffer();
|
||||
}catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
}finally {
|
||||
|
@ -544,25 +529,77 @@ public class CommonController {
|
|||
}else {
|
||||
|
||||
}
|
||||
// String filePath = uploadpath + File.separator + imgPath;
|
||||
// filePath.replaceAll(" ","");
|
||||
// File file = new File(filePath);
|
||||
// if(!file.exists()){
|
||||
// response.setStatus(404);
|
||||
// log.error("文件["+imgPath+"]不存在..");
|
||||
// //throw new RuntimeException();
|
||||
// }
|
||||
// // 设置强制下载不打开
|
||||
// response.setContentType("application/force-download");
|
||||
// response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
|
||||
// inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
// outputStream = response.getOutputStream();
|
||||
// byte[] buf = new byte[1024];
|
||||
// int len;
|
||||
// while ((len = inputStream.read(buf)) > 0) {
|
||||
// outputStream.write(buf, 0, len);
|
||||
// }
|
||||
// response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
log.error("预览文件失败" + e.getMessage());
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.OK(null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/ycxz2", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<?> ycxz2(@RequestBody JSONObject jsonObject, HttpServletResponse response) {
|
||||
String downpath = jsonObject.getString("filename");
|
||||
String xsxh = jsonObject.getString("xsxh");
|
||||
System.out.println("downPath---->"+downpath);
|
||||
for(String imgPath: downpath.split(",")){
|
||||
System.out.println("imgPath---->"+imgPath);
|
||||
// 其余处理略
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
imgPath = imgPath.replace("..", "").replace("../","");
|
||||
if (imgPath.endsWith(SymbolConstant.COMMA)) {
|
||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||
}
|
||||
|
||||
// imgPath = imgPath.substring(0, imgPath.lastIndexOf("."))+xsxh+imgPath.substring(imgPath.lastIndexOf(".")+1,imgPath.length());
|
||||
//update-begin---author:liusq ---date:20230912 for:检查下载文件类型--------------
|
||||
SsrfFileTypeFilter.checkDownloadFileType(imgPath);
|
||||
//update-end---author:liusq ---date:20230912 for:检查下载文件类型--------------
|
||||
// if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
|
||||
if(1==1) {
|
||||
try{
|
||||
// SFTPUtil.writeFileToRes(sftpConfig,imgPath,response);
|
||||
int index = imgPath.lastIndexOf("/");
|
||||
String path = "temp";
|
||||
if(index != -1){
|
||||
path = imgPath.substring(0,index);
|
||||
}
|
||||
System.out.println("------------------------path:"+path);
|
||||
//TODO 不确定是否有问题,
|
||||
Map<String,String> map = SFTPUtil.downloadReplacename(sftpConfig,imgPath,getDownloadPath(path),xsxh);
|
||||
System.out.println("msg-->"+map.get("msg"));
|
||||
if(!map.get("code").equals("0")){
|
||||
response.setStatus(404);
|
||||
throw new RuntimeException(map.get("msg"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
}finally {
|
||||
SFTPUtil.disChannel();
|
||||
SFTPUtil.disSession();
|
||||
}
|
||||
}else {
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("预览文件失败" + e.getMessage());
|
||||
response.setStatus(404);
|
||||
|
|
|
@ -803,4 +803,78 @@ public class SFTPUtil {
|
|||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param directory 下载目录
|
||||
* @param saveFile 存在本地的路径
|
||||
*/
|
||||
public static Map<String,String> downloadReplacename(SftpConfig sftpConfig, String directory, String saveFile,String xsxh) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("code","0");
|
||||
map.put("msg","下载成功");
|
||||
directory = sftpConfig.getFullpath()+"/"+ directory;
|
||||
String[] df = getDirectoryAndFileName(directory);
|
||||
|
||||
File localDirFile = new File(saveFile);
|
||||
// 判断本地目录是否存在,不存在需要新建各级目录
|
||||
if (!localDirFile.exists()) {
|
||||
localDirFile.mkdirs();
|
||||
}
|
||||
saveFile = saveFile.replace("\\","/");
|
||||
String newName = CommonUtils.getFileName(df[1]);
|
||||
if(!newName.startsWith("/")){
|
||||
newName = "/"+newName;
|
||||
newName = newName.substring(0,newName.lastIndexOf(".")) + xsxh + newName.substring(newName.lastIndexOf("."),newName.length());
|
||||
}
|
||||
String newDownloadFile = saveFile.concat(newName);
|
||||
|
||||
File localFile = new File(newDownloadFile);
|
||||
// 判断本地目录是否存在,不存在需要新建各级目录
|
||||
if (localFile.exists()) {
|
||||
map.put("fileName",newDownloadFile);
|
||||
return map;
|
||||
}
|
||||
|
||||
try{
|
||||
if(sftp == null){
|
||||
getChannelSftp(sftpConfig);
|
||||
if(sftp == null){
|
||||
map.put("code","1");
|
||||
map.put("msg","sftp链接异常:");
|
||||
return map;
|
||||
}
|
||||
}else{
|
||||
sftp.cd(sftpConfig.getFullpath());
|
||||
}
|
||||
OutputStream output = null;
|
||||
try {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("开始获取远程文件:[{}]---->[{}]", new Object[]{directory, newDownloadFile});
|
||||
}
|
||||
// sftp.cd(directory);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("打开远程文件:[{}]", new Object[]{directory});
|
||||
}
|
||||
output = new FileOutputStream(localFile);
|
||||
sftp.get(directory, output);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("文件下载成功");
|
||||
}
|
||||
map.put("fileName",newDownloadFile);
|
||||
} catch (Exception e) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("文件下载出现异常,[{}]", e);
|
||||
}
|
||||
throw new RuntimeException("文件下载出现异常,[{}]", e);
|
||||
} finally {
|
||||
closeStream(null,output);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
map.put("code","1");
|
||||
map.put("msg","sftp异常:" + e.getMessage());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# port
|
||||
VITE_PORT = 3100
|
||||
VITE_PORT = 3101
|
||||
|
||||
# 网站标题
|
||||
VITE_GLOB_APP_TITLE = 教学督导平台
|
||||
|
|
|
@ -432,6 +432,7 @@ async function handleChakan(record) {
|
|||
lwinfo.value = record;
|
||||
console.log("lwinfo--->",lwinfo)
|
||||
sfxk.value = 2;
|
||||
const xsxh = record.xsxh;
|
||||
|
||||
var filename = "";
|
||||
|
||||
|
@ -450,20 +451,27 @@ async function handleChakan(record) {
|
|||
|
||||
if(filename){
|
||||
console.log("filename--->",filename)
|
||||
defHttp.post({ url: '/sys/common/ycxz',params:{filename} }).then((res) => {});
|
||||
await defHttp.post({ url: '/sys/common/ycxz2',params:{filename,xsxh} }).then((res) => {});
|
||||
}
|
||||
|
||||
ktbgUrl.value = '';
|
||||
if (record.ktbg) {
|
||||
var file1 = getFileAccessHttpUrl(record.ktbg.replaceAll(" ",""));
|
||||
console.log("file1---->",file1);
|
||||
console.log("file11111---->",encodeURIComponent(encryptByBase64(file1)));
|
||||
var file = record.ktbg;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.ktbg:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
ktbgUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
console.log("🚀 ~ handleChakan ~ ktbgUrl.value:", ktbgUrl.value)
|
||||
} else {
|
||||
ktbgUrl.value = '';
|
||||
}
|
||||
|
||||
ktbgshyjUrl.value = '';
|
||||
if (record.ktbgshyj) {
|
||||
var file1 = getFileAccessHttpUrl(record.ktbgshyj.replaceAll(" ",""));
|
||||
var file = record.ktbgshyj;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.ktbgshyj:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
ktbgshyjUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
ktbgshyjUrl.value = '';
|
||||
|
@ -476,15 +484,22 @@ async function handleChakan(record) {
|
|||
// zqjcUrl.value = '';
|
||||
// }
|
||||
|
||||
lwzgUrl.value = '';
|
||||
if (record.lwzg) {
|
||||
var file1 = getFileAccessHttpUrl(record.lwzg.replaceAll(" ",""));
|
||||
var file = record.lwzg;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.lwzg:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
lwzgUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
lwzgUrl.value = '';
|
||||
}
|
||||
|
||||
zdjldUrl.value = '';
|
||||
if (record.zdjld) {
|
||||
var file1 = getFileAccessHttpUrl(record.zdjld.replaceAll(" ",""));
|
||||
var file = record.zdjld;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.zdjld:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
zdjldUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
zdjldUrl.value = '';
|
||||
|
|
|
@ -427,49 +427,89 @@ function handleYulan(record) {
|
|||
}
|
||||
//查看论文材料
|
||||
async function handleChakan(record) {
|
||||
console.log("record--->",record)
|
||||
lwinfo.value = record;
|
||||
console.log("lwinfo--->",lwinfo)
|
||||
sfxk.value = 2;
|
||||
const xsxh = record.xsxh;
|
||||
|
||||
if (lwinfo.value.ktbg) {
|
||||
var file1 = getFileAccessHttpUrl(record.ktbg);
|
||||
var filename = "";
|
||||
|
||||
if (record.ktbg) {
|
||||
filename = filename+record.ktbg+",";
|
||||
}
|
||||
if (record.ktbgshyj) {
|
||||
filename = filename+record.ktbgshyj+",";
|
||||
}
|
||||
if (record.lwzg) {
|
||||
filename = filename+record.lwzg+",";
|
||||
}
|
||||
if (record.zdjld) {
|
||||
filename = filename+record.zdjld+",";
|
||||
}
|
||||
|
||||
if(filename){
|
||||
console.log("filename--->",filename)
|
||||
await defHttp.post({ url: '/sys/common/ycxz2',params:{filename,xsxh} }).then((res) => {});
|
||||
}
|
||||
|
||||
ktbgUrl.value = '';
|
||||
if (record.ktbg) {
|
||||
var file = record.ktbg;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.ktbg:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
ktbgUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
console.log("🚀 ~ handleChakan ~ ktbgUrl.value:", ktbgUrl.value)
|
||||
} else {
|
||||
ktbgUrl.value = '';
|
||||
}
|
||||
|
||||
if (lwinfo.value.ktbgshyj) {
|
||||
var file1 = getFileAccessHttpUrl(record.ktbgshyj);
|
||||
ktbgshyjUrl.value = '';
|
||||
if (record.ktbgshyj) {
|
||||
var file = record.ktbgshyj;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.ktbgshyj:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
ktbgshyjUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
ktbgshyjUrl.value = '';
|
||||
}
|
||||
|
||||
if (lwinfo.value.zqjc) {
|
||||
var file1 = getFileAccessHttpUrl(record.zqjc);
|
||||
zqjcUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
zqjcUrl.value = '';
|
||||
}
|
||||
// if (lwinfo.value.zqjc) {
|
||||
// var file1 = getFileAccessHttpUrl(record.zqjc.replace(" ",""));
|
||||
// zqjcUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
// } else {
|
||||
// zqjcUrl.value = '';
|
||||
// }
|
||||
|
||||
if (lwinfo.value.lwzg) {
|
||||
var file1 = getFileAccessHttpUrl(record.lwzg);
|
||||
lwzgUrl.value = '';
|
||||
if (record.lwzg) {
|
||||
var file = record.lwzg;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.lwzg:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
lwzgUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
lwzgUrl.value = '';
|
||||
}
|
||||
|
||||
if (lwinfo.value.zdjld) {
|
||||
var file1 = getFileAccessHttpUrl(record.zdjld);
|
||||
zdjldUrl.value = '';
|
||||
if (record.zdjld) {
|
||||
var file = record.zdjld;
|
||||
file = file.substring(0,file.lastIndexOf(".")) + xsxh + file.substring(file.lastIndexOf("."),file.length);
|
||||
console.log("🚀 ~ handleChakan ~ record.zdjld:", file)
|
||||
var file1 = getFileAccessHttpUrl(file.replaceAll(" ",""));
|
||||
zdjldUrl.value = 'https://jxdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file1));
|
||||
} else {
|
||||
zdjldUrl.value = '';
|
||||
}
|
||||
|
||||
if (lwinfo.value.ccjg) {
|
||||
if (record.ccjg) {
|
||||
jcbgUrl.value = record.ccjg;
|
||||
} else {
|
||||
jcbgUrl.value = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const getViewFileDomain = () => defHttp.get({ url: '/sys/comment/getFileViewDomain' });
|
||||
|
|
Loading…
Reference in New Issue