axcwg 5 сар өмнө
parent
commit
b8f4972535
3 өөрчлөгдсөн 30 нэмэгдсэн , 11 устгасан
  1. 0 1
      .gitignore
  2. BIN
      database.db
  3. 30 10
      main.js

+ 0 - 1
.gitignore

@@ -1,5 +1,4 @@
 node_modules
-database.db
 secret.txt
 audio_file
 MDX_Net_Models

BIN
database.db


+ 30 - 10
main.js

@@ -8,6 +8,7 @@ const bodyParser = require("body-parser");
 const {spawn} = require("child_process");
 const nrc = require('node-run-cmd')
 
+
 console.log(crypto.randomUUID())
 
 app.use(bodyParser.json({"limit": "200mb"}));
@@ -55,33 +56,52 @@ app.options('/submit', function (req, res) {
 })
 
 app.post('/search_api', function (req, res) {
-    function OnFetched(err, rows){
-        try{
+    function OnFetched(err, rows) {
+        try {
             res.header("Access-Control-Allow-Origin", "*");
             console.log("Triggered");
             res.end(JSON.stringify(rows));
-        }catch(e){
+        } catch (e) {
 
         }
 
     }
 
     console.log(req.body.searchStr)
-    db.all(`SELECT id, uuid, song_name, album_name, artist FROM instrument_entry WHERE song_name like '%${req.body.searchStr}%' or album_name like '%${req.body.searchStr}%' or artist like '%${req.body.searchStr}%'`, OnFetched)
+    db.all(`SELECT id, uuid, song_name, album_name, artist
+            FROM instrument_entry
+            WHERE song_name like '%${req.body.searchStr}%'
+               or album_name like '%${req.body.searchStr}%'
+               or artist like '%${req.body.searchStr}%'`, OnFetched)
 })
 
 app.post('/fetch', function (req, res) {
-    function Provider(err, rows){
-        try{
+    function Provider(err, rows) {
+        try {
             res.header("Access-Control-Allow-Origin", "*");
-            console.log("Triggered");
-            res.end(rows[0]);
-        }catch(e){
+            console.log(rows[0].binary)
+
+
+            res.end(JSON.stringify({data: Buffer.from(rows[0].binary).toString('base64')}) );
+
+
+        } catch (e) {
+            console.log(e)
+            console.log("Triggered err");
 
         }
     }
-    db.all(`SELECT binary FROM instrument_entry WHERE uuid=${req.body.uuid}`, Provider)
 
+    console.log(req.body.uuid)
+    db.all(`SELECT "binary"
+            FROM instrument_entry
+            WHERE uuid = '${req.body.uuid}'`, Provider)
+
+})
+app.options('/fetch', function (req, res) {
+    res.header("Access-Control-Allow-Origin", "*");
+    res.header("Access-Control-Allow-Headers", "Content-Type");
+    res.end()
 })
 
 app.options('/search_api', function (req, res) {