细节调整,主要是从配置文件读取文件路径

This commit is contained in:
zayac 2023-09-30 02:12:48 +08:00
parent cdcec317b9
commit a9f423e014
5 changed files with 38 additions and 44 deletions

View File

@ -9,6 +9,7 @@ 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 com.zayac.changeurl.exception.BizException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -24,8 +25,15 @@ import java.util.List;
@Slf4j @Slf4j
@Service @Service
public class ChangeUrlServiceImpl implements ChangeUrlService { public class ChangeUrlServiceImpl implements ChangeUrlService {
private static final String KYJS = "/www/wwwroot/cdn.static.cdcseo.com/js/ky.js"; @Value("${path.ky.target}")
private static final String HTHJS = "/www/wwwroot/cdn.static.cdcseo.com/js/hth.js"; private String kyjs;
@Value("${path.hth.target}")
private String hthjs;
@Value("${path.ky.template}")
private String kyjsTemplate;
@Value("${path.hth.template}")
private String hthjsTemplate;
@Override @Override
public Boolean change(String text) { public Boolean change(String text) {
@ -36,7 +44,7 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
if (text.contains("SEO 专用域名")) { if (text.contains("SEO 专用域名")) {
KyMsgEntity kyMsg = new KyMsgEntity(arr); KyMsgEntity kyMsg = new KyMsgEntity(arr);
List<String> kyTargets = new ArrayList<>(); List<String> kyTargets = new ArrayList<>();
kyTargets.add(KYJS); kyTargets.add(kyjs);
KyTemplateEntity kyTemplate = KyTemplateEntity kyTemplate =
new KyTemplateEntity( new KyTemplateEntity(
@ -46,7 +54,7 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
"kyPc2", "kyPc2",
"kyH51", "kyH51",
"kyH52", "kyH52",
"/www/wwwroot/cdn.static.cdcseo.com/js/ky.js.template", kyjsTemplate,
kyTargets); kyTargets);
//读取模板文件 //读取模板文件
String template = loadTemplate(kyTemplate.getTemplatePath()); String template = loadTemplate(kyTemplate.getTemplatePath());
@ -60,7 +68,7 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
modifyFile(template, kyTemplate.getTargets()); modifyFile(template, kyTemplate.getTargets());
//读取修改过的文件 校验修改成功失败 //读取修改过的文件 校验修改成功失败
String result = FileUtil.readUtf8String(KYJS); String result = FileUtil.readUtf8String(kyjs);
if (ReUtil.count(Constant.URL_PATTERN, result) < 6) { if (ReUtil.count(Constant.URL_PATTERN, result) < 6) {
throw new BizException(500, "开云链接更新失败,请手动检查文件"); throw new BizException(500, "开云链接更新失败,请手动检查文件");
} }
@ -68,8 +76,8 @@ public class ChangeUrlServiceImpl implements ChangeUrlService {
} 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", "/www/wwwroot/cdn.static.cdcseo.com/js/hth.js.template", hthTargets); HthTemplateEntity hthTemplate = new HthTemplateEntity("hthApp", "hthtyApp", "hthPc", "hthH5", hthjsTemplate, hthTargets);
//读取模板文件 //读取模板文件
String template = loadTemplate(hthTemplate.getTemplatePath()); String template = loadTemplate(hthTemplate.getTemplatePath());
template = template template = template

View File

@ -1,32 +1,10 @@
msg: path:
ky: ky:
startWith: template: "ky.js.template"
web: "WEB" target: "C:\\Users\\Administrator\\Desktop\\js\\ky.js"
h5: "H5"
app: "全站"
hth: hth:
startWith: template: "hth.js.template"
web: "" target: "C:\\Users\\Administrator\\Desktop\\js\\hth.js"
h5: ""
app1: ""
app2: ""
js:
ky:
kyweb1: "kyPc1"
kyweb2: "kyPc2"
kyh51: "kyH5"
kyh52: ""
kyApp1: "kyApp"
kyApp2: ""
hth:
hthweb: ""
hthh5: ""
hthApp1: ""
hthApp2: ""
path:
template: "link.js.template"
targets: "link.js"
server: server:
port: 8888 port: 8888
spring: spring:

View File

@ -1,9 +0,0 @@
server:
port: 8888
spring:
cache:
type: CAFFEINE
caffeine:
spec: maximumSize=100,expireAfterWrite=10m
ip:
white: "127.0.0.1"

View File

@ -0,0 +1,17 @@
server:
port: 8359
spring:
cache:
type: CAFFEINE
caffeine:
spec: maximumSize=100,expireAfterWrite=10m
ip:
white: "127.0.0.1"
path:
ky:
template: "/www/wwwroot/cdn.static.cdcseo.com/template/ky.js.template"
target: "/www/wwwroot/cdn.static.cdcseo.com/js/ky.js"
hth:
template: "/www/wwwroot/cdn.static.cdcseo.com/template/hth.js.template"
target: "/www/wwwroot/cdn.static.cdcseo.com/js/hth.js"

View File

@ -6,7 +6,7 @@ spring:
caffeine: caffeine:
spec: maximumSize=100,expireAfterWrite=10m spec: maximumSize=100,expireAfterWrite=10m
profiles: profiles:
active: "ky" active: "prod"
logging: logging:
logback: logback: