🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: add videoGeneration pricing unit and clean up all asset files on deletion
YuTengjing57772d1f3b4e
diff --git a/packages/database/src/models/generationBatch.ts b/packages/database/src/models/generationBatch.tsindex 4e0d9ebde28..02c39a928f7 100644--- a/packages/database/src/models/generationBatch.ts+++ b/packages/database/src/models/generationBatch.ts@@ -1,8 +1,8 @@import type {Generation,- GenerationAsset,GenerationBatch,GenerationConfig,+ VideoGenerationAsset,} from '@lobechat/types';import debug from 'debug';import { and, eq } from 'drizzle-orm';@@ -169,16 +169,16 @@ export class GenerationBatchModel {* Delete a generation batch and return associated file URLs for cleanup** This method follows the "database first, files second" deletion principle:- * 1. First queries the batch with its generations to collect thumbnail URLs+ * 1. First queries the batch with its generations to collect asset file URLs* 2. Then deletes the database record (cascade delete handles related generations)- * 3. Returns the deleted batch data and thumbnail URLs for file cleanup+ * 3. Returns the deleted batch data and file URLs for cleanup** @param id - The batch ID to delete- * @returns Object containing deleted batch data and thumbnail URLs to clean, or undefined if batch not found or access denied+ * @returns Object containing deleted batch data and file URLs to clean, or undefined if batch not found or access denied*/async delete(id: string,- ): Promise<{ deletedBatch: GenerationBatchItem; thumbnailUrls: string[] } | undefined> {+ ): Promise<{ deletedBatch: GenerationBatchItem; filesToDelete: string[] } | undefined> {log('Deleting generation batch: %s for user: %s', id, this.userId);// 1. First, get generations with their assets to collect thumbnail URLs@@ -198,14 +198,14 @@ export class GenerationBatchModel {return undefined;}- // 2. Collect thumbnail URLs that need to be deleted- const thumbnailUrls: string[] = [];+ // 2. Collect asset file URLs that need to be deleted (video, cover, thumbnail)+ const filesToDelete: string[] = [];if (batchWithGenerations.generations) {for (const gen of batchWithGenerations.generations) {- const asset = gen.asset as GenerationAsset;- if (asset?.thumbnailUrl) {- thumbnailUrls.push(asset.thumbnailUrl);- }+ const asset = gen.asset as VideoGenerationAsset;+ if (asset?.url) filesToDelete.push(asset.url);+ if (asset?.thumbnailUrl) filesToDelete.push(asset.thumbnailUrl);+ if (asset?.coverUrl) filesToDelete.push(asset.coverUrl);}}@@ -216,14 +216,14 @@ export class GenerationBatchModel {.returning();log(- 'Generation batch %s deleted successfully with %d thumbnails to clean',+ 'Generation batch %s deleted successfully with %d files to clean',id,- thumbnailUrls.length,+ filesToDelete.length,);return {deletedBatch,- thumbnailUrls,+ filesToDelete,};}}diff --git a/packages/database/src/models/generationTopic.ts b/packages/database/src/models/generationTopic.tsindex bf3aa24ace4..37ec1015654 100644--- a/packages/database/src/models/generationTopic.ts+++ b/packages/database/src/models/generationTopic.ts@@ -1,4 +1,4 @@-import type { GenerationAsset, ImageGenerationTopic } from '@lobechat/types';+import type { ImageGenerationTopic, VideoGenerationAsset } from '@lobechat/types';import { and, desc, eq } from 'drizzle-orm';import { FileService } from '@/server/services/file';@@ -112,14 +112,14 @@ export class GenerationTopicModel {filesToDelete.push(topicWithBatches.coverUrl);}- // Add thumbnail URLs from all generations+ // Add asset file URLs from all generations (video, cover, thumbnail)if (topicWithBatches.batches) {for (const batch of topicWithBatches.batches) {for (const gen of batch.generations) {- const asset = gen.asset as GenerationAsset;- if (asset?.thumbnailUrl) {- filesToDelete.push(asset.thumbnailUrl);- }+ const asset = gen.asset as VideoGenerationAsset;+ if (asset?.url) filesToDelete.push(asset.url);+ if (asset?.thumbnailUrl) filesToDelete.push(asset.thumbnailUrl);+ if (asset?.coverUrl) filesToDelete.push(asset.coverUrl);}}}diff --git a/src/features/ModelSwitchPanel/components/ModelDetailPanel.tsx b/src/features/ModelSwitchPanel/components/ModelDetailPanel.tsxindex 9c194e7bef5..b688960e8b5 100644--- a/src/features/ModelSwitchPanel/components/ModelDetailPanel.tsx+++ b/src/features/ModelSwitchPanel/components/ModelDetailPanel.tsx@@ -79,7 +79,7 @@ const getPrice = (pricing: Pricing) => {// --- Pricing detail helpers ----type PricingGroup = 'audio' | 'image' | 'text';+type PricingGroup = 'audio' | 'image' | 'text' | 'video';const UNIT_GROUP_MAP: Record<PricingUnitName, PricingGroup> = {audioInput: 'audio',@@ -93,9 +93,10 @@ const UNIT_GROUP_MAP: Record<PricingUnitName, PricingGroup> = {textInput_cacheRead: 'text',textInput_cacheWrite: 'text',textOutput: 'text',+ videoGeneration: 'video',};-const GROUP_ORDER: PricingGroup[] = ['text', 'image', 'audio'];+const GROUP_ORDER: PricingGroup[] = ['text', 'image', 'audio', 'video'];const UNIT_ICON_MAP: Partial<Record<PricingUnitName, LucideIcon>> = {audioInput: ArrowUpFromDot,@@ -123,6 +124,7 @@ const UNIT_SORT_ORDER: Record<PricingUnitName, number> = {audioInput: 0,audioOutput: 1,audioInput_cacheRead: 2,+ videoGeneration: 0,};const UNIT_LABEL_MAP: Record<string, string> = {diff --git a/src/server/routers/lambda/__tests__/generationTopic.test.ts b/src/server/routers/lambda/__tests__/generationTopic.test.tsindex 26f64d1a819..21f9277d719 100644--- a/src/server/routers/lambda/__tests__/generationTopic.test.ts+++ b/src/server/routers/lambda/__tests__/generationTopic.test.ts@@ -45,7 +45,7 @@ describe('generationTopicRouter', () => {const result = await caller.createTopic();expect(result).toBe(mockTopicId);- expect(mockCreate).toHaveBeenCalledWith('');+ expect(mockCreate).toHaveBeenCalledWith('', undefined);});it('should get all generation topics', async () => {diff --git a/src/server/routers/lambda/generationBatch.ts b/src/server/routers/lambda/generationBatch.tsindex 74b37009f6b..2c3f3b53601 100644--- a/src/server/routers/lambda/generationBatch.ts+++ b/src/server/routers/lambda/generationBatch.ts@@ -28,18 +28,18 @@ export const generationBatchRouter = router({return;}- const { deletedBatch, thumbnailUrls } = result;+ const { deletedBatch, filesToDelete } = result;- // 2. Clean up thumbnail files from S3+ // 2. Clean up asset files from S3 (videos, covers, thumbnails)// Note: Even if file deletion fails, we consider the batch deletion successful// since the database record has been removed and users won't see the batch anymore- if (thumbnailUrls.length > 0) {+ if (filesToDelete.length > 0) {try {- await ctx.fileService.deleteFiles(thumbnailUrls);+ await ctx.fileService.deleteFiles(filesToDelete);} catch (error) {// Log the error but don't throw - file cleanup failure shouldn't affect// the user experience since the database operation succeeded- console.error('Failed to delete thumbnail files from S3:', error);+ console.error('Failed to delete files from S3:', error);}}