移除了不需要的类,添加了简单的日志记录

This commit is contained in:
zayac 2023-09-09 21:21:46 +08:00
parent f7d68b1dab
commit 5846f5f22f
5 changed files with 31 additions and 22 deletions

View File

@ -9,9 +9,9 @@
<relativePath/> <relativePath/>
</parent> </parent>
<groupId>com.zayac</groupId> <groupId>com.zayac</groupId>
<artifactId>changeURL</artifactId> <artifactId>changeUrl</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-2023.9.9</version>
<name>changeURL</name> <name>changeUrl</name>
<description>通过http请求修改指定模板内指定关键词的小工具</description> <description>通过http请求修改指定模板内指定关键词的小工具</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>

View File

@ -1,6 +1,7 @@
package com.zayac.changeurl.exception; package com.zayac.changeurl.exception;
import com.zayac.changeurl.response.Result; import com.zayac.changeurl.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@ -11,12 +12,14 @@ import static com.zayac.changeurl.enums.ErrorEnum.INTERNAL_SERVER_ERROR;
* @author zayac * @author zayac
* @since 2023-09-09 17:36 * @since 2023-09-09 17:36
*/ */
@Slf4j
@ControllerAdvice @ControllerAdvice
public class GlobalExceptionHandler{ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody @ResponseBody
public <T> Result<T> handleAllException(Exception e) { public <T> Result<T> handleAllException(Exception e) {
log.error(e.getMessage());
return Result.error(INTERNAL_SERVER_ERROR); return Result.error(INTERNAL_SERVER_ERROR);
} }

View File

@ -7,6 +7,8 @@ import com.zayac.changeurl.entity.HthMsgEntity;
import com.zayac.changeurl.entity.HthTemplateEntity; import com.zayac.changeurl.entity.HthTemplateEntity;
import com.zayac.changeurl.entity.KyMsgEntity; import com.zayac.changeurl.entity.KyMsgEntity;
import com.zayac.changeurl.entity.KyTemplateEntity; import com.zayac.changeurl.entity.KyTemplateEntity;
import com.zayac.changeurl.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -19,14 +21,15 @@ import java.util.List;
* @author zayac * @author zayac
* @since 2023-08-30 12:08 * @since 2023-08-30 12:08
*/ */
@Slf4j
@Service @Service
public class ChangeUrlServiceImpl implements ChangeUrlService { public class ChangeUrlServiceImpl implements ChangeUrlService {
private static final String KYJS = "ky.js"; private static final String KYJS = "/www/wwwroot/cdn.static.cdcseo.com/js/ky.js";
private static final String HTHJS = "hth.js"; private static final String HTHJS = "/www/wwwroot/cdn.static.cdcseo.com/js/hth.js";
@Override @Override
public Boolean change(String text) { public Boolean change(String text) {
log.info(text);
String[] arr = text.split("\n"); String[] arr = text.split("\n");
//传入text 包含SEO 专用域名 则为开云 //传入text 包含SEO 专用域名 则为开云
@ -43,7 +46,7 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
"kyPc2", "kyPc2",
"kyH51", "kyH51",
"kyH52", "kyH52",
"ky.js.template", "/www/wwwroot/cdn.static.cdcseo.com/template/ky.js.template",
kyTargets); kyTargets);
//读取模板文件 //读取模板文件
String template = loadTemplate(kyTemplate.getTemplatePath()); String template = loadTemplate(kyTemplate.getTemplatePath());
@ -58,13 +61,15 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
modifyFile(template, kyTemplate.getTargets()); modifyFile(template, kyTemplate.getTargets());
//读取修改过的文件 校验修改成功失败 //读取修改过的文件 校验修改成功失败
String result = FileUtil.readUtf8String(KYJS); String result = FileUtil.readUtf8String(KYJS);
//如果修改后的js文件中 if (ReUtil.count(Constant.URL_PATTERN, result) < 6) {
return ReUtil.count(Constant.URL_PATTERN, result) >= 6; throw new BizException(500, "开云链接更新失败,请手动检查文件");
}
log.info("开云js更新成功");
} else { } else {
HthMsgEntity hthMsg = new HthMsgEntity(arr); HthMsgEntity hthMsg = new HthMsgEntity(arr);
List<String> hthTargets = new ArrayList<>(); List<String> hthTargets = new ArrayList<>();
hthTargets.add(HTHJS); hthTargets.add(HTHJS);
HthTemplateEntity hthTemplate = new HthTemplateEntity("hthApp", "hthtyApp", "hthPc", "hthH5", "hth.js.template", hthTargets); HthTemplateEntity hthTemplate = new HthTemplateEntity("hthApp", "hthtyApp", "hthPc", "hthH5", "/www/wwwroot/cdn.static.cdcseo.com/template/ky.js.template/hth.js.template", hthTargets);
//读取模板文件 //读取模板文件
String template = loadTemplate(hthTemplate.getTemplatePath()); String template = loadTemplate(hthTemplate.getTemplatePath());
template = template template = template
@ -76,9 +81,12 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
//读取修改过的文件 校验修改成功失败 //读取修改过的文件 校验修改成功失败
String result = FileUtil.readUtf8String(files.get(0)); String result = FileUtil.readUtf8String(files.get(0));
//如果修改后的js文件中 //如果修改后的js文件中
return ReUtil.count(Constant.URL_PATTERN, result) >= 4; if (ReUtil.count(Constant.URL_PATTERN, result) < 4) {
throw new BizException(500, "华体会链接更新失败,请手动检查文件");
}
log.info("华体会js更新成功");
} }
return true;
} }
/** /**

View File

@ -1,8 +0,0 @@
package com.zayac.changeurl.util;
/**
* @author zayac
* @since 2023-08-30 13:12
*/
public class util {
}

View File

@ -6,4 +6,10 @@ spring:
caffeine: caffeine:
spec: maximumSize=100,expireAfterWrite=10m spec: maximumSize=100,expireAfterWrite=10m
profiles: profiles:
active: "ky" active: "ky"
logging:
logback:
rollingpolicy:
max-file-size: 10MB
max-history: 10