AXCWG пре 3 месеци
родитељ
комит
dec85c72aa
1 измењених фајлова са 42 додато и 5 уклоњено
  1. 42 5
      main.js

+ 42 - 5
main.js

@@ -52,6 +52,9 @@ let currentTask = [];
 function Submit(req, res) {
 
     let uuid = crypto.randomUUID()
+
+
+
     db.connect(function (err) {
         if (err) {
             console.log(err)
@@ -64,11 +67,20 @@ function Submit(req, res) {
         fetch(req.body.file).then(res => {
             res.arrayBuffer().then(r => fs.writeFileSync("./" + uuid, Buffer.from(r)));
         })
-        fetch(req.body.albumCover).then(res => {
-            res.arrayBuffer().then(r => {
-                albumCover = r
+        if(URL.canParse(req.body.albumCover)){
+            console.log("can parse ")
+            fetch(req.body.albumCover).then(res => {
+                res.arrayBuffer().then(async r => {
+                    if(!fs.existsSync("tmp")){
+                        fs.mkdirSync("tmp")
+                    }
+                    fs.writeFileSync("tmp/"+uuid, new Buffer.from(r));
+                    await webp.cwebp("tmp/"+uuid, "tmp/"+uuid+".webp", "-q 80", "-v")
+                    albumCover = fs.readFileSync("tmp/"+uuid+".webp")
+                })
             })
-        })
+        }
+
 
 
     } catch (err) {
@@ -142,6 +154,12 @@ function Submit(req, res) {
 
 
         })
+        try{
+            fs.rmSync("tmp/"+uuid)
+            fs.rmSync("tmp/"+uuid+".webp")
+        }catch(err){
+
+        }
         if (req.body.email !== undefined) {
             console.log(req.body.email)
             transporter.sendMail({
@@ -181,7 +199,6 @@ function SubmitWrapper(req, res) {
                   and kind = ${req.body.kind} `, (err, result) => {
 
         if (result.length === 0) {
-            let repeat = false;
             for (const item of currentTask) {
                 if (req.body.name === item.name) {
                     if (req.body.albumName === item.albumName) {
@@ -301,6 +318,7 @@ app.options('/search_api', function (req, res) {
     res.end()
 })
 app.get("/getSingle", function (req, res) {
+    let uuid = crypto.randomUUID()
 
     if (req.query.id) {
         db.execute(`SELECT song_name, album_name, artist, kind, albumcover
@@ -312,7 +330,26 @@ app.get("/getSingle", function (req, res) {
             res.contentType("application/json");
             res.header("Access-Control-Allow-Origin", "*");
             res.header("Access-Control-Allow-Headers", "Content-Type");
+            if(rows[0]!==undefined){
+                if(rows[0].albumcover !== null) {
+                    if(!fs.existsSync("tmp")){
+                        fs.mkdirSync("tmp")
+                    }
+                    fs.writeFileSync("tmp/"+uuid, rows[0].albumcover);
+                    await webp.cwebp("tmp/"+uuid, "tmp/"+uuid+".webp", "-q 80", "-v")
+                    rows[0].albumcover = fs.readFileSync("tmp/"+uuid+".webp")
+
+                }
+            }
+
             res.end(JSON.stringify(rows[0]));
+            try{
+                fs.rmSync("tmp/"+uuid)
+                fs.rmSync("tmp/"+uuid+".webp")
+            }catch(err){
+
+            }
+
         })
 
     } else {