fix some codestyle problem

pull/134/MERGE
陈精华 2023-05-06 16:51:06 +08:00
parent 9e3d450854
commit 93fb40d282
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D
19 changed files with 97 additions and 96 deletions

View File

@ -121,12 +121,12 @@ watermark.angle = ${WATERMARK_ANGLE:10}
#Tiftifjsjpgjpgpdfpdf便 #Tiftifjsjpgjpgpdfpdf便
tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif} tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif}
# #
BeiAn = beiAn =
# #
prohibit =exe,dll,dat prohibit =exe,dll,dat
# #
sc.password =123456 sc.password = 123456
# OFFICECADTIFF # OFFICECADTIFF
delete.source.file = true delete.source.file = true
PDFdpi #PDFdpi
pdf2jpg.dpi = 105 pdf2jpg.dpi = 105

View File

@ -42,12 +42,12 @@ public class ConfigConstants {
private static String pdfBookmarkDisable; private static String pdfBookmarkDisable;
private static Boolean fileUploadDisable; private static Boolean fileUploadDisable;
private static String tifPreviewType; private static String tifPreviewType;
private static String BeiAn; private static String beiAn;
private static String[] prohibit= {}; private static String[] prohibit = {};
private static String size; private static String size;
private static String password; private static String password;
private static int pdf2JpgDpi; private static int pdf2JpgDpi;
private static Boolean deletesourcefile; private static Boolean deleteSourceFile;
public static final String DEFAULT_CACHE_ENABLED = "true"; public static final String DEFAULT_CACHE_ENABLED = "true";
public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd"; public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@ -68,12 +68,12 @@ public class ConfigConstants {
public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true"; public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true";
public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false"; public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false";
public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif"; public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif";
public static final String DEFAULT_BeiAn_DISABLE = "无"; public static final String DEFAULT_BEIAN = "无";
public static final String DEFAULT_size_DISABLE = "500MB"; public static final String DEFAULT_SIZE = "500MB";
public static final String DEFAULT_prohibit_DISABLE = "exe,dll"; public static final String DEFAULT_PROHIBIT = "exe,dll";
public static final String DEFAULT_password_DISABLE = "123456"; public static final String DEFAULT_PASSWORD = "123456";
public static final String DEFAULT_PDF2_JPG_DPI_DISABLE = "105"; public static final String DEFAULT_PDF2_JPG_DPI_DISABLE = "105";
public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true"; public static final String DEFAULT_DELETE_SOURCE_FILE = "true";
public static Boolean isCacheEnabled() { public static Boolean isCacheEnabled() {
return cacheEnabled; return cacheEnabled;
@ -367,73 +367,73 @@ public class ConfigConstants {
} }
public static String getBeiAn() { public static String getBeiAn() {
return BeiAn; return beiAn;
} }
@Value("${BeiAn:无}") @Value("${beiAn:无}")
public void setBeiAn(String BeiAn) { public void setBeiAn(String beiAn) {
setBeiAnValue(BeiAn); setBeiAnValue(beiAn);
} }
public static void setBeiAnValue(String BeiAn) { public static void setBeiAnValue(String beiAn) {
ConfigConstants.BeiAn = BeiAn; ConfigConstants.beiAn = beiAn;
} }
public static String[] getprohibit() { public static String[] getProhibit() {
return prohibit; return prohibit;
} }
@Value("${prohibit:exe,dll}") @Value("${prohibit:exe,dll}")
public void setprohibit(String prohibit) { public void setProhibit(String prohibit) {
String[] prohibittArr = prohibit.split(","); String[] prohibitArr = prohibit.split(",");
setprohibitValue(prohibittArr); setProhibitValue(prohibitArr);
} }
public static void setprohibitValue(String[] prohibit) { public static void setProhibitValue(String[] prohibit) {
ConfigConstants.prohibit = prohibit; ConfigConstants.prohibit = prohibit;
} }
public static String maxsize() { public static String maxSize() {
return size; return size;
} }
@Value("${spring.servlet.multipart.max-file-size:500MB}") @Value("${spring.servlet.multipart.max-file-size:500MB}")
public void setsize(String size) { public void setSize(String size) {
setsizeValue(size); setSizeValue(size);
} }
public static void setsizeValue(String size) { public static void setSizeValue(String size) {
ConfigConstants.size = size; ConfigConstants.size = size;
} }
public static String getpassword() { public static String getPassword() {
return password; return password;
} }
@Value("${sc.password:123456}") @Value("${sc.password:123456}")
public void setpassword(String password) { public void setPassword(String password) {
setpasswordValue(password); setPasswordValue(password);
} }
public static void setpasswordValue(String password) { public static void setPasswordValue(String password) {
ConfigConstants.password = password; ConfigConstants.password = password;
} }
public static int getpdf2JpgDpi() { public static int getPdf2JpgDpi() {
return pdf2JpgDpi; return pdf2JpgDpi;
} }
@Value("${pdf.picture.size:105}") @Value("${pdf.picture.size:105}")
public void pdf2JpgDpi(int pdf2JpgDpi) { public void pdf2JpgDpi(int pdf2JpgDpi) {
setpdf2JpgDpiValue(pdf2JpgDpi); setPdf2JpgDpiValue(pdf2JpgDpi);
} }
public static void setpdf2JpgDpiValue(int pdf2JpgDpi) { public static void setPdf2JpgDpiValue(int pdf2JpgDpi) {
ConfigConstants.pdf2JpgDpi = pdf2JpgDpi; ConfigConstants.pdf2JpgDpi = pdf2JpgDpi;
} }
public static Boolean getdeletesourcefile() { public static Boolean getDeleteSourceFile() {
return deletesourcefile; return deleteSourceFile;
} }
@Value("${delete.source.file:true}") @Value("${delete.source.file:true}")
public void setdeletesourcefile(Boolean deletesourcefile) { public void setDeleteSourceFile(Boolean deleteSourceFile) {
setdeletesourcefileValue(deletesourcefile); setDeleteSourceFileValue(deleteSourceFile);
} }
public static void setdeletesourcefileValue(Boolean deletesourcefile) { public static void setDeleteSourceFileValue(Boolean deleteSourceFile) {
ConfigConstants.deletesourcefile = deletesourcefile; ConfigConstants.deleteSourceFile = deleteSourceFile;
} }
} }

