presentation

This commit is contained in:
2025-03-17 19:49:41 +02:00
parent d5d8d60212
commit 9eb14f0668
13 changed files with 218 additions and 117 deletions
+14 -2
View File
@@ -2,6 +2,10 @@ import decompress from "decompress";
import sharp from 'sharp';
sharp.cache({ files : 0 });
import util from 'node:util';
import { execFile as npExecFile } from 'child_process';
const execFile = util.promisify(npExecFile);
import fs from 'fs';
import path from 'path';
@@ -99,7 +103,7 @@ class GameObjectsManager{
}else{
object.asset.type = 'single';
await fs.promises.copyFile(src, def + ext);
if (['.jpg', '.png', '.webp'].includes(ext)){
if (['.jpg', '.png', '.webp', '.mp4', '.avi', '.webv'].includes(ext)){
await this.addThumb(object, src);
}
}
@@ -111,8 +115,16 @@ class GameObjectsManager{
* @param {File} thumbSrc A thumbnail, представително изображение
*/
this.addThumb = async function(object, thumbSrc){
let ext = path.extname(object.asset.ofn).toLowerCase();
let dest = `${config.fs.repo}/thumb/${object.id}.webp`;
await sharp(thumbSrc).resize({height: 250}).toFile(dest);
if (['.jpg', '.png', '.webp'].includes(ext)){
await sharp(thumbSrc).resize({height: 250}).toFile(dest);
}else if (['.mp4', '.avi', '.webv'].includes(ext)){
let frame = 1;
await execFile('ffmpeg', [
'-i', thumbSrc, '-vf', `select=eq(n\\,${frame}),scale=-2:300`,
'-vframes', 1, '-f', 'image2', '-y', dest]);
}
object.asset.thumb = `${object.id}.webp`;
}