Covert to ESM and get it functional locally

This commit is contained in:
Allan Carr
2024-08-27 13:45:12 -07:00
parent e793402a79
commit 36ada6fd1f
19 changed files with 980 additions and 1046 deletions

View File

@@ -5,15 +5,12 @@ import { access } from "fs/promises";
import gm from "gm";
import imageThumbnail from "image-thumbnail";
import path from "path";
import { logger } from "../server";
import { AssetPaths, FolderPaths } from "./serverInit";
const simpleThumb = require("simple-thumbnail");
import { logger } from "../server.js";
import { AssetPaths, FolderPaths } from "./serverInit.js";
//@ts-ignore
import simpleThumb from "simple-thumbnail";
//const ffmpeg = require("ffmpeg-static");
var Bluebird = require("bluebird");
Bluebird.promisifyAll(gm.prototype);
/** @returns {string} Returns the relative path from the file to the thumbnail on the server. This must be converted to a URL. */
export default async function GenerateThumbnail(
file: string
@@ -73,14 +70,17 @@ export default async function GenerateThumbnail(
async function GeneratePdfThumbnail(file: string, thumbPath: string) {
const fileOnDisk: Buffer = await fs.readFile(file);
return new Promise<string>((resolve, reject) => {
const result = gm(fileOnDisk)
gm(fileOnDisk)
.selectFrame(0)
.setFormat("png")
.resize(200, 200, "!") // Resize to fixed 200px width, maintaining aspect ratio
.resize(200, 200, "!")
.quality(75)
.write(thumbPath, (error) => {
if (error) reject(error.message);
resolve(thumbPath);
if (error) {
reject(error);
} else {
resolve(thumbPath);
}
});
});
}