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,12 +1,12 @@
package com.mesasoft.cn.service.impl;
import com.mesasoft.cn.dao.AuthDAO;
import com.mesasoft.cn.util.BeanUtils;
import com.mesasoft.cn.config.SettingConfig;
import com.mesasoft.cn.dao.AuthDAO;
import com.mesasoft.cn.entity.Auth;
import com.mesasoft.cn.model.AuthRecord;
import com.mesasoft.cn.modules.constant.ConfigConsts;
import com.mesasoft.cn.service.IAuthService;
import com.mesasoft.cn.util.BeanUtils;
import com.mesasoft.cn.util.ServiceUtils;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.Checker;

View File

@@ -1,7 +1,7 @@
package com.mesasoft.cn.service.impl;
import com.mesasoft.cn.modules.constant.DefaultValues;
import com.mesasoft.cn.config.SettingConfig;
import com.mesasoft.cn.modules.constant.DefaultValues;
import com.mesasoft.cn.service.ICommonService;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.Checker;

View File

@@ -1,7 +1,7 @@
package com.mesasoft.cn.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.mesasoft.cn.SketchApplication;
import com.mesasoft.cn.WebSketchApplication;
import com.mesasoft.cn.modules.constant.ConfigConsts;
import com.mesasoft.cn.service.IConfigService;
import org.springframework.stereotype.Service;
@@ -15,7 +15,7 @@ public class ConfigServiceImpl implements IConfigService {
@Override
public String getGlobalConfig() {
JSONObject jsonObject = (JSONObject) SketchApplication.settings.getObjectUseEval(ConfigConsts
JSONObject jsonObject = (JSONObject) WebSketchApplication.settings.getObjectUseEval(ConfigConsts
.GLOBAL_OF_SETTINGS).clone();
jsonObject.remove(ConfigConsts.UPLOAD_PATH_OF_GLOBAL);
jsonObject.remove(ConfigConsts.TOKEN_PATH_OF_GLOBAL);
@@ -25,7 +25,7 @@ public class ConfigServiceImpl implements IConfigService {
@Override
public String getUserConfig() {
JSONObject jsonObject = (JSONObject) SketchApplication.settings.getObjectUseEval(ConfigConsts.USER_OF_SETTINGS)
JSONObject jsonObject = (JSONObject) WebSketchApplication.settings.getObjectUseEval(ConfigConsts.USER_OF_SETTINGS)
.clone();
jsonObject.remove(ConfigConsts.EMAIL_CONFIG_OF_USER);
return jsonObject.toString();

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);

View File

@@ -1,13 +1,13 @@
package com.mesasoft.cn.service.impl;
import com.mesasoft.cn.SketchApplication;
import com.mesasoft.cn.dao.UserDAO;
import com.mesasoft.cn.util.BeanUtils;
import com.mesasoft.cn.WebSketchApplication;
import com.mesasoft.cn.config.SettingConfig;
import com.mesasoft.cn.config.TokenConfig;
import com.mesasoft.cn.dao.UserDAO;
import com.mesasoft.cn.entity.User;
import com.mesasoft.cn.modules.constant.ConfigConsts;
import com.mesasoft.cn.service.IUserService;
import com.mesasoft.cn.util.BeanUtils;
import com.zhazhapan.modules.constant.ValueConsts;
import com.zhazhapan.util.Checker;
import com.zhazhapan.util.DateUtils;
@@ -67,11 +67,11 @@ public class UserServiceImpl implements IUserService {
@Override
public User login(String loginName, String password, String token, HttpServletResponse response) {
boolean allowLogin = SketchApplication.settings.getBooleanUseEval(ConfigConsts.ALLOW_LOGIN_OF_SETTINGS);
boolean allowLogin = WebSketchApplication.settings.getBooleanUseEval(ConfigConsts.ALLOW_LOGIN_OF_SETTINGS);
User user = null;
if (allowLogin) {
if (Checker.isNotEmpty(token) && SketchApplication.tokens.containsKey(token)) {
user = userDAO.getUserById(SketchApplication.tokens.get(token));
if (Checker.isNotEmpty(token) && WebSketchApplication.tokens.containsKey(token)) {
user = userDAO.getUserById(WebSketchApplication.tokens.get(token));
if (Checker.isNotNull(response)) {
Cookie cookie = new Cookie(ValueConsts.TOKEN_STRING, TokenConfig.generateToken(token, user.getId
()));
@@ -92,9 +92,9 @@ public class UserServiceImpl implements IUserService {
@Override
public boolean register(String username, String email, String password) {
boolean allowRegister = SketchApplication.settings.getBooleanUseEval(ConfigConsts.ALLOW_REGISTER_OF_SETTINGS);
boolean allowRegister = WebSketchApplication.settings.getBooleanUseEval(ConfigConsts.ALLOW_REGISTER_OF_SETTINGS);
if (allowRegister) {
boolean isValid = Checker.isEmail(email) && checkPassword(password) && Pattern.compile(SketchApplication.settings
boolean isValid = Checker.isEmail(email) && checkPassword(password) && Pattern.compile(WebSketchApplication.settings
.getStringUseEval(ConfigConsts.USERNAME_PATTERN_OF_SETTINGS)).matcher(username).matches();
if (isValid) {
User user = new User(username, ValueConsts.EMPTY_STRING, email, password);
@@ -113,8 +113,8 @@ public class UserServiceImpl implements IUserService {
@Override
public boolean checkPassword(String password) {
int min = SketchApplication.settings.getIntegerUseEval(ConfigConsts.PASSWORD_MIN_LENGTH_OF_SETTINGS);
int max = SketchApplication.settings.getIntegerUseEval(ConfigConsts.PASSWORD_MAX_LENGTH_OF_SETTINGS);
int min = WebSketchApplication.settings.getIntegerUseEval(ConfigConsts.PASSWORD_MIN_LENGTH_OF_SETTINGS);
int max = WebSketchApplication.settings.getIntegerUseEval(ConfigConsts.PASSWORD_MAX_LENGTH_OF_SETTINGS);
return Checker.isLimited(password, min, max);
}