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:
@@ -436,6 +436,8 @@ export function createToolRoute<T>(app: FastifyInstance, config: ToolRouteConfig
|
||||
duration_ms: Date.now() - startTime,
|
||||
category: TOOLS.find((t) => t.id === config.toolId)?.category ?? "unknown",
|
||||
is_ai_tool: getBundleForTool(config.toolId) !== null,
|
||||
error_code: err instanceof Error ? err.constructor.name : "UnknownError",
|
||||
error_message: message.slice(0, 200),
|
||||
});
|
||||
return reply.status(422).send({
|
||||
error: "Processing failed",
|
||||
|
||||
@@ -5,13 +5,19 @@ import { z } from "zod";
|
||||
import { resolveOutputFormat } from "../../lib/output-format.js";
|
||||
import { createToolRoute } from "../tool-factory.js";
|
||||
|
||||
const settingsSchema = z.object({
|
||||
width: z.number().positive().optional(),
|
||||
height: z.number().positive().optional(),
|
||||
fit: z.enum(["contain", "cover", "fill", "inside", "outside"]).default("contain"),
|
||||
withoutEnlargement: z.boolean().default(false),
|
||||
percentage: z.number().positive().optional(),
|
||||
});
|
||||
const MAX_DIMENSION = 16383;
|
||||
|
||||
const settingsSchema = z
|
||||
.object({
|
||||
width: z.number().int().positive().max(MAX_DIMENSION).optional(),
|
||||
height: z.number().int().positive().max(MAX_DIMENSION).optional(),
|
||||
fit: z.enum(["contain", "cover", "fill", "inside", "outside"]).default("contain"),
|
||||
withoutEnlargement: z.boolean().default(false),
|
||||
percentage: z.number().positive().optional(),
|
||||
})
|
||||
.refine((s) => s.width !== undefined || s.height !== undefined || s.percentage !== undefined, {
|
||||
message: "At least one of width, height, or percentage is required",
|
||||
});
|
||||
|
||||
export function registerResize(app: FastifyInstance) {
|
||||
createToolRoute(app, {
|
||||
|
||||
Reference in New Issue
Block a user