Răsfoiți Sursa

s-t check for upload. Stupid I am.

AXCWG 3 luni în urmă
părinte
comite
fec5b5e8b5
1 a modificat fișierele cu 68 adăugiri și 50 ștergeri
  1. 68 50
      main.js

+ 68 - 50
main.js

@@ -52,7 +52,7 @@ const transporter = nodemailer.createTransport({
     }
 })
 
-/// TODO
+
 let ncmAPIUrl = "http://localhost:5999";
 
 
@@ -202,71 +202,87 @@ app.get('/queue', (req, res) => {
 
 app.post('/submit', SubmitWrapper)
 
-function SubmitWrapper(req, res) {
-
-    db.execute(`SELECT uuid, song_name, album_name, link_to, artist, kind
-                from instrunet_entry
-                where song_name = "${req.body.name}"
-                  and artist = "${req.body.artist}"
-                  and kind = ${req.body.kind} `, async (err, result) => {
-
-        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) {
-                if (req.body.name === item.name) {
-                    if (req.body.albumName === item.albumName) {
-                        if (req.body.kind === item.kind) {
+async function SubmitWrapper(req, res) {
+    // TODO
+    //  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 = '${await converters2t.convertPromise(req.body.name)}'
+                  and artist = '${await converters2t.convertPromise(req.body.artist)}'
+                  and kind = ${req.body.kind}`, async (err, rowsT) => {
+        db.execute(`SELECT uuid, song_name, album_name, artist, kind
+                    FROM instrunet_entry
+                    WHERE song_name = '${await convertert2s.convertPromise(req.body.name)}'
+                      and artist = '${await convertert2s.convertPromise(req.body.artist)}'
+                      and kind = ${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) {
+                    dedupe = dedupe.concat(row);
+                }
+            })
+            console.log(dedupe);
+            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, 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(currentTask)
-            if (currentTask.length === 1) {
-                queue.next()
+                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("傻逼,重复了。请在盲目上传之前看看库里有没有好么傻逼?")
-        }
-
 
+        })
     })
 
 
+
 }
 
 app.post('/lyric', async (req, res) => {
@@ -303,6 +319,8 @@ app.options('/submit', function (req, res) {
     res.header("Access-Control-Allow-Headers", "Content-Type");
     res.end()
 })
+
+
 app.post('/search_api', async function (req, res) {