mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: resolve analytics data gaps and resize validation failures
- Fix resize 20% failure rate: add Zod refine requiring at least one dimension, enforce integer/max constraints, clamp percentage scaling to minimum 1px, and guard against missing metadata in withoutEnlargement - Fix PostHog init race condition: move consent check before async import so frontend events (search, pageview) are no longer silently dropped - Fix identify() passing nested $set/$set_once wrappers instead of flat properties, so version person property now appears on PostHog profiles - Add error_code and error_message to failed tool_used analytics events for debugging tool failures from PostHog
This commit is contained in:
@@ -8,10 +8,11 @@ export async function resize(image: Sharp, options: ResizeOptions): Promise<Shar
|
||||
throw new Error("Resize percentage must be greater than 0");
|
||||
}
|
||||
const metadata = await image.metadata();
|
||||
const currentWidth = metadata.width ?? 0;
|
||||
const currentHeight = metadata.height ?? 0;
|
||||
width = Math.round(currentWidth * (percentage / 100));
|
||||
height = Math.round(currentHeight * (percentage / 100));
|
||||
if (!metadata.width || !metadata.height) {
|
||||
throw new Error("Cannot determine image dimensions for percentage resize");
|
||||
}
|
||||
width = Math.max(1, Math.round(metadata.width * (percentage / 100)));
|
||||
height = Math.max(1, Math.round(metadata.height * (percentage / 100)));
|
||||
}
|
||||
|
||||
if (width !== undefined && width <= 0) {
|
||||
@@ -26,10 +27,11 @@ export async function resize(image: Sharp, options: ResizeOptions): Promise<Shar
|
||||
|
||||
if (withoutEnlargement) {
|
||||
const meta = await image.metadata();
|
||||
const curW = meta.width ?? 0;
|
||||
const curH = meta.height ?? 0;
|
||||
if (width !== undefined && width > curW) width = curW;
|
||||
if (height !== undefined && height > curH) height = curH;
|
||||
if (!meta.width || !meta.height) {
|
||||
throw new Error("Cannot determine image dimensions for resize clamping");
|
||||
}
|
||||
if (width !== undefined && width > meta.width) width = meta.width;
|
||||
if (height !== undefined && height > meta.height) height = meta.height;
|
||||
}
|
||||
|
||||
return image.resize({
|
||||
|
||||
Reference in New Issue
Block a user