parameterize media fetch query

This commit is contained in:
WaveringAna 2024-12-28 20:47:14 -05:00
parent 414a4ac11a
commit 6853149638
3 changed files with 360 additions and 136 deletions

View file

@ -20,11 +20,11 @@ import fs from "fs";
* @property {string} APPLE - Uses the h264_videotoolbox codec for Apple GPU/MediaEngine-based encoding
*/
export enum EncodingType {
CPU = "libx264",
NVIDIA = "h264_nvenc",
AMD = "h264_amf",
INTEL = "h264_qsv",
APPLE = "h264_videotoolbox",
CPU = "libx264",
NVIDIA = "h264_nvenc",
AMD = "h264_amf",
INTEL = "h264_qsv",
APPLE = "h264_videotoolbox"
}
/**

View file

@ -31,13 +31,17 @@ const upload = multer({ storage: fileStorage /**, fileFilter: fileFilter**/ });
const fetchMedia: Middleware = (req, res, next) => {
const admin: boolean = req.user.username == "admin" ? true : false;
/**Check if the user is an admin, if so, show all posts from all users */
const query: string =
admin == true
? "SELECT * FROM media"
: `SELECT * FROM media WHERE username = '${req.user.username}'`;
const query: string = admin
? "SELECT * FROM media"
: "SELECT * FROM media WHERE username = ?";
db.all(query, (err: Error, rows: []) => {
if (err) return next(err);
const params: any[] = admin ? [] : [req.user.username];
db.all(query, params, (err: Error, rows: []) => {
if (err) {
console.error("Error fetching media:", err);
return res.status(500).send("Database error");
}
const files = rows.map((row: MediaRow) => {
return {
id: row.id,