Fix file format conversion in MediaBackend class

This commit is contained in:
Jesse Wierzbinski 2024-03-03 18:33:01 -10:00
parent 2d6de3064c
commit 576a5c83db
No known key found for this signature in database

View file

@ -41,7 +41,7 @@ class MediaBackend {
switch (fileFormatToConvertTo) { switch (fileFormatToConvertTo) {
case "png": case "png":
return new File( return new File(
[(await sharpCommand.png().toBuffer()).buffer], [(await sharpCommand.png().toBuffer()).buffer] as any,
// Replace the file extension with PNG // Replace the file extension with PNG
name.replace(/\.[^/.]+$/, ".png"), name.replace(/\.[^/.]+$/, ".png"),
{ {
@ -50,7 +50,7 @@ class MediaBackend {
); );
case "webp": case "webp":
return new File( return new File(
[(await sharpCommand.webp().toBuffer()).buffer], [(await sharpCommand.webp().toBuffer()).buffer] as any,
// Replace the file extension with WebP // Replace the file extension with WebP
name.replace(/\.[^/.]+$/, ".webp"), name.replace(/\.[^/.]+$/, ".webp"),
{ {
@ -59,7 +59,7 @@ class MediaBackend {
); );
case "jpeg": case "jpeg":
return new File( return new File(
[(await sharpCommand.jpeg().toBuffer()).buffer], [(await sharpCommand.jpeg().toBuffer()).buffer] as any,
// Replace the file extension with JPEG // Replace the file extension with JPEG
name.replace(/\.[^/.]+$/, ".jpeg"), name.replace(/\.[^/.]+$/, ".jpeg"),
{ {
@ -68,7 +68,7 @@ class MediaBackend {
); );
case "avif": case "avif":
return new File( return new File(
[(await sharpCommand.avif().toBuffer()).buffer], [(await sharpCommand.avif().toBuffer()).buffer] as any,
// Replace the file extension with AVIF // Replace the file extension with AVIF
name.replace(/\.[^/.]+$/, ".avif"), name.replace(/\.[^/.]+$/, ".avif"),
{ {
@ -78,7 +78,7 @@ class MediaBackend {
// Needs special build of libvips // Needs special build of libvips
case "jxl": case "jxl":
return new File( return new File(
[(await sharpCommand.jxl().toBuffer()).buffer], [(await sharpCommand.jxl().toBuffer()).buffer] as any,
// Replace the file extension with JXL // Replace the file extension with JXL
name.replace(/\.[^/.]+$/, ".jxl"), name.replace(/\.[^/.]+$/, ".jxl"),
{ {
@ -87,7 +87,7 @@ class MediaBackend {
); );
case "heif": case "heif":
return new File( return new File(
[(await sharpCommand.heif().toBuffer()).buffer], [(await sharpCommand.heif().toBuffer()).buffer] as any,
// Replace the file extension with HEIF // Replace the file extension with HEIF
name.replace(/\.[^/.]+$/, ".heif"), name.replace(/\.[^/.]+$/, ".heif"),
{ {