Skip to content

Commit

Permalink
updated hash to take into account params
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Jan 5, 2022
1 parent 3a5a753 commit b3847b0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions images/route.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ export let loader: LoaderFunction = async ({ request }) => {
return badImageResponse();
}

let width = getIntOrNull(url.searchParams.get("width"));
let height = getIntOrNull(url.searchParams.get("height"));
let fit: any = url.searchParams.get("fit") || "cover";

let hash = createHash("sha256");
hash.update("v1");
hash.update(request.method);
hash.update(request.url);
hash.update(width?.toString() || "0");
hash.update(height?.toString() || "0");
hash.update(fit);
let key = hash.digest("hex");
let cachedFile = path.resolve(path.join(".cache/images", key + ".webp"));

Expand Down Expand Up @@ -95,9 +102,6 @@ export let loader: LoaderFunction = async ({ request }) => {
console.error(error);
});

let width = getIntOrNull(url.searchParams.get("width"));
let height = getIntOrNull(url.searchParams.get("height"));
let fit: any = url.searchParams.get("fit") || "cover";
if (width || height) {
sharpInstance.resize(width, height, { fit });
}
Expand Down

0 comments on commit b3847b0

Please sign in to comment.