Covert to ESM and get it functional locally
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user