From 322e00404c2b782fbbaead1195ba6bcffd28f714 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Wed, 2 Mar 2022 11:39:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89ss?= =?UTF-8?q?r=E8=AE=A2=E9=98=85=E5=9C=B0=E5=9D=80=20=E4=BF=AE=E6=94=B9http?= =?UTF-8?q?=E2=86=92https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/tools/ToolsApplication.java | 3 +- .../java/com/yutou/tools/other/tools.java | 25 +- .../com/yutou/tools/web/userController.java | 4 +- web/html/body/nas/music.html | 6 +- web/html/body/tools/clash.html | 21 +- web/js/recordmp3.js | 219 ++++++++++++++++++ 6 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 web/js/recordmp3.js diff --git a/src/main/java/com/yutou/tools/ToolsApplication.java b/src/main/java/com/yutou/tools/ToolsApplication.java index aa197c8..900ba7e 100644 --- a/src/main/java/com/yutou/tools/ToolsApplication.java +++ b/src/main/java/com/yutou/tools/ToolsApplication.java @@ -1,11 +1,12 @@ package com.yutou.tools; +import com.yutou.tools.other.tools; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ToolsApplication { - public static final String version="1.4.4.1"; + public static final String version="1.4.4.4"; public static void main(String[] args) { System.out.println("当前版本号:" + version); diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index 4770685..0fe0aaa 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -152,8 +152,13 @@ public class tools { @RequestMapping(value="/tools/clash/get.do",produces ="text/plain;charset=utf-8") public String getClash(){ StringBuilder builder=new StringBuilder(); - String ssrUrl="https://s.sublink.me/subscribe/49191/IsXYcj95sGg/ssr/"; - String text= HttpTools.get("https://pub-api-1.bianyuan.xyz/sub?url="+ URLEncoder.encode(ssrUrl, StandardCharsets.UTF_8) +"&insert=false&config=https%3A%2F%2Fraw.githubusercontent.com%2FDarkatse%2FACL4SSR%2Fmaster%2FClash%2Fconfig%2FACL4SSR_Online.ini&target=clash"); + String ssrUrl=RedisTools.get("ssr"); + String url="http://127.0.0.1:25500/sub?target=clash&new_name=true&url="+URLEncoder.encode(ssrUrl, StandardCharsets.UTF_8) +"&insert=false&config=http%3A%2F%2Fgit.yutou233.cn%2Fyutou%2FACL4SSR%2Fsrc%2Fmaster%2FClash%2Fconfig%2FACL4SSR.ini"; + String text= HttpTools.get(url); + if(text==null){ + System.out.println("ssr is Null = " + url); + return ""; + } String[] tmp=text.split("\n"); text=RedisTools.get("clash"); builder.append("mixed-port: 7890").append("\n"); @@ -174,6 +179,22 @@ public class tools { return builder.toString(); } @ResponseBody + @RequestMapping("/tools/clash/ssr.do") + public JSONObject setClashSSR(String url){ + RedisTools.set("ssr",url); + JSONObject json=new JSONObject(); + json.put("msg","OK~"); + return json; + } + @ResponseBody + @RequestMapping("/tools/clash/getssr.do") + public JSONObject getClashSSR(){ + JSONObject json=new JSONObject(); + json.put("code",0); + json.put("data",RedisTools.get("ssr")); + return json; + } + @ResponseBody @RequestMapping("/tools/clash/list.do") public JSONObject clashList(){ String text=RedisTools.get("clash"); diff --git a/src/main/java/com/yutou/tools/web/userController.java b/src/main/java/com/yutou/tools/web/userController.java index 940ec42..37ee2e1 100644 --- a/src/main/java/com/yutou/tools/web/userController.java +++ b/src/main/java/com/yutou/tools/web/userController.java @@ -72,7 +72,7 @@ public class userController { RedisTools.set("login", cc, 5 * 60 * 1000); String token = UUID.randomUUID().toString().replace("-", ""); RedisTools.set(token, Tools.getRemoteAddress(request), 10 * 60 * 1000); - String url = "http://tools.yutou233.cn/login/ban.do?token=" + token; + String url = "https://tools.yutou233.cn/login/ban.do?token=" + token; Tools.sendServer("管理后台登录验证码", "本次登录验证码为:" + cc + ",登录IP:" + Tools.getRemoteAddress(request) + ",非正常登录,封禁IP:" + url);*/ @@ -108,7 +108,7 @@ public class userController { RedisTools.set("ban", array.toJSONString()); writer.write("已封禁"); } else { - String url = "http://tools.yutou233.cn/login/ban.do?token=" + token + "&model=yes"; + String url = "https://tools.yutou233.cn/login/ban.do?token=" + token + "&model=yes"; String html = "
click my is ban this IP :" + ip + "
"; writer.write(html); } diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index 12b6852..0b2c637 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -80,7 +80,7 @@ } localhost = json.data ; if (localhost === 'http://null:8000' || localhost === ":8000") { - localhost = "http://"+window.location.host; + localhost = "https://"+window.location.host; } } catch (e) { localhost = "" @@ -189,7 +189,7 @@ if(json.code===0){ layer.prompt({ title:"分享链接", - value:"http://"+window.location.host+"/html/body/nas/music.html?share="+json.data.token + value:"https://"+window.location.host+"/html/body/nas/music.html?share="+json.data.token },function (value,index,elem){ layer.close(index); }) @@ -258,7 +258,7 @@ if(json.code===0){ layer.prompt({ title:"分享链接", - value:"http://"+window.location.host+"/html/body/nas/music.html?share="+json.data.token + value:"https://"+window.location.host+"/html/body/nas/music.html?share="+json.data.token }) } }) diff --git a/web/html/body/tools/clash.html b/web/html/body/tools/clash.html index cb39c76..d124848 100644 --- a/web/html/body/tools/clash.html +++ b/web/html/body/tools/clash.html @@ -13,6 +13,12 @@
+
+ +
+ +
+
@@ -73,7 +79,7 @@ } else if(obj.event === 'showUrl'){ layer.prompt({ formType: 2, - value: 'http://'+window.location.host+'/tools/clash/get.do?token=X9C2h61pDI7KFa0kaHNITjlCY7bbIFN0', + value: 'https://'+window.location.host+'/tools/clash/get.do?token=X9C2h61pDI7KFa0kaHNITjlCY7bbIFN0', title: '请输入地址', }, function (path, index, elem) { $.post('/tools/clash/add.do', {'url': path}, function (json) { @@ -87,7 +93,18 @@ }) - + $('#ssr').keyup(function (event) { + if(event.keyCode===13){ + $.post("/tools/clash/ssr.do?url="+$('#ssr')[0].value,function (json) { + layer.msg(json.msg) + }) + } + }) + $.get("/tools/clash/getssr.do",function(json){ + if(json.code===0){ + $('#ssr')[0].value=json.data + } + }) }); $('#header').load("/html/header.html"); diff --git a/web/js/recordmp3.js b/web/js/recordmp3.js new file mode 100644 index 0000000..30bf989 --- /dev/null +++ b/web/js/recordmp3.js @@ -0,0 +1,219 @@ +(function(window){ + + var WORKER_PATH = '/js/recorderWorker.js'; + var encoderWorker = new Worker('/js/mp3Worker.js'); + + var Recorder = function(source, cfg){ + var config = cfg || {}; + var bufferLen = config.bufferLen || 4096; + var numChannels = config.numChannels || 2; + this.context = source.context; + this.node = (this.context.createScriptProcessor || + this.context.createJavaScriptNode).call(this.context, + bufferLen, numChannels, numChannels); + var worker = new Worker(config.workerPath || WORKER_PATH); + worker.postMessage({ + command: 'init', + config: { + sampleRate: this.context.sampleRate, + numChannels: numChannels + } + }); + var recording = false, + currCallback; + + this.node.onaudioprocess = function(e){ + if (!recording) return; + var buffer = []; + for (var channel = 0; channel < numChannels; channel++){ + buffer.push(e.inputBuffer.getChannelData(channel)); + } + worker.postMessage({ + command: 'record', + buffer: buffer + }); + } + + this.configure = function(cfg){ + for (var prop in cfg){ + if (cfg.hasOwnProperty(prop)){ + config[prop] = cfg[prop]; + } + } + } + + this.record = function(){ + recording = true; + } + + this.stop = function(){ + recording = false; + } + + this.clear = function(){ + worker.postMessage({ command: 'clear' }); + } + + this.getBuffer = function(cb) { + currCallback = cb || config.callback; + worker.postMessage({ command: 'getBuffer' }) + } + + this.exportWAV = function(cb, type){ + currCallback = cb || config.callback; + type = type || config.type || 'audio/wav'; + if (!currCallback) throw new Error('Callback not set'); + worker.postMessage({ + command: 'exportWAV', + type: type + }); + } + + //Mp3 conversion + worker.onmessage = function(e){ + var blob = e.data; + //console.log("the blob " + blob + " " + blob.size + " " + blob.type); + + var arrayBuffer; + var fileReader = new FileReader(); + + fileReader.onload = function(){ + arrayBuffer = this.result; + var buffer = new Uint8Array(arrayBuffer), + data = parseWav(buffer); + + console.log(data); + console.log("Converting to Mp3"); + //log.innerHTML += "\n" + "Converting to Mp3"; + + encoderWorker.postMessage({ cmd: 'init', config:{ + mode : 3, + channels:1, + samplerate: data.sampleRate, + bitrate: data.bitsPerSample + }}); + + encoderWorker.postMessage({ cmd: 'encode', buf: Uint8ArrayToFloat32Array(data.samples) }); + encoderWorker.postMessage({ cmd: 'finish'}); + encoderWorker.onmessage = function(e) { + if (e.data.cmd == 'data') { + + console.log("Done converting to Mp3"); + //log.innerHTML += "\n" + "Done converting to Mp3"; + + /*var audio = new Audio(); + audio.src = 'data:audio/mp3;base64,'+encode64(e.data.buf); + audio.play();*/ + + //console.log ("The Mp3 data " + e.data.buf); + + var mp3Blob = new Blob([new Uint8Array(e.data.buf)], {type: 'audio/mp3'}); + uploadAudio(mp3Blob); + + var url = 'data:audio/mp3;base64,'+encode64(e.data.buf); + var li = document.createElement('li'); + var au = document.createElement('audio'); + var hf = document.createElement('a'); + + au.controls = true; + au.src = url; + hf.href = url; + hf.download = 'audio_recording_' + new Date().getTime() + '.mp3'; + hf.innerHTML = hf.download; + li.appendChild(au); + li.appendChild(hf); + recordingslist.appendChild(li); + + } + }; + }; + + fileReader.readAsArrayBuffer(blob); + + currCallback(blob); + } + + + function encode64(buffer) { + var binary = '', + bytes = new Uint8Array( buffer ), + len = bytes.byteLength; + + for (var i = 0; i < len; i++) { + binary += String.fromCharCode( bytes[ i ] ); + } + return window.btoa( binary ); + } + + function parseWav(wav) { + function readInt(i, bytes) { + var ret = 0, + shft = 0; + + while (bytes) { + ret += wav[i] << shft; + shft += 8; + i++; + bytes--; + } + return ret; + } + if (readInt(20, 2) != 1) throw 'Invalid compression code, not PCM'; + if (readInt(22, 2) != 1) throw 'Invalid number of channels, not 1'; + return { + sampleRate: readInt(24, 4), + bitsPerSample: readInt(34, 2), + samples: wav.subarray(44) + }; + } + + function Uint8ArrayToFloat32Array(u8a){ + var f32Buffer = new Float32Array(u8a.length); + for (var i = 0; i < u8a.length; i++) { + var value = u8a[i<<1] + (u8a[(i<<1)+1]<<8); + if (value >= 0x8000) value |= ~0x7FFF; + f32Buffer[i] = value / 0x8000; + } + return f32Buffer; + } + + function uploadAudio(mp3Data){ + var reader = new FileReader(); + reader.onload = function(event){ + var fd = new FormData(); + var mp3Name = encodeURIComponent('audio_recording_' + new Date().getTime() + '.mp3'); + console.log("mp3name = " + mp3Name); + fd.append('fname', mp3Name); + fd.append('data', event.target.result); + $.ajax({ + type: 'POST', + url: 'upload.php', + data: fd, + processData: false, + contentType: false + }).done(function(data) { + //console.log(data); + log.innerHTML += "\n" + data; + }); + }; + reader.readAsDataURL(mp3Data); + } + + source.connect(this.node); + this.node.connect(this.context.destination); //this should not be necessary + }; + + /*Recorder.forceDownload = function(blob, filename){ + console.log("Force download"); + var url = (window.URL || window.webkitURL).createObjectURL(blob); + var link = window.document.createElement('a'); + link.href = url; + link.download = filename || 'output.wav'; + var click = document.createEvent("Event"); + click.initEvent("click", true, true); + link.dispatchEvent(click); + }*/ + + window.Recorder = Recorder; + + })(window); \ No newline at end of file