start some documentation work
This commit is contained in:
parent
a42eeeda90
commit
1e23bd879b
8 changed files with 8857 additions and 11052 deletions
|
@ -7,8 +7,8 @@ mkdirp.sync("./var/db");
|
|||
|
||||
export const db = new sqlite3.Database("./var/db/media.db");
|
||||
|
||||
/**Create the database schema for the embedders app*/
|
||||
export function createDatabase(version: number){
|
||||
// create the database schema for the embedders app
|
||||
console.log("Creating database");
|
||||
|
||||
db.run("CREATE TABLE IF NOT EXISTS users ( \
|
||||
|
@ -46,6 +46,27 @@ export function updateDatabase(oldVersion: number, newVersion: number){
|
|||
}
|
||||
}
|
||||
|
||||
/**Inserts into the media table */
|
||||
export function insertToDB (filename: string, expireDate: Date, username: string) {
|
||||
const params: MediaParams = [
|
||||
filename,
|
||||
expireDate,
|
||||
username
|
||||
];
|
||||
|
||||
db.run("INSERT INTO media (path, expire, username) VALUES (?, ?, ?)", params, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return err;
|
||||
}
|
||||
console.log(`Uploaded ${filename} to database`);
|
||||
if (expireDate == null)
|
||||
console.log("It will not expire");
|
||||
else if (expireDate != null || expireDate != undefined)
|
||||
console.log(`It will expire on ${expireDate}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**Searches the database and returns images with partial or exact keysearches */
|
||||
export function searchImages(imagename: string, partial: boolean) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -75,7 +96,7 @@ export function createUser(username: string, password: string) {
|
|||
});
|
||||
}
|
||||
|
||||
/**Selects a path for a file given ID */
|
||||
/**Selects the path for a file given ID */
|
||||
export function getPath(id: number | string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = "SELECT path FROM media WHERE id = ?";
|
||||
|
|
|
@ -10,7 +10,7 @@ import fs from "fs";
|
|||
import process from "process";
|
||||
|
||||
import {extension, videoExtensions, imageExtensions} from "./lib";
|
||||
import {db, MediaParams} from "./db";
|
||||
import {db, MediaParams, insertToDB} from "./db";
|
||||
|
||||
export const checkAuth: Middleware = (req, res, next) => {
|
||||
if (!req.user) {
|
||||
|
@ -158,31 +158,10 @@ export const handleUpload: Middleware = (req, res, next) => {
|
|||
|
||||
if (files instanceof Array) {
|
||||
for (const file in files) {
|
||||
insertToDB(files[file].filename, expireDate, username, next);
|
||||
insertToDB(files[file].filename, expireDate, username);
|
||||
}
|
||||
} else
|
||||
insertToDB(files.filename, expireDate, username, next);
|
||||
insertToDB(files.filename, expireDate, username);
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
/**Inserts into media database */
|
||||
function insertToDB (filename: string, expireDate: Date, username: string, next: NextFunction) {
|
||||
const params: MediaParams = [
|
||||
filename,
|
||||
expireDate,
|
||||
username
|
||||
];
|
||||
|
||||
db.run("INSERT INTO media (path, expire, username) VALUES (?, ?, ?)", params, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return next(err);
|
||||
}
|
||||
console.log(`Uploaded ${filename} to database`);
|
||||
if (expireDate == null)
|
||||
console.log("It will not expire");
|
||||
else if (expireDate != null || expireDate != undefined)
|
||||
console.log(`It will expire on ${expireDate}`);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue