feat: enhance dashboard and canvas components with credit management features
- Integrated CreditOverview and RecentTransactions components into the dashboard for better credit visibility. - Updated canvas toolbar to display current credit balance using CreditDisplay. - Improved AI image and prompt nodes to show credit costs and handle credit availability checks during image generation. - Added new queries for fetching recent transactions and monthly usage statistics to support dashboard features. - Refactored existing code to streamline credit-related functionalities across components.
This commit is contained in:
10
convex/ai.ts
10
convex/ai.ts
@@ -17,6 +17,7 @@ export const generateImage = action({
|
||||
aspectRatio: v.optional(v.string()),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
// Auth: über requireAuth in runMutation — kein verschachteltes getCurrentUser (ConvexError → generische Client-Fehler).
|
||||
const internalCreditsEnabled =
|
||||
process.env.INTERNAL_CREDITS_ENABLED === "true";
|
||||
|
||||
@@ -31,13 +32,9 @@ export const generateImage = action({
|
||||
throw new Error(`Unknown model: ${modelId}`);
|
||||
}
|
||||
|
||||
if (!(await ctx.runQuery(api.auth.getCurrentUser, {}))) {
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
const reservationId = internalCreditsEnabled
|
||||
? await ctx.runMutation(api.credits.reserve, {
|
||||
estimatedCost: modelConfig.estimatedCostPerImage,
|
||||
estimatedCost: modelConfig.creditCost,
|
||||
description: `Bildgenerierung — ${modelConfig.name}`,
|
||||
model: modelId,
|
||||
nodeId: args.nodeId,
|
||||
@@ -76,7 +73,7 @@ export const generateImage = action({
|
||||
const existing = await ctx.runQuery(api.nodes.get, { nodeId: args.nodeId });
|
||||
if (!existing) throw new Error("Node not found");
|
||||
const prev = (existing.data ?? {}) as Record<string, unknown>;
|
||||
const creditCost = modelConfig.estimatedCostPerImage;
|
||||
const creditCost = modelConfig.creditCost;
|
||||
|
||||
const aspectRatio =
|
||||
args.aspectRatio?.trim() ||
|
||||
@@ -89,6 +86,7 @@ export const generateImage = action({
|
||||
storageId,
|
||||
prompt: args.prompt,
|
||||
model: modelId,
|
||||
modelLabel: modelConfig.name,
|
||||
modelTier: modelConfig.tier,
|
||||
generatedAt: Date.now(),
|
||||
creditCost,
|
||||
|
||||
Reference in New Issue
Block a user