From 27161f554fcb55e670b9fd04e83bc7778bc9068c Mon Sep 17 00:00:00 2001 From: Philippe Loctaux
Date: Wed, 17 May 2023 23:14:19 +0200 Subject: [PATCH] wallpapers: make sure file is an image --- utils/wallpapers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/wallpapers.ts b/utils/wallpapers.ts index f6cf748..d9a01cf 100644 --- a/utils/wallpapers.ts +++ b/utils/wallpapers.ts @@ -1,6 +1,7 @@ import exifr from "npm:exifr@^7.1.3"; import { writeJson } from "https://deno.land/x/jsonfile@1.0.0/mod.ts"; +import { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; const publicPath = "/public"; const wallpapersPath = "/wallpapers"; @@ -17,10 +18,13 @@ const wallpapers: MyWallpaper[] = []; // For each file in the wallpapers directory for await (const dirEntry of Deno.readDir(imagesPath)) { - if (!dirEntry.isFile || dirEntry.name === ".gitkeep") { + // Make sure it is a file and it is an image + if (!dirEntry.isFile || !mime.getType(dirEntry.name)?.startsWith("image/")) { continue; } + console.log(`Processing ${dirEntry.name}`); + // Open file const path = `${imagesPath}/${dirEntry.name}`; const bytes = await Deno.readFile(path); @@ -44,8 +48,6 @@ for await (const dirEntry of Deno.readDir(imagesPath)) { // Final filename const file = `${wallpapersPath}/${dirEntry.name}`; - console.log(`Processed ${file}`); - wallpapers.push({ file, date,