Convert image uploads into webp files unless it's a gif (closes #11)

This commit is contained in:
Oliver 2026-02-03 18:20:43 -07:00
parent 4a2c40397f
commit 73601c579c
4 changed files with 54 additions and 8 deletions

View file

@ -1,5 +1,5 @@
import { __ID__, filePath } from "../consts.mjs";
import { determineFileExtension, getFile, hashFile, lastModifiedAt, uploadFile, uploadJson } from "../utils/fs.mjs";
import { convertToWebp, determineFileExtension, getFile, hashFile, lastModifiedAt, uploadFile, uploadJson } from "../utils/fs.mjs";
import { DBConnectorMixin } from "./mixins/DBConnector.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
@ -147,7 +147,7 @@ export class ImageApp extends
this.#artistCache.push({ value: id, label: artist.name });
};
};
console.log(this._doc);
const ctx = {
meta: {
idp: this.id,
@ -170,7 +170,7 @@ export class ImageApp extends
#file = null;
async #changeImage(event) {
/** @type {File} */
const file = this.#file = event.target.files[0];
let file = this.#file = event.target.files[0];
// Prevent memory leaks
URL.revokeObjectURL(this._doc.path);
@ -185,7 +185,15 @@ export class ImageApp extends
};
// Ensure we don't already have the file uploaded
const extension = determineFileExtension(file);
const webp = await convertToWebp(file);
let extension;
if (webp) {
file = this.#file = webp;
extension = `webp`;
} else {
extension = determineFileExtension(file);
};
const hash = await hashFile(file);
const path = `storage/tokens/${hash}.${extension}`;
const lastModified = await lastModifiedAt(path);