diff --git a/src/main/java/com/yutou/tools/ToolsApplication.java b/src/main/java/com/yutou/tools/ToolsApplication.java index 4c3174a..aed4bd8 100644 --- a/src/main/java/com/yutou/tools/ToolsApplication.java +++ b/src/main/java/com/yutou/tools/ToolsApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ToolsApplication { - public static final String version="1.4.9"; + public static final String version="1.5.0"; public static void main(String[] args) { System.out.println("当前版本号:" + version); diff --git a/src/main/java/com/yutou/tools/nas/NasManager.java b/src/main/java/com/yutou/tools/nas/NasManager.java index da53799..d36d080 100644 --- a/src/main/java/com/yutou/tools/nas/NasManager.java +++ b/src/main/java/com/yutou/tools/nas/NasManager.java @@ -29,7 +29,7 @@ import java.util.UUID; @Controller public class NasManager { - public static String NasUrl="http://yutou233.cn"; + public static String NasUrl="https://nas.yutou233.cn"; static { if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) { NasUrl="http://192.168.31.88"; @@ -184,7 +184,7 @@ public class NasManager { json.put("data", NasUrl + ":8000"); } else { if (UpdateIp.nas_ip == null) { - json.put("data", "http://yutou233.cn:8001"); + json.put("data", "http://nas.yutou233.cn:8001"); } else { json.put("data", String.format("http://%s:8000", UpdateIp.nas_ip)); } @@ -282,7 +282,7 @@ public class NasManager { json.put("data", NasUrl + ":8000/nas/music/list.do?token="); } else { if (UpdateIp.nas_ip == null) { - json.put("data", "http://yutou233.cn:8001/nas/music/list.do?token="); + json.put("data", "http://nas.yutou233.cn:8001/nas/music/list.do?token="); } else { json.put("data", String.format("http://%s:8000/nas/music/list.do?token=", UpdateIp.nas_ip)); } diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index 609301a..928e789 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -6,6 +6,7 @@ import com.yutou.tools.ToolsApplication; import com.yutou.tools.mybatis.dao.UKeyDao; import com.yutou.tools.mybatis.model.UKey; import com.yutou.tools.mybatis.model.UKeyExample; +import com.yutou.tools.utils.ConfigTools; import com.yutou.tools.utils.HttpTools; import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.Tools; @@ -217,7 +218,11 @@ public class tools { } return builder.toString(); } - + @ResponseBody + @RequestMapping(value = "/tools/ssr/get.do", produces = "text/plain;charset=utf-8") + public String getSSRUrl(){ + return (String) ConfigTools.load(ConfigTools.DATA,"ssr"); + } @ResponseBody @RequestMapping("/tools/clash/ssr.do") public JSONObject setClashSSR(String url) { diff --git a/src/main/java/com/yutou/tools/utils/ConfigTools.java b/src/main/java/com/yutou/tools/utils/ConfigTools.java index 607cae8..11f2b06 100644 --- a/src/main/java/com/yutou/tools/utils/ConfigTools.java +++ b/src/main/java/com/yutou/tools/utils/ConfigTools.java @@ -1,6 +1,8 @@ package com.yutou.tools.utils; +import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; +import com.aliyuncs.utils.StringUtils; import java.io.*; @@ -8,57 +10,88 @@ import java.io.*; * 配置和参数 */ public class ConfigTools { - public static final String CONFIG="config.json"; - public static final String DATA="data.json"; - public static final String SQLITE="sqlite.json"; + public static final String CONFIG = "config.json"; + public static final String DATA = "data.json"; + public static final String SQLITE = "sqlite.json"; + + static { try { - File file=new File(CONFIG); - if(!file.exists()){ + File file = new File(CONFIG); + if (!file.exists()) { file.createNewFile(); } - file=new File(DATA); - if(!file.exists()){ + file = new File(DATA); + if (!file.exists()) { file.createNewFile(); } - file=null; - }catch (Exception e){ + file = null; + } catch (Exception e) { e.printStackTrace(); } } - public static Object load(String type,String key){ - File file=new File(type); - //System.out.println(type+"配置文件地址:"+file.getAbsolutePath()); - String src=readFile(file); - if(src!=null){ + + public static Object load(String type, String key) { + return load(type, key, Object.class, null); + } + + public static T load(String type, String key, Class t) { + return load(type, key, t, null); + } + + public static T load(String type, String key, Class t, T def) { + File file = new File(type); + //com.yutou.nas.utils.Log.i(type+"配置文件地址:"+file.getAbsolutePath()); + String src = readFile(file); + if (src != null) { try { - JSONObject json=JSONObject.parseObject(src); - if(json==null){ - json=new JSONObject(); - saveFile(file,json.toJSONString()); - } - return json.getOrDefault(key, ""); - }catch (Exception e){ - return ""; + JSONObject json = JSONObject.parseObject(src, JSONObject.class); + return json.getObject(key, t); + } catch (Exception e) { + e.printStackTrace(); } } - return ""; + + return def; } - public static boolean save(String type,String key,Object data){ - File file=new File(type); - String src=readFile(file); - if(src==null){ - src="{}"; + + public static String loadIni(File file, String key) { + try { + BufferedReader reader = new BufferedReader(new FileReader(file)); + String tmp, str = null; + while ((tmp = reader.readLine()) != null) { + if (tmp.startsWith(key + "=")) { + str = tmp.split("=")[1]; + if (StringUtils.isEmpty(str)) { + str = null; + } + break; + } + } + return str; + + } catch (Exception e) { + e.printStackTrace(); } - JSONObject json=JSONObject.parseObject(src); - json.put(key,data); - saveFile(file,json.toJSONString()); + return null; + } + + public static boolean save(String type, String key, Object data) { + File file = new File(type); + String src = readFile(file); + if (src == null) { + src = "{}"; + } + JSONObject json = JSON.parseObject(src); + json.put(key, data); + saveFile(file, json.toJSONString()); return false; } - public static boolean saveFile(File file,String data){ + + public static boolean saveFile(File file, String data) { try { - FileWriter writer=new FileWriter(file); + FileWriter writer = new FileWriter(file); writer.write(data); writer.flush(); writer.close(); @@ -68,13 +101,14 @@ public class ConfigTools { return false; } } - public static String readFile(File file){ + + public static String readFile(File file) { try { - BufferedReader reader=new BufferedReader(new FileReader(file)); + BufferedReader reader = new BufferedReader(new FileReader(file)); String tmp; - StringBuilder str= new StringBuilder(); - while ((tmp=reader.readLine())!=null){ - str.append(tmp); + StringBuilder str = new StringBuilder(); + while ((tmp = reader.readLine()) != null) { + str.append(tmp).append("\n"); } reader.close(); return str.toString(); @@ -84,3 +118,4 @@ public class ConfigTools { return null; } } + diff --git a/src/main/java/com/yutou/tools/utils/CorsConfig.java b/src/main/java/com/yutou/tools/utils/CorsConfig.java index 04f0e79..64bfb4e 100644 --- a/src/main/java/com/yutou/tools/utils/CorsConfig.java +++ b/src/main/java/com/yutou/tools/utils/CorsConfig.java @@ -10,13 +10,10 @@ public class CorsConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { //设置允许跨域的路径 registry.addMapping("/**") - //设置允许跨域请求的域名 - .allowedOrigins("Access-Control-Allow-Origin") - //是否允许证书 不再默认开启 - .allowCredentials(true) - //设置允许的方法 - .allowedMethods("*") - //跨域允许时间 - .maxAge(3600); + .allowedOrigins("https://tools.yutou233.cn") // 允许哪些域的请求 + .allowedMethods("POST", "GET") // 允许的请求方法 + .allowedHeaders("*") // 允许的头部设置 + .allowCredentials(true) // 是否发送cookie + .maxAge(168000); // 预检间隔时间 } } \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/utils/Tools.java b/src/main/java/com/yutou/tools/utils/Tools.java index 50ef393..6fda890 100644 --- a/src/main/java/com/yutou/tools/utils/Tools.java +++ b/src/main/java/com/yutou/tools/utils/Tools.java @@ -435,7 +435,7 @@ public class Tools { } public static String getLoginUser() { - if("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) { + if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) { return "admin"; } Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); @@ -459,7 +459,7 @@ public class Tools { } public static String getPinYin(String text) { - String pinyin = HttpTools.get("http://api.tianapi.com/pinyin/index?key=a1e0f7267037c4e0ea02fb1cb3912367&text=" + URLEncoder.encode(text, StandardCharsets.UTF_8)); + String pinyin = HttpTools.get("https://apis.tianapi.com/pinyin/index?key=" + ConfigTools.load(ConfigTools.CONFIG, "tianapi.key", String.class) + "&text=" + URLEncoder.encode(text, StandardCharsets.UTF_8)); JSONObject json = JSONObject.parseObject(pinyin); if (json.getInteger("code") == 200) { return json.getJSONArray("newslist").getJSONObject(0).getString("pinyin").trim().replace(" ", ""); @@ -472,17 +472,18 @@ public class Tools { calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(new Date()); - return calendar.get(Calendar.DAY_OF_WEEK) - 1; + return calendar.get(Calendar.DAY_OF_WEEK) - 1; } - public static Date timeToDate(String date,String time){ + + public static Date timeToDate(String date, String time) { String form; - if(StringUtils.isEmpty(time)){ - form="yyyy-MM-dd"; - }else{ - form="yyyy-MM-dd HH:mm:ss"; + if (StringUtils.isEmpty(time)) { + form = "yyyy-MM-dd"; + } else { + form = "yyyy-MM-dd HH:mm:ss"; } try { - return new SimpleDateFormat(form).parse(date+" "+time); + return new SimpleDateFormat(form).parse(date + " " + time); } catch (ParseException e) { return null; } diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index b089a6e..fef4fc3 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -101,7 +101,7 @@ return; } localhost = json.data; - if (localhost === 'http://null:8000' || localhost === ":8000") { + if (localhost === 'https://null:8000' || localhost === ":8000") { localhost = "https://" + window.location.host; } } catch (e) { @@ -210,7 +210,7 @@ } $.post('/nas/music/share.do', {file: file, isDir: isDir}, function (json) { if (json.code === 0) { - var url = "http://" + window.location.host + "/html/body/nas/music.html?share=" + json.data.token + var url = "https://" + window.location.host + "/html/body/nas/music.html?share=" + json.data.token layer.prompt({ title: "分享链接", value: url @@ -290,7 +290,7 @@ $('#play_share').click(function () { $.post('/nas/music/share.do', {file: playNow}, function (json) { if (json.code === 0) { - let url = "http://" + window.location.host + "/html/body/nas/music.html?share=" + json.data.token + let url = "https://" + window.location.host + "/html/body/nas/music.html?share=" + json.data.token layer.prompt({ title: "分享链接", value: url diff --git a/web/html/footer.html b/web/html/footer.html index 4d37336..71c8ee0 100644 --- a/web/html/footer.html +++ b/web/html/footer.html @@ -11,7 +11,7 @@ ©2022 by yutou
- 湘ICP备16005656号1 + 湘ICP备16005656号1
diff --git a/web/html/header.html b/web/html/header.html index f72ecd9..a7714c7 100644 --- a/web/html/header.html +++ b/web/html/header.html @@ -12,7 +12,7 @@