فهرست منبع

redesigned_download

AXCWG 5 ماه پیش
والد
کامیت
1ded1eeb50
3فایلهای تغییر یافته به همراه52 افزوده شده و 7 حذف شده
  1. 34 7
      main.js
  2. 17 0
      package-lock.json
  3. 1 0
      package.json

+ 34 - 7
main.js

@@ -8,9 +8,11 @@ const bodyParser = require("body-parser");
 const {spawn} = require("child_process");
 const nrc = require('node-run-cmd')
 const https = require("node:https");
+const {encode} = require("html-entities");
+const querystring = require("node:querystring");
 
-var key = fs.readFileSync('./andyxie.cn.key')
-var cert = fs.readFileSync('./andyxie.cn.pem')
+// var key = fs.readFileSync('./andyxie.cn.key')
+// var cert = fs.readFileSync('./andyxie.cn.pem')
 
 console.log(crypto.randomUUID())
 
@@ -76,14 +78,41 @@ 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 {
             res.header("Access-Control-Allow-Origin", "*");
             console.log(rows[0].binary)
-
-
+            var str = URL.createObjectURL(new Blob(rows[0].binary))
+            console.log(str)
             res.end(JSON.stringify({data: Buffer.from(rows[0].binary).toString('base64')}));
 
 
@@ -111,6 +140,4 @@ app.options('/search_api', function (req, res) {
     res.header("Access-Control-Allow-Headers", "Content-Type");
     res.end()
 })
-https.createServer({
-    key:key, cert: cert,
-}, app).listen(8080)
+app.listen(8080)

+ 17 - 0
package-lock.json

@@ -11,6 +11,7 @@
       "dependencies": {
         "body-parser": "^1.20.3",
         "express": "^4.21.1",
+        "html-entities": "^2.5.2",
         "https": "^1.0.0",
         "jsonwebtoken": "^9.0.2",
         "node-run-cmd": "^1.0.1",
@@ -945,6 +946,22 @@
         "node": ">= 0.4"
       }
     },
+    "node_modules/html-entities": {
+      "version": "2.5.2",
+      "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.5.2.tgz",
+      "integrity": "sha512-K//PSRMQk4FZ78Kyau+mZurHn3FH0Vwr+H36eE0rPbeYkRRi9YxceYPhuN60UwWorxyKHhqoAJl2OFKa4BVtaA==",
+      "funding": [
+        {
+          "type": "github",
+          "url": "https://github.com/sponsors/mdevils"
+        },
+        {
+          "type": "patreon",
+          "url": "https://patreon.com/mdevils"
+        }
+      ],
+      "license": "MIT"
+    },
     "node_modules/http-cache-semantics": {
       "version": "4.1.1",
       "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz",

+ 1 - 0
package.json

@@ -12,6 +12,7 @@
   "dependencies": {
     "body-parser": "^1.20.3",
     "express": "^4.21.1",
+    "html-entities": "^2.5.2",
     "https": "^1.0.0",
     "jsonwebtoken": "^9.0.2",
     "node-run-cmd": "^1.0.1",