-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: watermark enabled without config #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds runtime validation for watermark configuration on link creation and update APIs, adjusts download logic to require watermarkConfig for PDF watermarking, and updates the UI toggle to preserve and set watermarkConfig based on current state and initial config. Changes
Possibly related PRs
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
pages/api/links/[id]/index.ts (1)
277-297: Validation logic is correct but duplicated.This validation block is identical to the one in
pages/api/links/index.ts(lines 126-146). See the refactoring suggestion in that file's review to extract this into a shared helper function.
🧹 Nitpick comments (1)
pages/api/links/index.ts (1)
126-146: Consider extracting duplicated validation logic.The watermark validation logic is sound and provides clear error messages. However, this exact validation block is duplicated in
pages/api/links/[id]/index.ts(lines 277-297).Consider extracting this into a reusable helper function:
Create a new file
lib/validations/watermark.ts:import { WatermarkConfigSchema } from "@/lib/types"; export function validateWatermarkConfig( enableWatermark: boolean, watermarkConfig: any ): { valid: boolean; error?: string; details?: string } { if (!enableWatermark) { return { valid: true }; } if (!watermarkConfig) { return { valid: false, error: "Watermark configuration is required when watermark is enabled.", }; } const validation = WatermarkConfigSchema.safeParse(watermarkConfig); if (!validation.success) { return { valid: false, error: "Invalid watermark configuration.", details: validation.error.issues .map((issue) => issue.message) .join(", "), }; } return { valid: true }; }Then use it in both endpoints:
+import { validateWatermarkConfig } from "@/lib/validations/watermark"; - if (linkData.enableWatermark) { - if (!linkData.watermarkConfig) { - return res.status(400).json({ - error: - "Watermark configuration is required when watermark is enabled.", - }); - } - - // Validate the watermark config structure - const validation = WatermarkConfigSchema.safeParse( - linkData.watermarkConfig, - ); - if (!validation.success) { - return res.status(400).json({ - error: "Invalid watermark configuration.", - details: validation.error.issues - .map((issue) => issue.message) - .join(", "), - }); - } - } + const watermarkValidation = validateWatermarkConfig( + linkData.enableWatermark, + linkData.watermarkConfig + ); + if (!watermarkValidation.valid) { + return res.status(400).json({ + error: watermarkValidation.error, + ...(watermarkValidation.details && { + details: watermarkValidation.details, + }), + }); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
components/links/link-sheet/watermark-section.tsx(1 hunks)pages/api/links/[id]/index.ts(2 hunks)pages/api/links/download/dataroom-document.ts(1 hunks)pages/api/links/index.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pages/api/links/index.ts (1)
lib/types.ts (1)
WatermarkConfigSchema(334-360)
pages/api/links/[id]/index.ts (1)
lib/types.ts (1)
WatermarkConfigSchema(334-360)
🔇 Additional comments (4)
pages/api/links/download/dataroom-document.ts (1)
200-204: LGTM! Watermark gating now requires valid configuration.The added
view.link.watermarkConfigcheck ensures watermarking only occurs when a valid configuration is present, aligning with the validation logic added to the API endpoints. This prevents attempts to watermark PDFs without proper configuration.pages/api/links/index.ts (1)
9-9: LGTM! Appropriate import for watermark validation.The
WatermarkConfigSchemaimport enables runtime validation of watermark configuration.pages/api/links/[id]/index.ts (1)
11-11: LGTM! Appropriate import for watermark validation.The
WatermarkConfigSchemaimport enables runtime validation of watermark configuration in the PUT endpoint.components/links/link-sheet/watermark-section.tsx (1)
68-79: LGTM! Toggle logic correctly preserves watermark configuration.The updated toggle logic properly handles watermark state:
- When enabling: preserves existing
watermarkConfigif present, otherwise falls back toinitialconfig- When disabling: sets
watermarkConfigtonullThis ensures the frontend state aligns with the backend validation requirements, where
watermarkConfigmust be present whenenableWatermarkis true.
Summary by CodeRabbit