AXCWG 6 miesięcy temu
rodzic
commit
c8b9d9b11c
1 zmienionych plików z 37 dodań i 28 usunięć
  1. 37 28
      main.js

+ 37 - 28
main.js

@@ -1,5 +1,6 @@
 var express = require('express');
 var app = express();
+var app_serve = express();
 var fs = require("fs");
 const sqlite3 = require('sqlite3').verbose();
 const db = new sqlite3.Database('./database.db');
@@ -19,6 +20,9 @@ console.log(crypto.randomUUID())
 app.use(bodyParser.json({"limit": "200mb"}));
 app.use(express.json());
 
+app_serve.use(bodyParser.json({"limit": "200mb"}));
+app_serve.use(express.json());
+
 const stmt = db.prepare("INSERT INTO instrument_entry (uuid, song_name, album_name, link_to, binary, artist) VALUES (?,?,?,?,?,?)")
 
 
@@ -78,34 +82,7 @@ app.post('/search_api', function (req, res) {
                or album_name like '%${req.body.searchStr}%'
                or artist like '%${req.body.searchStr}%'`, OnFetched)
 })
-app.get('/:uuid', function (req, res) {
-    async function Provider(err, rows) {
-        try {
-            res.header("Access-Control-Allow-Origin", "*");
-            /** @type {ArrayBuffer}*/
-            var buffer = rows[0].binary
-            res.setHeader('Content-Length', buffer.byteLength);
-            db.all(`SELECT "song_name"
-                    FROM instrument_entry
-                    WHERE uuid = '${req.params.uuid}'`, (err, row) => {
 
-                res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURI(row[0].song_name)+'.mp3' );
-                res.send(buffer)
-                res.end()
-            })
-
-
-        } catch (e) {
-            console.log(e)
-            console.log("Triggered err");
-
-        }
-    }
-
-    db.all(`SELECT "binary"
-            FROM instrument_entry
-            WHERE uuid = '${req.params.uuid}'`, Provider)
-})
 app.post('/fetch', function (req, res) {
     function Provider(err, rows) {
         try {
@@ -140,4 +117,36 @@ app.options('/search_api', function (req, res) {
     res.header("Access-Control-Allow-Headers", "Content-Type");
     res.end()
 })
-app.listen(8080)
+app_serve.get('/:uuid', function (req, res) {
+    async function Provider(err, rows) {
+        try {
+            res.header("Access-Control-Allow-Origin", "*");
+            /** @type {ArrayBuffer}*/
+            var buffer = rows[0].binary
+            res.setHeader('Content-Length', buffer.byteLength);
+            db.all(`SELECT "song_name"
+                    FROM instrument_entry
+                    WHERE uuid = '${req.params.uuid}'`, (err, row) => {
+
+                res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURI(row[0].song_name)+'.mp3' );
+                res.send(buffer)
+                res.end()
+            })
+
+
+        } catch (e) {
+            console.log(e)
+            console.log("Triggered err");
+
+        }
+    }
+
+    db.all(`SELECT "binary"
+            FROM instrument_entry
+            WHERE uuid = '${req.params.uuid}'`, Provider)
+})
+https.createServer({
+    key: fs.readFileSync('andyxie.cn.key'),
+    cert: fs.readFileSync('andyxie.cn.pem')
+},app).listen(8080)
+app_serve.listen(8079)