Files
lemonspace_app/convex/presets.ts
Matthias f3c5c2d8f1 Enhance canvas functionality with new node types and validation
- Added support for new canvas node types: curves, color-adjust, light-adjust, detail-adjust, and render.
- Implemented validation for adjustment nodes to restrict incoming edges to one.
- Updated canvas connection validation to improve user feedback on invalid connections.
- Enhanced node creation and rendering logic to accommodate new node types and their properties.
- Refactored related components and utilities for better maintainability and performance.
2026-04-02 11:39:05 +02:00

73 lines
1.7 KiB
TypeScript

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;
},
});