|
@@ -5,6 +5,8 @@ import express from "express";
|
|
import session from "express-session";
|
|
import session from "express-session";
|
|
|
|
|
|
import cwh from "./Singletons.js";
|
|
import cwh from "./Singletons.js";
|
|
|
|
+import fs from "fs";
|
|
|
|
+import webp from "webp-converter";
|
|
|
|
|
|
export default function UserInteractions(opts) {
|
|
export default function UserInteractions(opts) {
|
|
async function sha256(message) {
|
|
async function sha256(message) {
|
|
@@ -125,7 +127,39 @@ export default function UserInteractions(opts) {
|
|
})
|
|
})
|
|
app.get("/playlist", async function (req, res) {
|
|
app.get("/playlist", async function (req, res) {
|
|
|
|
|
|
- db.execute("SELECT * FROM playlist where uuid=?", [req.query.playlistuuid], function (err, result) {
|
|
|
|
|
|
+ db.execute("SELECT owner, uuid, content, private FROM playlist where uuid=?", [req.query.playlistuuid], function (err, result) {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ res.set(cwh).status(500).json({code: 500, R: "AD"})
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (result.length === 0) {
|
|
|
|
+ res.set(cwh).status(404).json({code: 404, R: "DNF"})
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res.set(cwh).json(result[0]);
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ app.get("/playlist-name", async function (req, res) {
|
|
|
|
+ db.execute("SELECT title FROM playlist where uuid=?", [req.query.playlistuuid], function (err, result) {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ res.set(cwh).status(500).json({code: 500, R: "AD"})
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (result.length === 0) {
|
|
|
|
+ res.set(cwh).status(404).json({code: 404, R: "DNF"})
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res.set(cwh).end(result[0].title);
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ app.get('/playlist-tmb', async function (req, res) {
|
|
|
|
+ db.execute("SELECT tmb FROM playlist where uuid=?", [req.query.playlistuuid], function (err, result) {
|
|
if (err) {
|
|
if (err) {
|
|
console.log(err);
|
|
console.log(err);
|
|
res.set(cwh).status(500).json({code: 500, R: "AD"})
|
|
res.set(cwh).status(500).json({code: 500, R: "AD"})
|
|
@@ -147,7 +181,7 @@ export default function UserInteractions(opts) {
|
|
}
|
|
}
|
|
if (req.body.playlistuuid) {
|
|
if (req.body.playlistuuid) {
|
|
db.execute("SELECT owner FROM playlist WHERE uuid = ?", [req.body.playlistuuid], function (err, result) {
|
|
db.execute("SELECT owner FROM playlist WHERE uuid = ?", [req.body.playlistuuid], function (err, result) {
|
|
- if(result.length === 0) {
|
|
|
|
|
|
+ if (result.length === 0) {
|
|
res.set(cwh).status(200).json({code: 301, R: "DNM"})
|
|
res.set(cwh).status(200).json({code: 301, R: "DNM"})
|
|
|
|
|
|
}
|
|
}
|
|
@@ -173,14 +207,47 @@ export default function UserInteractions(opts) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (req.body.playlistuuid) {
|
|
if (req.body.playlistuuid) {
|
|
- db.execute("SELECT owner FROM playlist WHERE uuid = ?", [req.body.playlistuuid], function (err, result) {
|
|
|
|
|
|
+ db.execute("SELECT owner FROM playlist WHERE uuid = ?", [req.body.playlistuuid], async function (err, result) {
|
|
if (result[0].owner === req.session.uuid) {
|
|
if (result[0].owner === req.session.uuid) {
|
|
- db.execute("UPDATE playlist SET content = ?, private = ?, tmb = ?, title = ? WHERE uuid = ?", [req.body.content, req.body.private, Buffer.from( Object.values(req.body.tmb.data)), req.body.title, req.body.playlistuuid], (err, result) => {
|
|
|
|
|
|
+ let uuid = crypto.randomUUID();
|
|
|
|
+ fs.writeFileSync("tmp/"+uuid, Buffer.from(Object.values(req.body.tmb.data)));
|
|
|
|
+ try{
|
|
|
|
+ await webp.cwebp("tmp/"+uuid, "tmp/"+uuid+".webp", "-q 80 -size 100000 -mt -metadata all", "-v")
|
|
|
|
+
|
|
|
|
+ }catch(e){
|
|
|
|
+ console.log(e)
|
|
|
|
+ res.set(cwh).status(500).json({code: 500, R: "Err"})
|
|
|
|
+ fs.rm("tmp/"+uuid, (err) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ fs.rm("tmp/"+uuid+".webp", (err) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let pl_cover = fs.readFileSync("tmp/"+uuid+".webp");
|
|
|
|
+ fs.rm("tmp/"+uuid, (err) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ fs.rm("tmp/"+uuid+".webp", (err) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ res.set(cwh).status(200).json({code: 200, R: "SS"})
|
|
|
|
+ db.execute("UPDATE playlist SET content = ?, private = ?, tmb = ?, title = ? WHERE uuid = ?", [req.body.content, req.body.private, pl_cover, req.body.title, req.body.playlistuuid], (err, result) => {
|
|
if (err) {
|
|
if (err) {
|
|
console.log(err);
|
|
console.log(err);
|
|
res.set(cwh).status(500).json({code: 500, R: "Err"})
|
|
res.set(cwh).status(500).json({code: 500, R: "Err"})
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
res.set(cwh).status(403).json({code: 403, R: "Forbidden"})
|
|
res.set(cwh).status(403).json({code: 403, R: "Forbidden"})
|