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 }}+