|
@@ -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)
|