|
@@ -206,77 +206,82 @@ app.post('/submit', SubmitWrapper)
|
|
async function SubmitWrapper(req, res) {
|
|
async function SubmitWrapper(req, res) {
|
|
// TODO
|
|
// TODO
|
|
// May extract logic for dupe check in the future.
|
|
// May extract logic for dupe check in the future.
|
|
-
|
|
|
|
- db.execute(("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name = ? and artist = ? and kind = ?"), [await converters2t.convertPromise(req.body.name), await converters2t.convertPromise(req.body.artist), req.body.kind], async (err, rowsT) => {
|
|
|
|
- db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name = ? and artist = ? and kind = ?", [await convertert2s.convertPromise(req.body.name), await convertert2s.convertPromise(req.body.artist), req.body.kind], (err, rowsS) => {
|
|
|
|
- let dedupe = [];
|
|
|
|
- rowsT.forEach(row => {
|
|
|
|
- dedupe = dedupe.concat(row);
|
|
|
|
- })
|
|
|
|
- rowsS.forEach(row => {
|
|
|
|
- if (JSON.stringify(dedupe).indexOf(JSON.stringify(row)) === -1) {
|
|
|
|
|
|
+ if(req.body.name !== undefined && req.body.name !== "" && req.body.name !== null){
|
|
|
|
+ db.execute(("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name = ? and artist = ? and kind = ?"), [await converters2t.convertPromise(req.body.name), await converters2t.convertPromise(req.body.artist), req.body.kind], async (err, rowsT) => {
|
|
|
|
+ db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name = ? and artist = ? and kind = ?", [await convertert2s.convertPromise(req.body.name), await convertert2s.convertPromise(req.body.artist), req.body.kind], (err, rowsS) => {
|
|
|
|
+ let dedupe = [];
|
|
|
|
+ rowsT.forEach(row => {
|
|
dedupe = dedupe.concat(row);
|
|
dedupe = dedupe.concat(row);
|
|
- }
|
|
|
|
- })
|
|
|
|
- if (dedupe.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) {
|
|
|
|
- if (req.body.name === item.name) {
|
|
|
|
- if (req.body.albumName === item.albumName) {
|
|
|
|
- if (req.body.kind === item.kind) {
|
|
|
|
|
|
+ })
|
|
|
|
+ rowsS.forEach(row => {
|
|
|
|
+ if (JSON.stringify(dedupe).indexOf(JSON.stringify(row)) === -1) {
|
|
|
|
+ dedupe = dedupe.concat(row);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ if (dedupe.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) {
|
|
|
|
+ if (req.body.name === item.name) {
|
|
|
|
+ if (req.body.albumName === item.albumName) {
|
|
|
|
+ if (req.body.kind === item.kind) {
|
|
|
|
|
|
- res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
- res.statusCode = 500
|
|
|
|
- res.end("傻逼,重复了。请在盲目上传之前看看库里有没有好么傻逼?")
|
|
|
|
- return
|
|
|
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
+ res.statusCode = 500
|
|
|
|
+ res.end("傻逼,重复了。请在盲目上传之前看看库里有没有好么傻逼?")
|
|
|
|
+ return
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- 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
|
|
|
|
|
|
+ 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) {
|
|
|
|
- req.body.link = ""
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ if (req.body.link === undefined) {
|
|
|
|
+ req.body.link = ""
|
|
|
|
+ }
|
|
|
|
|
|
- queue.add(() => {
|
|
|
|
- Submit(req)
|
|
|
|
- })
|
|
|
|
- currentTask.push({
|
|
|
|
- name: req.body.name,
|
|
|
|
- albumName: req.body.albumName,
|
|
|
|
- kind: req.body.kind,
|
|
|
|
- artist: req.body.artist,
|
|
|
|
- email: req.body.email !== undefined ? req.body.email : null,
|
|
|
|
- })
|
|
|
|
|
|
|
|
- console.log(queue.contents)
|
|
|
|
- console.log(currentTask)
|
|
|
|
- if (currentTask.length === 1) {
|
|
|
|
- queue.next()
|
|
|
|
|
|
+ queue.add(() => {
|
|
|
|
+ Submit(req)
|
|
|
|
+ })
|
|
|
|
+ currentTask.push({
|
|
|
|
+ name: req.body.name,
|
|
|
|
+ albumName: req.body.albumName,
|
|
|
|
+ kind: req.body.kind,
|
|
|
|
+ artist: req.body.artist,
|
|
|
|
+ email: req.body.email !== undefined ? req.body.email : null,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ console.log(queue.contents)
|
|
|
|
+ console.log(currentTask)
|
|
|
|
+ if (currentTask.length === 1) {
|
|
|
|
+ queue.next()
|
|
|
|
+ }
|
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
+ res.end("api_success")
|
|
|
|
+ } else {
|
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
+ res.statusCode = 500
|
|
|
|
+ res.end("傻逼,重复了。请在盲目上传之前看看库里有没有好么傻逼?")
|
|
}
|
|
}
|
|
- res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
- res.end("api_success")
|
|
|
|
- } else {
|
|
|
|
- res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
- res.statusCode = 500
|
|
|
|
- res.end("傻逼,重复了。请在盲目上传之前看看库里有没有好么傻逼?")
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ })
|
|
})
|
|
})
|
|
- })
|
|
|
|
|
|
+ }else{
|
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
+ res.end("api_success")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|