|
@@ -1,10 +1,11 @@
|
|
|
+const cron = require("node-cron");
|
|
|
const fs = require('fs');
|
|
|
const express = require('express');
|
|
|
const app = express();
|
|
|
const app_serve = express();
|
|
|
const mysql = require('mysql2')
|
|
|
const SendSeekable = require('send-seekable');
|
|
|
-
|
|
|
+const WebSocket = require('ws');
|
|
|
const pool = mysql.createPool({
|
|
|
keepAliveInitialDelay: 10000, enableKeepAlive: true,
|
|
|
})
|
|
@@ -16,6 +17,8 @@ const nodemailer = require('nodemailer')
|
|
|
const bodyParser = require("body-parser");
|
|
|
const nrc = require('node-run-cmd')
|
|
|
const https = require("node:https");
|
|
|
+const {WebSocketServer} = require("ws");
|
|
|
+const http = require("node:http");
|
|
|
|
|
|
app.use(bodyParser.json({"limit": "200mb"}));
|
|
|
app.use(express.json());
|
|
@@ -25,15 +28,14 @@ app_serve.use(express.json());
|
|
|
app_serve.use(SendSeekable)
|
|
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
- host: 'smtp.qq.com',
|
|
|
- port: 465,
|
|
|
- secure: true,
|
|
|
- auth: {
|
|
|
- user: '3095864740@qq.com',
|
|
|
- pass: 'caemyuagapsadfff',
|
|
|
+ host: 'smtp.qq.com', port: 465, secure: true, auth: {
|
|
|
+ user: '3095864740@qq.com', pass: 'caemyuagapsadfff',
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
app.post('/submit', function (req, res) {
|
|
|
let uuid = crypto.randomUUID()
|
|
|
db.connect(function (err) {
|
|
@@ -77,6 +79,19 @@ app.post('/submit', function (req, res) {
|
|
|
kind_of[2] = `${uuid}_(Instrumental)_UVR_MDXNET_KARA.mp3`
|
|
|
kind_of[3] = `./output/${uuid}_(Vocals)_UVR_MDXNET_KARA.mp3`
|
|
|
break;
|
|
|
+ case 3:
|
|
|
+ kind_of[0] = `audio-separator ./${uuid} --model_filename kuielab_a_bass.onnx --mdx_segment_size 4000 --mdx_overlap 0.75 --output_format mp3 --mdx_batch_size 300 --output_dir output`
|
|
|
+ kind_of[1] = `./output/${uuid}_(Bass)_kuielab_a_bass.mp3`
|
|
|
+ kind_of[2] = `${uuid}_(Bass)_kuielab_a_bass.mp3`
|
|
|
+ kind_of[3] = `./output/${uuid}_(No Bass)_kuielab_a_bass.mp3`
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ kind_of[0] = `audio-separator ./${uuid} --model_filename kuielab_a_drums.onnx --mdx_segment_size 4000 --mdx_overlap 0.75 --output_format mp3 --mdx_batch_size 300 --output_dir output`
|
|
|
+ kind_of[1] = `./output/${uuid}_(Drums)_kuielab_a_drums.mp3`
|
|
|
+ kind_of[2] = `${uuid}_(Drums)_kuielab_a_drums.mp3`
|
|
|
+ kind_of[3] = `./output/${uuid}_(No Drums)_kuielab_a_drums.mp3`
|
|
|
+ break;
|
|
|
+
|
|
|
|
|
|
}
|
|
|
nrc.run([kind_of[0]], {
|
|
@@ -93,6 +108,12 @@ app.post('/submit', function (req, res) {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
+ fs.rm(kind_of[3], (err) => {
|
|
|
+ if (err) {
|
|
|
+ console.log(err);
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
fs.rm(uuid, (err) => {
|
|
|
if (err) {
|
|
|
console.log(err);
|
|
@@ -108,10 +129,7 @@ app.post('/submit', function (req, res) {
|
|
|
to: req.body.email,
|
|
|
subject: "你的音频已处理完成。",
|
|
|
text: "你的音频已处理完成。",
|
|
|
- html:
|
|
|
- "<h1>哈喽👋</h1><p>你在伴奏网网站上传的音频已经处理完毕,快来下载吧!<br/>下载链接:<br/><a href='https://andyxie.cn:8201/" + uuid + "'>这里</a><br/><br/>" +
|
|
|
- "与其他网站不一样,本邮件发送邮箱真的有个伞兵在后面!<br/>" +
|
|
|
- "请随意骚扰!</p>"
|
|
|
+ html: "<h1>哈喽👋</h1><p>你在伴奏网网站上传的音频已经处理完毕,快来下载吧!<br/>下载链接:<br/><a href='https://andyxie.cn:8201/" + uuid + "'>这里</a><br/><br/>" + "与其他网站不一样,本邮件发送邮箱真的有个伞兵在后面!<br/>" + "请随意骚扰!</p>"
|
|
|
}).then((result) => {
|
|
|
console.log("Message sent: %s", result.messageId)
|
|
|
|
|
@@ -157,7 +175,7 @@ app.options('/search_api', function (req, res) {
|
|
|
})
|
|
|
app.get("/getSingle", function (req, res) {
|
|
|
if (req.query.id) {
|
|
|
- db.execute(`SELECT song_name, album_name, artist
|
|
|
+ db.execute(`SELECT song_name, album_name, artist, kind
|
|
|
FROM instrunet_entry
|
|
|
WHERE uuid = "${req.query.id}"`, function (err, rows) {
|
|
|
if (err) {
|
|
@@ -170,7 +188,7 @@ app.get("/getSingle", function (req, res) {
|
|
|
res.end(JSON.stringify(rows[0]));
|
|
|
})
|
|
|
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
res.contentType("application/json");
|
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
|
res.header("Access-Control-Allow-Headers", "Content-Type");
|
|
@@ -178,14 +196,24 @@ app.get("/getSingle", function (req, res) {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
+var availCache = {}
|
|
|
+cron.schedule('*/1 * * * *', ()=>{
|
|
|
+ availCache = {}
|
|
|
+})
|
|
|
app_serve.get('/:uuid', function (req, res, next) {
|
|
|
- async function Provider(err, rows) {
|
|
|
+
|
|
|
+ let uuid = req.params.uuid;
|
|
|
+
|
|
|
+ function Provider(err, rows) {
|
|
|
try {
|
|
|
+ res.contentType("audio/mp3");
|
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
|
+ res.header("Access-Control-Allow-Headers", "Content-Type");
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
+ res.header('Content-Disposition', `attachment; filename="${encodeURI(rows[0].song_name)}"`);
|
|
|
/** @type {ArrayBuffer}*/
|
|
|
- let buffer = rows[0].databinary
|
|
|
- res.sendSeekable(buffer)
|
|
|
- db.unprepare()
|
|
|
+ availCache[uuid] = rows[0].databinary
|
|
|
+ res.sendSeekable(availCache[uuid])
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
@@ -195,12 +223,30 @@ app_serve.get('/:uuid', function (req, res, next) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- db.execute(`SELECT databinary
|
|
|
+ if (availCache[uuid] !== undefined) {
|
|
|
+ db.execute(`SELECT song_name
|
|
|
FROM instrunet_entry
|
|
|
- WHERE uuid = '${req.params.uuid}'`, Provider)
|
|
|
- db.unprepare()
|
|
|
+ WHERE uuid = '${uuid}'`, (err, rows) => {
|
|
|
+ res.contentType("audio/mp3");
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
+ res.header("Access-Control-Allow-Headers", "Content-Type");
|
|
|
+ res.header("Access-Control-Allow-Origin", "*");
|
|
|
+ res.header('Content-Disposition', `attachment; filename="${encodeURI(rows[0].song_name)}"`);
|
|
|
+ res.sendSeekable(availCache[uuid])
|
|
|
+ })
|
|
|
+
|
|
|
+ }else{
|
|
|
+ db.execute(`SELECT song_name, databinary
|
|
|
+ FROM instrunet_entry
|
|
|
+ WHERE uuid = '${uuid}'`, Provider)
|
|
|
+ db.unprepare()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
})
|
|
|
|
|
|
+// TODO Always use HTTPS before publishing.
|
|
|
|
|
|
https.createServer({
|
|
|
key: fs.readFileSync('andyxie.cn.key'), cert: fs.readFileSync('andyxie.cn.pem')
|
|
@@ -213,5 +259,6 @@ https.createServer({
|
|
|
|
|
|
}, app_serve).listen(8079)
|
|
|
|
|
|
+
|
|
|
// app.listen(8080)
|
|
|
// app_serve.listen(8079)
|