Add adjustment preset node type validation and enhance render data normalization
- Introduced `adjustmentPresetNodeTypeValidator` for validating new adjustment preset node types. - Added new constants for render output resolutions and formats, including custom dimension constraints. - Implemented normalization functions for render data, ensuring proper validation and error handling. - Updated node creation and update mutations to utilize normalized data for improved consistency.
This commit is contained in:
72
convex/presets.ts
Normal file
72
convex/presets.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { mutation, query } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
|
||||
import { requireAuth } from "./helpers";
|
||||
import { adjustmentPresetNodeTypeValidator } from "./node-type-validator";
|
||||
|
||||
export const list = query({
|
||||
args: {
|
||||
nodeType: v.optional(adjustmentPresetNodeTypeValidator),
|
||||
},
|
||||
handler: async (ctx, { nodeType }) => {
|
||||
const user = await requireAuth(ctx);
|
||||
|
||||
if (nodeType) {
|
||||
return await ctx.db
|
||||
.query("adjustmentPresets")
|
||||
.withIndex("by_userId_nodeType", (q) =>
|
||||
q.eq("userId", user.userId).eq("nodeType", nodeType),
|
||||
)
|
||||
.order("desc")
|
||||
.collect();
|
||||
}
|
||||
|
||||
return await ctx.db
|
||||
.query("adjustmentPresets")
|
||||
.withIndex("by_userId", (q) => q.eq("userId", user.userId))
|
||||
.order("desc")
|
||||
.collect();
|
||||
},
|
||||
});
|
||||
|
||||
export const save = mutation({
|
||||
args: {
|
||||
name: v.string(),
|
||||
nodeType: adjustmentPresetNodeTypeValidator,
|
||||
params: v.any(),
|
||||
},
|
||||
handler: async (ctx, { name, nodeType, params }) => {
|
||||
const user = await requireAuth(ctx);
|
||||
const normalizedName = name.trim();
|
||||
if (!normalizedName) {
|
||||
throw new Error("Preset name cannot be empty.");
|
||||
}
|
||||
|
||||
return await ctx.db.insert("adjustmentPresets", {
|
||||
userId: user.userId,
|
||||
name: normalizedName,
|
||||
nodeType,
|
||||
params,
|
||||
createdAt: Date.now(),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const remove = mutation({
|
||||
args: {
|
||||
presetId: v.id("adjustmentPresets"),
|
||||
},
|
||||
handler: async (ctx, { presetId }) => {
|
||||
const user = await requireAuth(ctx);
|
||||
const preset = await ctx.db.get(presetId);
|
||||
if (!preset) {
|
||||
return false;
|
||||
}
|
||||
if (preset.userId !== user.userId) {
|
||||
throw new Error("Forbidden");
|
||||
}
|
||||
|
||||
await ctx.db.delete(presetId);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user