Add documentation to functions

This commit is contained in:
waveringana 2022-12-11 06:31:19 +00:00
parent 0a0d9b9802
commit 34e991f017
5 changed files with 18 additions and 7 deletions

View file

@ -4,7 +4,7 @@ import express from "express";
import {db, createUser} from "../types/db";
const router: Router = express.Router();
/**Middleware to check if a user is actually signed in */
const adminCheck: Middleware = (req: Request, res: Response, next: NextFunction) => {
if (!req.user)
return res.status(403).send("You are not authorized to perform this action");

View file

@ -18,9 +18,10 @@ import {fileStorage, fileFilter} from "../types/multer";
import {checkAuth, checkSharexAuth, createEmbedData, handleUpload} from "./middleware";
let upload = multer({ storage: fileStorage /**, fileFilter: fileFilter**/ }); //maybe make this a env variable?
/**Middleware to grab media from media database */
const fetchMedia: Middleware = (req, res, next) => {
let admin: boolean = req.user.username == "admin" ? true : false
/**Check if the user is an admin, if so, show all posts from all users */
let query: string = admin == true ? "SELECT * FROM media" : `SELECT * FROM media WHERE username = '${req.user.username}'`;
db.all(query, (err:Error, rows: []) => {

View file

@ -20,6 +20,7 @@ export const checkAuth: Middleware = (req, res, next) => {
next();
}
/**Checks shareX auth key */
export const checkSharexAuth: Middleware = (req, res, next) => {
let auth = process.env.EBAPI_KEY || process.env.EBPASS || "pleaseSetAPI_KEY";
let key = null;
@ -40,6 +41,7 @@ export const checkSharexAuth: Middleware = (req, res, next) => {
next();
}
/**Creates oembed json file for embed metadata */
export const createEmbedData: Middleware = (req, res, next) => {
const files = req.files as Express.Multer.File[]
for (let file in files) {
@ -62,7 +64,7 @@ export const createEmbedData: Middleware = (req, res, next) => {
}
next();
}
/** Converts video to gif and vice versa using ffmpeg */
export const convert: Middleware = (req, res, next) => {
const files = req.files as Express.Multer.File[]
for (let file in files) {
@ -100,7 +102,7 @@ export const convert: Middleware = (req, res, next) => {
}
}
}
/**Middleware for handling uploaded files. Inserts it into the database */
export const handleUpload: Middleware = (req, res, next) => {
if (!req.file && !req.files) {
console.log("No files were uploaded");
@ -120,7 +122,7 @@ export const handleUpload: Middleware = (req, res, next) => {
next();
}
/**Inserts into media database */
function insertToDB (filename: string, expireDate: Date, username: string, next: NextFunction) {
let params: MediaParams = [
filename,