View File

@ -55,11 +55,11 @@ public class ConfigRefreshComponent {
String tifPreviewType; String tifPreviewType;
String prohibit; String prohibit;
String[] prohibitArray; String[] prohibitArray;
String BeiAn; String beiAn;
String size; String size;
String password; String password;
int pdf2JpgDpi; int pdf2JpgDpi;
Boolean deletesourcefile; boolean deleteSourceFile;
while (true) { while (true) {
FileReader fileReader = new FileReader(configFilePath); FileReader fileReader = new FileReader(configFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader); BufferedReader bufferedReader = new BufferedReader(fileReader);
@ -84,12 +84,12 @@ public class ConfigRefreshComponent {
pdfBookmarkDisable = properties.getProperty("pdf.bookmark.disable", ConfigConstants.DEFAULT_PDF_BOOKMARK_DISABLE); pdfBookmarkDisable = properties.getProperty("pdf.bookmark.disable", ConfigConstants.DEFAULT_PDF_BOOKMARK_DISABLE);
fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE)); fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE));
tifPreviewType = properties.getProperty("tif.preview.type", ConfigConstants.DEFAULT_TIF_PREVIEW_TYPE); tifPreviewType = properties.getProperty("tif.preview.type", ConfigConstants.DEFAULT_TIF_PREVIEW_TYPE);
size = properties.getProperty("spring.servlet.multipart.max-file-size", ConfigConstants.DEFAULT_size_DISABLE); size = properties.getProperty("spring.servlet.multipart.max-file-size", ConfigConstants.DEFAULT_SIZE);
BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE); beiAn = properties.getProperty("beiAn", ConfigConstants.DEFAULT_BEIAN);
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE); prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_PROHIBIT);
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE); password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_PASSWORD);
pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI_DISABLE)); pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI_DISABLE));
deletesourcefile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE)); deleteSourceFile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_DELETE_SOURCE_FILE));
prohibitArray = prohibit.split(","); prohibitArray = prohibit.split(",");
ConfigConstants.setCacheEnabledValueValue(cacheEnabled); ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
@ -109,12 +109,12 @@ public class ConfigRefreshComponent {
ConfigConstants.setPdfBookmarkDisableValue(pdfBookmarkDisable); ConfigConstants.setPdfBookmarkDisableValue(pdfBookmarkDisable);
ConfigConstants.setFileUploadDisableValue(fileUploadDisable); ConfigConstants.setFileUploadDisableValue(fileUploadDisable);
ConfigConstants.setTifPreviewTypeValue(tifPreviewType); ConfigConstants.setTifPreviewTypeValue(tifPreviewType);
ConfigConstants.setBeiAnValue(BeiAn); ConfigConstants.setBeiAnValue(beiAn);
ConfigConstants.setsizeValue(size); ConfigConstants.setSizeValue(size);
ConfigConstants.setprohibitValue(prohibitArray); ConfigConstants.setProhibitValue(prohibitArray);
ConfigConstants.setpasswordValue(password); ConfigConstants.setPasswordValue(password);
ConfigConstants.setpdf2JpgDpiValue(pdf2JpgDpi); ConfigConstants.setPdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setdeletesourcefileValue(deletesourcefile); ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
setWatermarkConfig(properties); setWatermarkConfig(properties);
bufferedReader.close(); bufferedReader.close();
fileReader.close(); fileReader.close();

View File

@ -120,7 +120,7 @@ public class FileAttribute {
public Boolean forceUpdatedCache() { public Boolean forceUpdatedCache() {
return forceUpdatedCache; return forceUpdatedCache;
} }
public void setforceUpdatedCache(Boolean forceUpdatedCache) { public void setForceUpdatedCache(Boolean forceUpdatedCache) {
this.forceUpdatedCache = forceUpdatedCache; this.forceUpdatedCache = forceUpdatedCache;
} }

View File

@ -1,6 +1,5 @@
package cn.keking.service; package cn.keking.service;
import cn.keking.config.ConfigConstants;
import cn.keking.model.FileType; import cn.keking.model.FileType;
import cn.keking.utils.RarUtils; import cn.keking.utils.RarUtils;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
@ -68,7 +67,6 @@ public class CompressFileReader {
if (result == ExtractOperationResult.OK) { if (result == ExtractOperationResult.OK) {
FileType type = FileType.typeFromUrl(str[0]); FileType type = FileType.typeFromUrl(str[0]);
if (type.equals(FileType.PICTURE)) { if (type.equals(FileType.PICTURE)) {
// System.out.println( baseUrl +folderName + "_" + str[0]);
imgUrls.add(baseUrl +folderName + "_/" + str[0].replace("\\", "/")); imgUrls.add(baseUrl +folderName + "_/" + str[0].replace("\\", "/"));
} }
fileHandlerService.putImgCache(fileName, imgUrls); fileHandlerService.putImgCache(fileName, imgUrls);

View File

@ -250,8 +250,8 @@ public class FileHandlerService {
String imageFilePath; String imageFilePath;
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format; imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format;
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getpdf2JpgDpi(), ImageType.RGB); BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getPdf2JpgDpi(), ImageType.RGB);
ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getpdf2JpgDpi()); ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getPdf2JpgDpi());
String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex); String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex);
imageUrls.add(imageUrl); imageUrls.add(imageUrl);
} }
@ -269,8 +269,7 @@ public class FileHandlerService {
} }
} catch (IOException e) { } catch (IOException e) {
System.out.println("发生错误:"+e); logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
// logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
throw new Exception(e); throw new Exception(e);
}finally { }finally {
if (doc != null) { //关闭 if (doc != null) { //关闭
@ -356,7 +355,6 @@ public class FileHandlerService {
fileName = strs[1] + urlStrr.trim(); fileName = strs[1] + urlStrr.trim();
attribute.setSkipDownLoad(true); attribute.setSkipDownLoad(true);
} }
// System.out.println(fileName);
url = WebUtils.encodeUrlFileName(url); url = WebUtils.encodeUrlFileName(url);
fileName = KkFileUtils.htmlEscape(fileName); //文件名处理 fileName = KkFileUtils.htmlEscape(fileName); //文件名处理
attribute.setType(type); attribute.setType(type);
@ -374,7 +372,7 @@ public class FileHandlerService {
attribute.setFileKey(fileKey); attribute.setFileKey(fileKey);
} }
if ("true".equalsIgnoreCase(forceUpdatedCache)) { if ("true".equalsIgnoreCase(forceUpdatedCache)) {
attribute.setforceUpdatedCache(true); attribute.setForceUpdatedCache(true);
} }
String tifPreviewType = req.getParameter("tifPreviewType"); String tifPreviewType = req.getParameter("tifPreviewType");

