|
@@ -63,9 +63,12 @@ function Submit(req, res) {
|
|
|
|
|
|
let albumCover = null;
|
|
let albumCover = null;
|
|
try {
|
|
try {
|
|
|
|
+
|
|
fetch(req.body.file).then(res => {
|
|
fetch(req.body.file).then(res => {
|
|
res.arrayBuffer().then(r => fs.writeFileSync("./" + uuid, Buffer.from(r)));
|
|
res.arrayBuffer().then(r => fs.writeFileSync("./" + uuid, Buffer.from(r)));
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+
|
|
if (URL.canParse(req.body.albumCover)) {
|
|
if (URL.canParse(req.body.albumCover)) {
|
|
console.log("can parse ")
|
|
console.log("can parse ")
|
|
fetch(req.body.albumCover).then(res => {
|
|
fetch(req.body.albumCover).then(res => {
|
|
@@ -196,9 +199,14 @@ function SubmitWrapper(req, res) {
|
|
from instrunet_entry
|
|
from instrunet_entry
|
|
where song_name = "${req.body.name}"
|
|
where song_name = "${req.body.name}"
|
|
and artist = "${req.body.artist}"
|
|
and artist = "${req.body.artist}"
|
|
- and kind = ${req.body.kind} `, (err, result) => {
|
|
|
|
|
|
+ and kind = ${req.body.kind} `, async (err, result) => {
|
|
|
|
|
|
if (result.length === 0) {
|
|
if (result.length === 0) {
|
|
|
|
+ // Verify
|
|
|
|
+ if(req.body.file.substring(0,5) !=="data:"){
|
|
|
|
+ res.status(500).header("Access-Control-Allow-Origin", "*").end("想都别想");
|
|
|
|
+ return
|
|
|
|
+ }
|
|
for (const item of currentTask) {
|
|
for (const item of currentTask) {
|
|
if (req.body.name === item.name) {
|
|
if (req.body.name === item.name) {
|
|
if (req.body.albumName === item.albumName) {
|
|
if (req.body.albumName === item.albumName) {
|
|
@@ -213,27 +221,28 @@ function SubmitWrapper(req, res) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (req.body.name === undefined) {
|
|
|
|
- req.body.name = "未知名称"
|
|
|
|
- }
|
|
|
|
- if (req.body.albumName === undefined) {
|
|
|
|
- req.body.albumName = "未知专辑"
|
|
|
|
|
|
+ for (let prop of [req.body.name, req.body.albumName, req.body.artist]) {
|
|
|
|
+ if (prop === undefined || prop === "" || prop === null) {
|
|
|
|
+ res.status(500).header("Access-Control-Allow-Origin", "*").end("想都别想");
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
if (req.body.link === undefined) {
|
|
if (req.body.link === undefined) {
|
|
req.body.link = ""
|
|
req.body.link = ""
|
|
}
|
|
}
|
|
- if (req.body.artist === undefined) {
|
|
|
|
- req.body.artist = "未知艺术家"
|
|
|
|
- }
|
|
|
|
- if (req.body.file !== undefined) {
|
|
|
|
- queue.add(() => {
|
|
|
|
- Submit(req, res)
|
|
|
|
- })
|
|
|
|
- currentTask.push({
|
|
|
|
- name: req.body.name, albumName: req.body.albumName, kind: req.body.kind, artist: req.body.artist,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ queue.add(() => {
|
|
|
|
+ Submit(req, res)
|
|
|
|
+ })
|
|
|
|
+ currentTask.push({
|
|
|
|
+ name: req.body.name, albumName: req.body.albumName, kind: req.body.kind, artist: req.body.artist,
|
|
|
|
+ })
|
|
|
|
+
|
|
console.log(queue.contents)
|
|
console.log(queue.contents)
|
|
console.log(currentTask)
|
|
console.log(currentTask)
|
|
if (currentTask.length === 1) {
|
|
if (currentTask.length === 1) {
|
|
@@ -379,8 +388,8 @@ app.options('/ncm/url', function (req, res) {
|
|
res.end()
|
|
res.end()
|
|
})
|
|
})
|
|
app.post("/ncm/url", function (req, res) {
|
|
app.post("/ncm/url", function (req, res) {
|
|
- if(isNaN(Number.parseInt(req.query.id))){
|
|
|
|
- res.status(500).header("Access-Control-Allow-Origin", "*").end("傻逼");
|
|
|
|
|
|
+ if (Number.isNaN(Number(req.body.id))) {
|
|
|
|
+ res.status(500).header("Access-Control-Allow-Origin", "*").end("格式错误");
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -394,21 +403,24 @@ app.post("/ncm/url", function (req, res) {
|
|
}).then(async result => {
|
|
}).then(async result => {
|
|
if (result.status === 200 || result.status === 304) {
|
|
if (result.status === 200 || result.status === 304) {
|
|
let result_json = await result.json()
|
|
let result_json = await result.json()
|
|
- let infos = await (await fetch(ncmAPIUrl + "/song/detail?ids=" + id)).json();
|
|
|
|
- req.body.file = "data:audio/flac;base64," + Buffer.from(await (await fetch(result_json.data.url)).arrayBuffer()).toString("base64")
|
|
|
|
- req.body.name = infos.songs[0].name;
|
|
|
|
- req.body.albumName = infos.songs[0].al.name
|
|
|
|
- req.body.albumCover = infos.songs[0].al.picUrl
|
|
|
|
- req.body.link = result_json.data.url
|
|
|
|
- req.body.artist = infos.songs[0].ar[0].name
|
|
|
|
- /// Complete
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- SubmitWrapper(req, res)
|
|
|
|
|
|
+ if (result_json.data.url !== null) {
|
|
|
|
+ let infos = await (await fetch(ncmAPIUrl + "/song/detail?ids=" + id)).json();
|
|
|
|
+ req.body.file = "data:audio/flac;base64," + Buffer.from(await (await fetch(result_json.data.url)).arrayBuffer()).toString("base64")
|
|
|
|
+ req.body.name = infos.songs[0].name;
|
|
|
|
+ req.body.albumName = infos.songs[0].al.name
|
|
|
|
+ req.body.albumCover = infos.songs[0].al.picUrl
|
|
|
|
+ req.body.link = result_json.data.url
|
|
|
|
+ req.body.artist = infos.songs[0].ar[0].name
|
|
|
|
+ /// Complete
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ SubmitWrapper(req, res)
|
|
|
|
+ } else {
|
|
|
|
+ res.status(500).header("Access-Control-Allow-Origin", "*").end("不存在");
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
res.status(404).header("Access-Control-Allow-Origin", "*").send("未找到或出现错误")
|
|
res.status(404).header("Access-Control-Allow-Origin", "*").send("未找到或出现错误")
|
|
}
|
|
}
|
|
|
|
|