Jobs Media List functional

This commit is contained in:
Patrick Fic
2022-04-28 19:30:49 -07:00
parent 295e4deeb2
commit 9962ce0baf
11 changed files with 4116 additions and 4624 deletions

3
util/MediaUrlGen.ts Normal file
View File

@@ -0,0 +1,3 @@
export default function GenerateUrl(components: string[]) {
return components.join("/").replace(/([^:]\/)\/+/g, "$1");
}

30
util/generateThumbnail.ts Normal file
View File

@@ -0,0 +1,30 @@
import fs from "fs-extra";
import { access } from "fs/promises";
import imageThumbnail from "image-thumbnail";
import path from "path";
export default async function GenerateThumbnail(
file: string,
thumbPath: string
) {
try {
//Ensure the thumbs directory exists.
await fs.ensureDir(path.dirname(thumbPath));
try {
await access(thumbPath);
return;
return;
} catch {}
const thumbnail = await imageThumbnail(file, {
responseType: "buffer",
height: 250,
width: 250,
});
await fs.writeFile(thumbPath, thumbnail);
} catch (err) {
console.error("Error when genenerating thumbnail:", thumbPath);
}
}

View File

@@ -8,11 +8,16 @@ dotenv.config({
});
const RootDirectory = process.env.MEDIA_PATH!.replace("~", os.homedir);
const JobsFolder = "Jobs";
const VendorsFolder = "Vendors";
export const FolderPaths = {
Root: RootDirectory,
Jobs: path.join(RootDirectory, "Jobs"),
Vendors: path.join(RootDirectory, "Vendors"),
Jobs: path.join(RootDirectory, JobsFolder),
Vendors: path.join(RootDirectory, VendorsFolder),
ThumbsSubDir: "/thumbs",
StaticPath: "/static",
JobsFolder,
VendorsFolder,
};
export default function InitServer() {