View File

@ -56,7 +56,8 @@ public class CadFilePreviewImpl implements FilePreview {
if (!convertResult) { if (!convertResult) {
return otherFilePreview.notSupportedFile(model, fileAttribute, "cad文件转换异常请联系管理员"); return otherFilePreview.notSupportedFile(model, fileAttribute, "cad文件转换异常请联系管理员");
} }
if( ConfigConstants.getdeletesourcefile()){ //是否保留CAD源文件 //是否保留CAD源文件
if( ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath); KkFileUtils.deleteFileByPath(filePath);
} }
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {

View File

@ -61,7 +61,8 @@ public class CompressFilePreviewImpl implements FilePreview {
} }
} }
if (!ObjectUtils.isEmpty(fileTree)) { if (!ObjectUtils.isEmpty(fileTree)) {
if( ConfigConstants.getdeletesourcefile()){ //是否保留压缩包源文件 //是否保留压缩包源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath); KkFileUtils.deleteFileByPath(filePath);
} }
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {

View File

@ -114,7 +114,8 @@ public class OfficeFilePreviewImpl implements FilePreview {
// 对转换后的文件进行操作(改变编码方式) // 对转换后的文件进行操作(改变编码方式)
fileHandlerService.doActionConvertedFile(outFilePath); fileHandlerService.doActionConvertedFile(outFilePath);
} }
if(ConfigConstants.getdeletesourcefile()){ //是否保留OFFICE源文件 //是否保留OFFICE源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath); KkFileUtils.deleteFileByPath(filePath);
} }
if (isUseCached) { if (isUseCached) {

View File

@ -60,8 +60,9 @@ public class TiffFilePreviewImpl implements FilePreview {
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg()); return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
} }
String filePath = response.getContent(); String filePath = response.getContent();
if(ConvertPicUtil.convertJpg2Pdf(filePath, outFilePath)){ if (ConvertPicUtil.convertJpg2Pdf(filePath, outFilePath)) {
if(ConfigConstants.getdeletesourcefile()){ //是否保留TIFF源文件 //是否保留TIFF源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath); KkFileUtils.deleteFileByPath(filePath);
} }
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {
@ -70,11 +71,10 @@ public class TiffFilePreviewImpl implements FilePreview {
} }
model.addAttribute("pdfUrl", pdfName); model.addAttribute("pdfUrl", pdfName);
return PDF_FILE_PREVIEW_PAGE; return PDF_FILE_PREVIEW_PAGE;
}else { } else {
return NOT_SUPPORTED_FILE_PAGE; return NOT_SUPPORTED_FILE_PAGE;
} }
} } else {
else {
model.addAttribute("pdfUrl", pdfName); model.addAttribute("pdfUrl", pdfName);
return PDF_FILE_PREVIEW_PAGE; return PDF_FILE_PREVIEW_PAGE;
} }

