AXCWG 5 months ago
parent
commit
06ef7eceba
3 changed files with 71 additions and 10 deletions
  1. 12 0
      .idea/dataSources.xml
  2. 7 0
      .idea/sqldialects.xml
  3. 52 10
      main.js

+ 12 - 0
.idea/dataSources.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
+    <data-source source="LOCAL" name="database" uuid="737a284f-b67d-4faf-aaa3-ea1b7a3f4aaf">
+      <driver-ref>sqlite.xerial</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>org.sqlite.JDBC</jdbc-driver>
+      <jdbc-url>jdbc:sqlite:$PROJECT_DIR$/database.db</jdbc-url>
+      <working-dir>$ProjectFileDir$</working-dir>
+    </data-source>
+  </component>
+</project>

+ 7 - 0
.idea/sqldialects.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="SqlDialectMappings">
+    <file url="file://$PROJECT_DIR$/main.js" dialect="GenericSQL" />
+    <file url="PROJECT" dialect="SQLite" />
+  </component>
+</project>

+ 52 - 10
main.js

@@ -7,24 +7,28 @@ const jwt = require("jsonwebtoken");
 const bodyParser = require("body-parser");
 const {spawn} = require("child_process");
 const nrc = require('node-run-cmd')
-console.log(process.cwd())
-app.use(bodyParser.json({"limit": "100mb"}));
+
+console.log(crypto.randomUUID())
+
+app.use(bodyParser.json({"limit": "200mb"}));
 app.use(express.json());
 
-db.close()
+const stmt = db.prepare("INSERT INTO instrument_entry (uuid, song_name, album_name, link_to, binary, artist) VALUES (?,?,?,?,?,?)")
 
 
 app.post('/submit', function (req, res) {
+
     res.header("Access-Control-Allow-Origin", "*");
 
 
-    fetch(req.body.file).then(res => {
-        res.arrayBuffer().then(r => fs.writeFileSync("./audio_file", Buffer.from(r)));
-    })
-        .catch(err => {
-        console.log(err)
-        res.sendStatus(500)
-    });
+    try {
+        fetch(req.body.file).then(res => {
+            res.arrayBuffer().then(r => fs.writeFileSync("./audio_file", Buffer.from(r)));
+        })
+    } catch (err) {
+        res.status(500).send("Server Error");
+        return
+    }
 
     var callback = function (d) {
         console.log(d.toString());
@@ -39,6 +43,8 @@ app.post('/submit', function (req, res) {
         r[1] === 1 ?
             res.sendStatus(500)
             : res.end("api_success");
+        stmt.run(crypto.randomUUID(), req.body.name, req.body.albumName, req.body.link, fs.readFileSync('./output/audio_file_(Instrumental)_UVR_MDXNET_KARA.flac', req.body.artist))
+
     })
 
 })
@@ -47,4 +53,40 @@ app.options('/submit', function (req, res) {
     res.header("Access-Control-Allow-Headers", "Content-Type");
     res.end()
 })
+
+app.post('/search_api', function (req, res) {
+    function OnFetched(err, rows){
+        try{
+            res.header("Access-Control-Allow-Origin", "*");
+            console.log("Triggered");
+            res.end(JSON.stringify(rows));
+        }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)
+})
+
+app.post('/fetch', function (req, res) {
+    function Provider(err, rows){
+        try{
+            res.header("Access-Control-Allow-Origin", "*");
+            console.log("Triggered");
+            res.end(rows[0]);
+        }catch(e){
+
+        }
+    }
+    db.all(`SELECT binary FROM instrument_entry WHERE uuid=${req.body.uuid}`, Provider)
+
+})
+
+app.options('/search_api', function (req, res) {
+    res.header("Access-Control-Allow-Origin", "*");
+    res.header("Access-Control-Allow-Headers", "Content-Type");
+    res.end()
+})
 app.listen(8080);