AXCWG 2 mesi fa
parent
commit
ea0a1f62a2
2 ha cambiato i file con 29 aggiunte e 15 eliminazioni
  1. 2 1
      .gitignore
  2. 27 14
      main.js

+ 2 - 1
.gitignore

@@ -7,4 +7,5 @@ output
 database.db
 .DS_Store
 .idea/.DS_Store
-*.mp3
+*.mp3
+log

+ 27 - 14
main.js

@@ -8,7 +8,23 @@ import 'cnchar'
 import 'sort-array'
 import nodemailer from 'nodemailer'
 import Queue from 'js-queue'
+import process from 'node:process'
 
+try {
+    fs.renameSync("log/latest.log", `log/${new Date().toISOString().replaceAll(":", ".")}.log`)
+} catch (e) {
+}
+
+let original = console.log;
+console.log = (str) => {
+    if (!fs.existsSync("log")) {
+        fs.mkdirSync("log")
+
+    }
+    fs.appendFileSync("log/latest.log",  "["+new Date().toISOString() + "] " + str.toString()+"\n");
+    original(str);
+
+}
 
 import webp from 'webp-converter'
 
@@ -238,10 +254,10 @@ async function Submit(req) {
             onData: callback, onError: errcb
         }).then(() => {
 
-            try{
+            try {
                 db.execute(("INSERT INTO instrunet_entry (uuid, song_name, album_name, link_to, databinary, artist,kind, albumcover, email) VALUES (?,?,?,?,?,?,?,?,?)"), [uuid, req.body.name, req.body.albumName, req.body.link, fs.readFileSync(kind_of[1]), req.body.artist, req.body.kind, albumCover === null ? new Buffer.from([]) : albumCover, (req.body.email === null || req.body.email === undefined || req.body.email === "") ? "" : req.body.email])
 
-            }catch(err) {
+            } catch (err) {
                 GC();
                 currentTask.shift();
                 console.log(queue.contents)
@@ -324,7 +340,7 @@ async function SubmitWrapper(req, res) {
                     }
                 })
                 rowsO.forEach(row => {
-                    if(JSON.stringify(dedupe).indexOf(JSON.stringify(row)) === -1) {
+                    if (JSON.stringify(dedupe).indexOf(JSON.stringify(row)) === -1) {
                         dedupe = dedupe.concat(row);
                     }
                 })
@@ -390,7 +406,6 @@ async function SubmitWrapper(req, res) {
     })
 
 
-
 }
 
 app.post('/lyric', async (req, res) => {
@@ -430,16 +445,16 @@ app.options('/submit', function (req, res) {
 
 app.post('/search_api', async function (req, res) {
 
-    db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name like ? or album_name like ? or artist like ?", [`%${req.body.searchStr}%`, `%${req.body.searchStr}%`, `%${req.body.searchStr}%`], async(err, rowsO)=>{
-        if(err){
+    db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name like ? or album_name like ? or artist like ?", [`%${req.body.searchStr}%`, `%${req.body.searchStr}%`, `%${req.body.searchStr}%`], async (err, rowsO) => {
+        if (err) {
             console.log(err)
         }
         db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name like ? or album_name like ? or artist like ?", [`%${await converters2t.convertPromise(req.body.searchStr)}%`, `%${await converters2t.convertPromise(req.body.searchStr)}%`, `%${await converters2t.convertPromise(req.body.searchStr)}%`], async (err, rowsT) => {
-            if(err){
+            if (err) {
                 console.log(err)
             }
             db.execute("SELECT uuid, song_name, album_name, artist, kind FROM instrunet_entry WHERE song_name like ? or album_name like ? or artist like ?", [`%${await convertert2s.convertPromise(req.body.searchStr)}%`, `%${await convertert2s.convertPromise(req.body.searchStr)}%`, `%${await convertert2s.convertPromise(req.body.searchStr)}%`], (err, rowsS) => {
-                if(err){
+                if (err) {
                     console.log(err)
                 }
                 try {
@@ -454,7 +469,7 @@ app.post('/search_api', async function (req, res) {
                         }
                     })
                     rowsO.forEach((row) => {
-                        if(JSON.stringify(prepare).indexOf(JSON.stringify(row)) === -1) {
+                        if (JSON.stringify(prepare).indexOf(JSON.stringify(row)) === -1) {
                             prepare = prepare.concat(row);
                         }
                     })
@@ -479,7 +494,6 @@ app.post('/search_api', async function (req, res) {
     })
 
 
-
 })
 app.options('/search_api', function (req, res) {
     res.header("Access-Control-Allow-Origin", "*");
@@ -549,9 +563,9 @@ app.post("/ncm/url", function (req, res) {
             }).then(async result => {
                 if (result.status === 200 || result.status === 304) {
                     let result_json = null;
-                    try{
-                       result_json =  await result.json()
-                    }catch (e){
+                    try {
+                        result_json = await result.json()
+                    } catch (e) {
                         res.status(500).header("Access-Control-Allow-Origin", "*").end("格式错误");
                         return
                     }
@@ -638,7 +652,6 @@ app.get('/:uuid', async function (req, res) {
                 })
 
 
-
             }