From da6a83e1c018160ae0679c123a4ac5bfb2cbc87b Mon Sep 17 00:00:00 2001 From: amuliang <982632988@qq.com> Date: Thu, 3 Aug 2023 22:59:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8C=E5=90=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.js | 10 +++++++++- app/model/StoreModel.js | 7 ++++++- html/index.html | 43 +++++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/app/main.js b/app/main.js index 8dbb596..f53a3ca 100644 --- a/app/main.js +++ b/app/main.js @@ -2,7 +2,7 @@ const http = require("http"); const url = require("url"); const { ServerModel } = require('./model/ServerModel'); const { SearchModel } = require('./model/SearchModel'); -const { storeMusic, storeLrc, storePic } = require('./model/StoreModel'); +const { storeMusic, storeLrc, storePic, checkMusicExists } = require('./model/StoreModel'); const { SuccessResult, ErrorResult } = require('./model/ResultModel'); const { QQSource } = require('./source/QQSource'); @@ -34,6 +34,7 @@ searcher.registerSourceModel(new mfm.MyFreemp31tingSource()); // *********************************************************************** // 添加API接口 const _server = new ServerModel(); + _server.get("/api/source/all", (req, res, query) => { // 罗列都有哪些源 return new SuccessResult(searcher.getSourceList()); @@ -45,6 +46,11 @@ _server.get("/api/search", async (req, res, query) => { return new SuccessResult(result); }); +_server.get("/api/store/check", async (req, res, query) => { + let is_exists = checkMusicExists(query.music_path); + return new SuccessResult(is_exists); +}); + _server.get("/api/store", async (req, res, query) => { //存储文件 let music_path = query.music_path; @@ -80,6 +86,7 @@ const server = http.createServer(async (req, res) => { let reqUrl = req.url; let reqApi = reqUrl.split('?')[0]; console.log(method, reqUrl); + let result; try { if(method == "GET") { @@ -94,6 +101,7 @@ const server = http.createServer(async (req, res) => { console.error(err); result = new ErrorResult(err); } + res.setHeader('Access-Control-Allow-Origin', '*'); //res.setHeader('Access-Control-Allow-Methods', '*'); res.setHeader('Access-Control-Allow-Headers', '*'); diff --git a/app/model/StoreModel.js b/app/model/StoreModel.js index 42a9f47..2612ad2 100644 --- a/app/model/StoreModel.js +++ b/app/model/StoreModel.js @@ -41,8 +41,13 @@ async function storePic(path, url) { return await storeResource(path, url); } +function checkMusicExists(path) { + return fs.existsSync(path); +} + module.exports = { storeMusic, storeLrc, - storePic + storePic, + checkMusicExists } \ No newline at end of file diff --git a/html/index.html b/html/index.html index 91f0613..cf67e54 100644 --- a/html/index.html +++ b/html/index.html @@ -35,7 +35,7 @@
{{ renderedStorePath }}
-{{ store_message }}
-{{ current_item.lrc }}+