Jobs Media List functional
This commit is contained in:
3
util/MediaUrlGen.ts
Normal file
3
util/MediaUrlGen.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function GenerateUrl(components: string[]) {
|
||||
return components.join("/").replace(/([^:]\/)\/+/g, "$1");
|
||||
}
|
||||
30
util/generateThumbnail.ts
Normal file
30
util/generateThumbnail.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user