View File

@ -17,14 +17,18 @@ import javax.media.jai.RenderedOp;
import java.awt.image.RenderedImage; import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock; import java.awt.image.renderable.ParameterBlock;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ConvertPicUtil { public class ConvertPicUtil {
private static final int FIT_WIDTH = 500;
private static final int FIT_HEIGHT = 900;
private final static Logger logger = LoggerFactory.getLogger(ConvertPicUtil.class); private final static Logger logger = LoggerFactory.getLogger(ConvertPicUtil.class);
private final static String fileDir = ConfigConstants.getFileDir(); private final static String fileDir = ConfigConstants.getFileDir();
/** /**
@ -77,10 +81,7 @@ public class ConvertPicUtil {
RenderedOp renderedOp = JAI.create("filestore", pb); RenderedOp renderedOp = JAI.create("filestore", pb);
renderedOp.dispose(); renderedOp.dispose();
logger.info("每页分别保存至: " + fileJpg.getCanonicalPath()); logger.info("每页分别保存至: " + fileJpg.getCanonicalPath());
} else {
// logger.info("JPG文件已存在 " + fileJpg.getCanonicalPath());
} }
listImageFiles.add(strJpgUrl); listImageFiles.add(strJpgUrl);
} }
@ -105,14 +106,12 @@ public class ConvertPicUtil {
* @param strJpgFile jpg * @param strJpgFile jpg
* @param strPdfFile pdf * @param strPdfFile pdf
*/ */
private static final int FIT_WIDTH = 500;
private static final int FIT_HEIGHT = 900;
public static boolean convertJpg2Pdf(String strJpgFile, String strPdfFile) { public static boolean convertJpg2Pdf(String strJpgFile, String strPdfFile) {
Document document= null; Document document = null;
RandomAccessFileOrArray rafa = null; RandomAccessFileOrArray rafa = null;
try { try {
document = new Document(); document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(strPdfFile)); PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(strPdfFile)));
document.open(); document.open();
rafa = new RandomAccessFileOrArray(new FileChannelRandomAccessSource(new RandomAccessFile(strJpgFile, "r").getChannel())); rafa = new RandomAccessFileOrArray(new FileChannelRandomAccessSource(new RandomAccessFile(strJpgFile, "r").getChannel()));
int pages = TiffImage.getNumberOfPages(rafa); int pages = TiffImage.getNumberOfPages(rafa);
@ -131,15 +130,16 @@ public class ConvertPicUtil {
document.close(); document.close();
rafa.close(); rafa.close();
return true; return true;
} } catch (Exception e) {
catch (Exception e) logger.error("图片转PDF异常图片文件路径" + strJpgFile, e);
{ } finally {
System.out.println("错误:"+ e.getMessage());
}
finally {
document.close();
try { try {
rafa.close(); if (document != null && document.isOpen()) {
document.close();
}
if (rafa != null) {
rafa.close();
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -13,7 +13,6 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder;
import java.util.UUID; import java.util.UUID;
import static cn.keking.utils.KkFileUtils.isFtpUrl; import static cn.keking.utils.KkFileUtils.isFtpUrl;

View File

@ -43,7 +43,6 @@ public class EncodingDetects {
} }
public static void readFile(String file, String code) { public static void readFile(String file, String code) {
BufferedReader fr; BufferedReader fr;
try { try {
String myCode = code!=null&&!"".equals(code) ? code : "UTF8"; String myCode = code!=null&&!"".equals(code) ? code : "UTF8";

View File

@ -186,7 +186,7 @@ public class KkFileUtils {
*/ */
public static boolean isAllowedUpload(String file) { public static boolean isAllowedUpload(String file) {
String fileType = suffixFromFileName(file); String fileType = suffixFromFileName(file);
for (String type : ConfigConstants.getprohibit()) { for (String type : ConfigConstants.getProhibit()) {
if (type.equals(fileType)) if (type.equals(fileType))
return false; return false;
} }

View File

@ -2,6 +2,8 @@ package cn.keking.utils;
import io.mola.galimatias.GalimatiasParseException; import io.mola.galimatias.GalimatiasParseException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils; import org.springframework.util.Base64Utils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.HtmlUtils;
@ -24,6 +26,8 @@ import java.util.regex.Pattern;
**/ **/
public class WebUtils { public class WebUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(WebUtils.class);
/** /**
* URL * URL
* *
@ -209,7 +213,7 @@ public class WebUtils {
* *
* 2022/12/17 * 2022/12/17
*/ */
public static boolean hefaurl (String url) { public static boolean isValidUrl(String url) {
String regStr = "^((https|http|ftp|rtsp|mms|file)://)";//[.?*]表示匹配的就是本身 String regStr = "^((https|http|ftp|rtsp|mms|file)://)";//[.?*]表示匹配的就是本身
Pattern pattern = Pattern.compile(regStr); Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(url); Matcher matcher = pattern.matcher(url);
@ -253,8 +257,7 @@ public class WebUtils {
try { try {
return new String(Base64Utils.decodeFromString(source.replaceAll(" ", "+").replaceAll("\n", "")), charsets); return new String(Base64Utils.decodeFromString(source.replaceAll(" ", "+").replaceAll("\n", "")), charsets);
} catch (Exception e) { } catch (Exception e) {
System.out.println("接入方法错误,或者未使用BASE64"); LOGGER.error("url解码异常可能是接入方法错误或者未使用BASE64", e);
// e.printStackTrace();
return null; return null;
} }
} }

View File

@ -65,7 +65,7 @@ public class FileController {
return checkResult; return checkResult;
} }
fileName = checkResult.getContent().toString(); fileName = checkResult.getContent().toString();
if(!ConfigConstants.getpassword().equalsIgnoreCase(password)){ if(!ConfigConstants.getPassword().equalsIgnoreCase(password)) {
logger.error("删除文件【{}】失败,密码错误!",fileName); logger.error("删除文件【{}】失败,密码错误!",fileName);
return ReturnResponse.failure("删除文件失败,密码错误!"); return ReturnResponse.failure("删除文件失败,密码错误!");
} }

View File

@ -40,8 +40,8 @@ public class AttributeSetFilter implements Filter {
request.setAttribute("fileKey", httpRequest.getParameter("fileKey")); request.setAttribute("fileKey", httpRequest.getParameter("fileKey"));
request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled()); request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable()); request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable());
request.setAttribute("BeiAn", ConfigConstants.getBeiAn()); request.setAttribute("beiAn", ConfigConstants.getBeiAn());
request.setAttribute("size", ConfigConstants.maxsize()); request.setAttribute("size", ConfigConstants.maxSize());
} }
/** /**

View File

@ -56,7 +56,8 @@ public class TrustDirFilter implements Filter {
} }
private boolean allowPreview(String urlPath) { private boolean allowPreview(String urlPath) {
if(!StringUtils.hasText(urlPath) || !WebUtils.hefaurl(urlPath)){ //判断URL是否合法 //判断URL是否合法
if(!StringUtils.hasText(urlPath) || !WebUtils.isValidUrl(urlPath)) {
return false ; return false ;
} }
try { try {

View File

@ -156,7 +156,7 @@
</div> </div>
<div style="display: grid; place-items: center;"> <div style="display: grid; place-items: center;">
<div> <div>
<a target="_blank" href="https://beian.miit.gov.cn/" >${BeiAn}</a> <a target="_blank" href="https://beian.miit.gov.cn/">${beiAn}</a>
</div> </div>
</div> </div>
<script> <script>