This commit is contained in:
zlzw 2024-05-14 13:35:20 +08:00
parent 2183444676
commit 1b61722446
9 changed files with 106 additions and 68 deletions

View File

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

View File

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

View File

@ -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) {

View File

@ -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> T load(String type, String key, Class<T> t) {
return load(type, key, t, null);
}
public static <T> T load(String type, String key, Class<T> 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;
}
JSONObject json=JSONObject.parseObject(src);
json.put(key,data);
saveFile(file,json.toJSONString());
break;
}
}
return str;
} catch (Exception e) {
e.printStackTrace();
}
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;
}
}

View File

@ -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); // 预检间隔时间
}
}

View File

@ -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(" ", "");
@ -474,15 +474,16 @@ public class Tools {
calendar.setTime(new Date());
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;
}

View File

@ -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

View File

@ -11,7 +11,7 @@
©2022 by yutou
</div>
<div>
<a href="http://beian.miit.gov.cn/">湘ICP备16005656号1</a>
<a href="https://beian.miit.gov.cn/">湘ICP备16005656号1</a>
<!--<script type="text/javascript" src="https://s4.cnzz.com/z_stat.php?id=1279421741&web_id=1279421741"></script>-->
</div>

View File

@ -12,7 +12,7 @@
<body>
<div class="layui-header">
<ul class="layui-nav" lay-filter="" style="background-color: #1772B4;">
<li class="layui-nav-item"><a href="http://blog.yutou233.cn">博客</a></li>
<li class="layui-nav-item"><a href="https://blog.yutou233.cn">博客</a></li>
<div id="admin" style="display: inline-block; font-size: 0px;">
<li class="layui-nav-item">
<a href="javascript:;">NAS管理</a>
@ -36,9 +36,9 @@
<li class="layui-nav-item">
<a href="javascript:;">页面集</a>
<dl class="layui-nav-child">
<dd><a href="http://nas.yutou233.cn/" target="_blank">管理后台</a></dd>
<dd><a href="http://bt.yutou233.cn" target="_blank">BT下载</a></dd>
<dd><a href="http://jellyfin.yutou233.cn:7800/" target="_blank">jellyfin</a></dd>
<dd><a href="https://nas.yutou233.cn/" target="_blank">管理后台</a></dd>
<dd><a href="https://bt.yutou233.cn" target="_blank">BT下载</a></dd>
<dd><a href="https://jellyfin.yutou233.cn:7800/" target="_blank">jellyfin</a></dd>
<dd><a href="/html/body/nas/music.html">NAS音乐播放器</a></dd>
<dd><a href="/html/body/tools/calendar.html">日历</a></dd>
</dl>