web sketch-查询代理功能优化 CN-663

This commit is contained in:
zhanghongqing
2023-01-10 15:51:02 +08:00
parent b3fa11d4b1
commit c125bb89cf
54 changed files with 515 additions and 2557 deletions

View File

@@ -1,10 +1,9 @@
package com.mesasoft.cn.service.impl;
import com.mesasoft.cn.SketchApplication;
import com.mesasoft.cn.WebSketchApplication;
import com.mesasoft.cn.config.SettingConfig;
import com.mesasoft.cn.dao.DownloadedDAO;
import com.mesasoft.cn.dao.FileDAO;
import com.mesasoft.cn.util.BeanUtils;
import com.mesasoft.cn.config.SettingConfig;
import com.mesasoft.cn.entity.Category;
import com.mesasoft.cn.entity.File;
import com.mesasoft.cn.entity.User;
@@ -17,6 +16,7 @@ import com.mesasoft.cn.modules.constant.DefaultValues;
import com.mesasoft.cn.service.IAuthService;
import com.mesasoft.cn.service.ICategoryService;
import com.mesasoft.cn.service.IFileService;
import com.mesasoft.cn.util.BeanUtils;
import com.mesasoft.cn.util.ServiceUtils;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.*;
@@ -134,7 +134,7 @@ public class FileServiceImpl implements IFileService {
AuthRecord authRecord = authService.getByFileIdAndUserId(id, user.getId());
String suffix = FileExecutor.getFileSuffix(name);
boolean canUpdate = (Checker.isNull(authRecord) ? user.getIsUpdatable() == 1 :
authRecord.getIsUpdatable() == 1) && Checker.isNotEmpty(name) && Pattern.compile(SketchApplication.settings.getStringUseEval(ConfigConsts.FILE_SUFFIX_MATCH_OF_SETTING)).matcher(suffix).matches();
authRecord.getIsUpdatable() == 1) && Checker.isNotEmpty(name) && Pattern.compile(WebSketchApplication.settings.getStringUseEval(ConfigConsts.FILE_SUFFIX_MATCH_OF_SETTING)).matcher(suffix).matches();
if (canUpdate) {
String localUrl = file.getLocalUrl();
java.io.File newFile = new java.io.File(localUrl);
@@ -208,7 +208,7 @@ public class FileServiceImpl implements IFileService {
@Override
public String getResource(String visitUrl, HttpServletRequest request) {
logger.info("visit url: " + visitUrl);
boolean downloadable = SketchApplication.settings.getBooleanUseEval(ConfigConsts
boolean downloadable = WebSketchApplication.settings.getBooleanUseEval(ConfigConsts
.ANONYMOUS_DOWNLOADABLE_OF_SETTING);
User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
File file = fileDAO.getFileByVisitUrl(visitUrl);
@@ -249,15 +249,15 @@ public class FileServiceImpl implements IFileService {
String suffix = FileExecutor.getFileSuffix(name);
String localUrl = SettingConfig.getUploadStoragePath() + ValueConsts.SEPARATOR + name;
Category category = categoryService.getById(categoryId);
long maxSize = Formatter.sizeToLong(SketchApplication.settings.getStringUseEval(ConfigConsts
long maxSize = Formatter.sizeToLong(WebSketchApplication.settings.getStringUseEval(ConfigConsts
.FILE_MAX_SIZE_OF_SETTING));
long size = multipartFile.getSize();
boolean fileExists = localUrlExists(localUrl);
//检测标签是否合法
if (SketchApplication.settings.getBooleanUseEval(ConfigConsts.TAG_REQUIRE_OF_SETTING)) {
if (WebSketchApplication.settings.getBooleanUseEval(ConfigConsts.TAG_REQUIRE_OF_SETTING)) {
String[] tags = Checker.checkNull(tag).split(ValueConsts.SPACE);
if (tags.length <= SketchApplication.settings.getIntegerUseEval(ConfigConsts.TAG_SIZE_OF_SETTING)) {
int maxLength = SketchApplication.settings.getIntegerUseEval(ConfigConsts.TAG_LENGTH_OF_SETTING);
if (tags.length <= WebSketchApplication.settings.getIntegerUseEval(ConfigConsts.TAG_SIZE_OF_SETTING)) {
int maxLength = WebSketchApplication.settings.getIntegerUseEval(ConfigConsts.TAG_LENGTH_OF_SETTING);
for (String t : tags) {
if (t.length() > maxLength) {
return false;
@@ -268,15 +268,15 @@ public class FileServiceImpl implements IFileService {
}
}
//是否可以上传
boolean canUpload = !multipartFile.isEmpty() && size <= maxSize && Pattern.compile(SketchApplication
boolean canUpload = !multipartFile.isEmpty() && size <= maxSize && Pattern.compile(WebSketchApplication
.settings.getStringUseEval(ConfigConsts.FILE_SUFFIX_MATCH_OF_SETTING)).matcher(suffix).matches()
&& (Checker.isNotExists(localUrl) || !fileExists || SketchApplication.settings.getBooleanUseEval
&& (Checker.isNotExists(localUrl) || !fileExists || WebSketchApplication.settings.getBooleanUseEval
(ConfigConsts.FILE_COVER_OF_SETTING));
logger.info("is empty [" + multipartFile.isEmpty() + "], file size [" + size + "], max file size [" +
maxSize + "]");
if (canUpload) {
String visitUrl = getRegularVisitUrl(Checker.isNotEmpty(prefix) && user.getPermission() > 1 ? prefix
: SketchApplication.settings.getStringUseEval(ConfigConsts.CUSTOM_LINK_RULE_OF_SETTING), user,
: WebSketchApplication.settings.getStringUseEval(ConfigConsts.CUSTOM_LINK_RULE_OF_SETTING), user,
name, suffix, category);
if (fileExists) {
removeByLocalUrl(localUrl);