diff --git a/packages/core/src/notification/notification.test.ts b/packages/core/src/notification/notification.test.ts index ffe0ba0a..0f6e2e88 100644 --- a/packages/core/src/notification/notification.test.ts +++ b/packages/core/src/notification/notification.test.ts @@ -362,4 +362,70 @@ describe('NotificationService', () => { count = await notificationService.getUnreadCount(tm.id, u1.id) expect(count).toBe(0) }) + + it('toNotificationInfo maps video sprite and poster urls', async () => { + const tm = await prisma.team.create({ data: { name: 'Team 1' } }) + + const asset = await prisma.asset.create({ + data: { + name: 'test-video.mp4', + type: 'file', + mediaType: 'video/mp4', + status: 'processed', + media: { + duration: 10, + filesize: 1024, + fps: 24, + frames: 240, + videoPreview: { width: 640, height: 360 }, + videoTranscodes: [], + imageTranscodes: [], + sprite: { key: 'sprites/test-video.jpg', tileX: 10, tileY: 10, frames: 100 }, + poster: { key: 'posters/test-video.jpg' }, + thumbnail: { + key: 'thumbnails/test-video.jpg', + width: 120, + height: 90, + format: 'jpg', + quality: 80, + }, + metadata: { + originalWidth: 1280, + originalHeight: 720, + duration: 10, + bitRate: 1000, + frameRate: 24, + hasAudio: false, + format: {}, + }, + finishedAt: new Date().toISOString(), + mimeType: 'video/mp4', + original: null, + }, + }, + }) + + const n = await prisma.notification.create({ + data: { + teamId: tm.id, + type: NotificationType.comment_created, + assetId: asset.id, + }, + }) + + const svc = notificationService + const info = await svc['toNotificationInfo']( + await prisma.notification.findUniqueOrThrow({ + where: { id: n.id }, + include: { creator: true, team: true, project: true, asset: true, user: true }, + }), + null, + ) + + expect(info.asset?.preview).toBeDefined() + expect(info.asset?.thumbnailUrl).toBeDefined() + expect(info.asset?.thumbnailUrl).toContain('posters/test-video.jpg') + expect(info.asset?.originalWidth).toBe(1280) + expect(info.asset?.originalHeight).toBe(720) + }) }) diff --git a/packages/core/src/notification/notification.ts b/packages/core/src/notification/notification.ts index f2be2293..da257ca4 100644 --- a/packages/core/src/notification/notification.ts +++ b/packages/core/src/notification/notification.ts @@ -371,6 +371,9 @@ export class NotificationService { if (n.asset) { const a = n.asset let previewUrl = '' + let thumbnailUrl = '' + let originalWidth = 0 + let originalHeight = 0 const media = a.media as PrismaJson.MediaInfo | null @@ -379,8 +382,16 @@ export class NotificationService { try { if (media.sprite) { previewUrl = await s3Service.presign(bucket, media.sprite.key, 'GET') + if (media.poster) { + thumbnailUrl = await s3Service.presign(bucket, media.poster.key || '', 'GET') + } + if (media.metadata) { + originalWidth = media.metadata.originalWidth + originalHeight = media.metadata.originalHeight + } } else if (media.thumbnail) { previewUrl = await s3Service.presign(bucket, media.thumbnail.key || '', 'GET') + thumbnailUrl = previewUrl } } catch (e) { console.error('Failed to generate presigned url for notification asset preview:', e) @@ -392,6 +403,9 @@ export class NotificationService { name: a.name, mediaType: a.mediaType || undefined, preview: previewUrl || undefined, + thumbnailUrl: thumbnailUrl || undefined, + originalWidth: originalWidth || undefined, + originalHeight: originalHeight || undefined, } } diff --git a/packages/dtos/src/notification.ts b/packages/dtos/src/notification.ts index 34d32276..024c6646 100644 --- a/packages/dtos/src/notification.ts +++ b/packages/dtos/src/notification.ts @@ -21,6 +21,9 @@ export const assetPreviewSchema = z.object({ mediaType: z.string().optional(), name: z.string().optional(), preview: z.string().optional(), + thumbnailUrl: z.string().optional(), + originalWidth: z.number().optional(), + originalHeight: z.number().optional(), }) export type AssetPreview = z.infer diff --git a/packages/webui/components/file-browser/file-browser.tsx b/packages/webui/components/file-browser/file-browser.tsx index 41191a5b..515fa602 100644 --- a/packages/webui/components/file-browser/file-browser.tsx +++ b/packages/webui/components/file-browser/file-browser.tsx @@ -275,7 +275,7 @@ export function FileBrowser({ }, }) queryClient.invalidateQueries({ queryKey: ['search', teamId] }) - queryClient.invalidateQueries({ queryKey: ['folders', teamId] }) + queryClient.invalidateQueries({ queryKey: ['folders'] }) setMoveCopyMode(null) setItemsToMoveCopy([]) onClearSelection() @@ -305,7 +305,7 @@ export function FileBrowser({ }, }) queryClient.invalidateQueries({ queryKey: ['search', teamId] }) - queryClient.invalidateQueries({ queryKey: ['folders', teamId] }) + queryClient.invalidateQueries({ queryKey: ['folders'] }) setMoveCopyMode(null) setItemsToMoveCopy([]) onClearSelection() diff --git a/packages/webui/components/file-browser/use-file-actions.ts b/packages/webui/components/file-browser/use-file-actions.ts index 53d91261..dca44080 100644 --- a/packages/webui/components/file-browser/use-file-actions.ts +++ b/packages/webui/components/file-browser/use-file-actions.ts @@ -159,6 +159,9 @@ export function useFileActions({ queryClient.invalidateQueries({ queryKey: ['search', teamId, assetId], }) + queryClient.invalidateQueries({ + queryKey: ['folders'], + }) }, }, ) @@ -273,7 +276,7 @@ export function useFileActions({ queryKey: ['search', teamId], }) queryClient.invalidateQueries({ - queryKey: ['folders', teamId], + queryKey: ['folders'], }) if (data?.id) { setEditingItemId(data.id) @@ -293,7 +296,7 @@ export function useFileActions({ queryKey: ['search', teamId], }) queryClient.invalidateQueries({ - queryKey: ['folders', teamId], + queryKey: ['folders'], }) }, }, @@ -310,7 +313,7 @@ export function useFileActions({ queryKey: ['search', teamId], }) queryClient.invalidateQueries({ - queryKey: ['folders', teamId], + queryKey: ['folders'], }) }, }, diff --git a/packages/webui/components/folder-tree.tsx b/packages/webui/components/folder-tree.tsx index a2d5b77b..42e2e506 100644 --- a/packages/webui/components/folder-tree.tsx +++ b/packages/webui/components/folder-tree.tsx @@ -13,6 +13,7 @@ import { Button } from '@/ui/components/ui/button' import { Dialog, DialogContent, + DialogDescription, DialogFooter, DialogHeader, DialogTitle, @@ -22,6 +23,7 @@ import { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, + DropdownMenuSeparator, } from '@/ui/components/ui/dropdown-menu' import { Input } from '@/ui/components/ui/input' import { usePermissions } from '@/ui/hooks/use-permissions' @@ -31,12 +33,15 @@ import type { AssetInfo, AssetInfoPaginatedList, CollectionInfo, ShareLinkInfo } import { useInfiniteQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { useMatch, useNavigate, useParams } from '@tanstack/react-router' import { + AlertTriangle, Bookmark, ChevronDown, ChevronRight, ChevronsDownUp, ChevronsUpDown, Clapperboard, + Download, + Edit, Folder, LayoutGrid, Loader2, @@ -222,16 +227,129 @@ export function FolderTree({ from: '/projects/$projectId/shares/$shareId', shouldThrow: false, }) + const folderParams = useParams({ + from: '/projects/$projectId/folders/$folderId', + shouldThrow: false, + }) const [renameId, setRenameId] = useState(null) - const [renameType, setRenameType] = useState<'collection' | 'share'>('collection') + const [renameType, setRenameType] = useState<'collection' | 'share' | 'folder'>('collection') const [renameName, setRenameName] = useState('') const [isRenameOpen, setIsRenameOpen] = useState(false) const [deleteId, setDeleteId] = useState(null) - const [deleteType, setDeleteType] = useState<'collection' | 'share'>('collection') + const [deleteType, setDeleteType] = useState<'collection' | 'share' | 'folder'>('collection') const [isDeleteOpen, setIsDeleteOpen] = useState(false) + const { mutate: renameFolder } = useMutation({ + mutationFn: async ({ id, name }: { id: string; name: string }) => { + const res = await client.api.folders[':folderId'].$put({ + param: { folderId: id }, + json: { name }, + }) + if (!res.ok) throw new Error('Failed to rename folder') + return await res.json() + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['search', teamId] }) + queryClient.invalidateQueries({ queryKey: ['folders'] }) + toast.success('Folder renamed') + setIsRenameOpen(false) + }, + onError: (err) => { + toast.error(`Error: ${err.message}`) + }, + }) + + const { mutate: deleteFolder } = useMutation({ + mutationFn: async (id: string) => { + const res = await client.api.folders.$delete({ + json: { ids: [id] }, + }) + if (!res.ok) throw new Error('Failed to delete folder') + return id + }, + onSuccess: (deletedId) => { + queryClient.invalidateQueries({ queryKey: ['search', teamId] }) + queryClient.invalidateQueries({ queryKey: ['folders'] }) + toast.success('Folder deleted') + setIsDeleteOpen(false) + if (folderParams?.folderId === deletedId) { + navigate({ + to: '/projects/$projectId', + params: { projectId }, + }) + } + }, + onError: (err) => { + toast.error(`Error: ${err.message}`) + }, + }) + + const [isDownloadOpen, setIsDownloadOpen] = useState(false) + const [isLoadingLinks, setIsLoadingLinks] = useState(false) + const [resolvedFiles, setResolvedFiles] = useState< + Array<{ id: string; name: string; url: string }> + >([]) + + const handleDownloadFolder = async (folderId: string) => { + setIsDownloadOpen(true) + setIsLoadingLinks(true) + setResolvedFiles([]) + try { + const res = await client.api.files['download-links'].$post({ + json: { ids: [folderId] }, + }) + if (!res.ok) throw new Error('Failed to prepare download links') + const data = await res.json() + setResolvedFiles(data.files) + } catch (error) { + toast.error('Failed to prepare download links') + setIsDownloadOpen(false) + console.error(error) + } finally { + setIsLoadingLinks(false) + } + } + + const startDownload = () => { + const files = [...resolvedFiles] + setIsDownloadOpen(false) + + if (files.length === 0) return + + toast.info( + `Starting download of ${files.length} files. Please allow multiple downloads if prompted by your browser.`, + { + duration: 5000, + }, + ) + + const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) + + const runQueue = async () => { + const batchSize = 5 + for (let i = 0; i < files.length; i += batchSize) { + const chunk = files.slice(i, i + batchSize) + for (const file of chunk) { + const a = document.createElement('a') + a.href = file.url + a.download = file.name + a.target = '_blank' + document.body.appendChild(a) + a.click() + a.remove() + } + await delay(1000) + } + } + + runQueue().catch((err) => { + console.error('Background downloads failed:', err) + toast.error('Some downloads could not be started') + }) + } + const { mutate: renameCollection } = useMutation({ mutationFn: async ({ id, name }: { id: string; name: string }) => { const res = await client.api.collections[':collectionId'].$patch({ @@ -338,9 +456,6 @@ export function FolderTree({ )} -
{ + setRenameId(id) + setRenameType('folder') + setRenameName(currentName) + setIsRenameOpen(true) + }} + onDeleteTrigger={(id) => { + setDeleteId(id) + setDeleteType('folder') + setIsDeleteOpen(true) + }} + onDownloadTrigger={(id) => { + handleDownloadFolder(id) + }} /> {canEdit && ( @@ -619,7 +748,12 @@ export function FolderTree({ e.stopPropagation()}> - Rename {renameType === 'collection' ? 'Collection' : 'Share Link'} + Rename{' '} + {renameType === 'collection' + ? 'Collection' + : renameType === 'share' + ? 'Share Link' + : 'Folder'}
@@ -631,8 +765,10 @@ export function FolderTree({ if (e.key === 'Enter' && renameName.trim()) { if (renameType === 'collection') { renameCollection({ id: renameId!, name: renameName }) - } else { + } else if (renameType === 'share') { renameShareLink({ id: renameId!, name: renameName }) + } else if (renameType === 'folder') { + renameFolder({ id: renameId!, name: renameName }) } } }} @@ -647,8 +783,10 @@ export function FolderTree({ onClick={() => { if (renameType === 'collection') { renameCollection({ id: renameId!, name: renameName }) - } else { + } else if (renameType === 'share') { renameShareLink({ id: renameId!, name: renameName }) + } else if (renameType === 'folder') { + renameFolder({ id: renameId!, name: renameName }) } }} > @@ -663,12 +801,22 @@ export function FolderTree({ e.stopPropagation()}> - Delete {deleteType === 'collection' ? 'Collection' : 'Share Link'}? + Delete{' '} + {deleteType === 'collection' + ? 'Collection' + : deleteType === 'share' + ? 'Share Link' + : 'Folder'} + ? Are you sure you want to delete this{' '} - {deleteType === 'collection' ? 'collection' : 'share link'}? This action cannot be - undone. + {deleteType === 'collection' + ? 'collection' + : deleteType === 'share' + ? 'share link' + : 'folder'} + ? This action cannot be undone. @@ -678,8 +826,10 @@ export function FolderTree({ onClick={() => { if (deleteType === 'collection') { deleteCollection(deleteId!) - } else { + } else if (deleteType === 'share') { deleteShareLink(deleteId!) + } else if (deleteType === 'folder') { + deleteFolder(deleteId!) } }} > @@ -688,6 +838,69 @@ export function FolderTree({ + + {/* Folder Download Dialog */} + + + + {isLoadingLinks ? 'Preparing Download' : 'Confirm Download'} + + {isLoadingLinks + ? 'Resolving all files and folders. Please wait...' + : 'Selected folder files will be prepared for download.'} + + + + {isLoadingLinks ? ( +
+ + + Preparing download links... + +
+ ) : ( +
+
+ This download will include{' '} + {resolvedFiles.length}{' '} + file(s). +
+
+ +
+

No Folder Structure

+

+ Folder hierarchy will be flattened. All nested files will be downloaded directly + into your default download folder. +

+
+
+
+ )} + + + {!isLoadingLinks ? ( + <> + + + + ) : ( + + )} + +
+
) } @@ -795,6 +1008,9 @@ interface FolderTreeItemProps { onSelect?: (folder: AssetInfo) => void selectedFolderId?: string canEdit?: boolean + onRenameTrigger: (id: string, name: string) => void + onDeleteTrigger: (id: string) => void + onDownloadTrigger: (id: string) => void } function FolderTreeItem({ @@ -807,6 +1023,9 @@ function FolderTreeItem({ onSelect, selectedFolderId, canEdit, + onRenameTrigger, + onDeleteTrigger, + onDownloadTrigger, }: FolderTreeItemProps) { const [isExpanded, setIsExpanded] = useState(isRoot || false) const navigate = useNavigate() @@ -954,6 +1173,53 @@ function FolderTreeItem({ )} {folder.name} + + {canEdit && !isRoot && ( +
e.stopPropagation()} + > + + + + + + { + onRenameTrigger(folder.id!, folder.name) + }} + > + + Rename + + { + onDownloadTrigger(folder.id!) + }} + > + + Download + + + { + onDeleteTrigger(folder.id!) + }} + > + + Delete + + + +
+ )}
{isExpanded && ( @@ -977,6 +1243,9 @@ function FolderTreeItem({ onSelect={onSelect} selectedFolderId={selectedFolderId} canEdit={canEdit} + onRenameTrigger={onRenameTrigger} + onDeleteTrigger={onDeleteTrigger} + onDownloadTrigger={onDownloadTrigger} /> ))} {hasNextPage && ( diff --git a/packages/webui/components/notification-card.tsx b/packages/webui/components/notification-card.tsx index 019a41ac..27b70350 100644 --- a/packages/webui/components/notification-card.tsx +++ b/packages/webui/components/notification-card.tsx @@ -1,6 +1,7 @@ import type { NotificationInfo } from '@shumai/dtos' import { formatTimeAgo } from '@/ui/lib/time' import { cn } from '@/ui/lib/utils' +import { SpriteScrubber } from './sprite-scrubber' interface NotificationCardProps { notification: NotificationInfo @@ -76,6 +77,13 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => { } })() + const isVideoWithSprite = + asset?.mediaType?.startsWith('video/') && + asset.preview && + asset.thumbnailUrl && + asset.originalWidth && + asset.originalHeight + const hasPreview = asset?.preview && (asset.mediaType?.startsWith('image') || asset.mediaType?.startsWith('video')) @@ -98,7 +106,16 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => { {hasPreview && (
- {asset!.name} + {isVideoWithSprite ? ( + + ) : ( + {asset!.name} + )}
)} diff --git a/packages/webui/components/search/search-filter-dialog.tsx b/packages/webui/components/search/search-filter-dialog.tsx index b6a8518b..1f649159 100644 --- a/packages/webui/components/search/search-filter-dialog.tsx +++ b/packages/webui/components/search/search-filter-dialog.tsx @@ -222,9 +222,6 @@ export function SearchFilterDialog({ const handleClearFilters = () => { setConditions([]) - setSearchInput('') - setTriggerQuery('') - setIsSemantic(false) } const formatTimestamp = (seconds: number) => { @@ -351,7 +348,7 @@ export function SearchFilterDialog({ )} - {(activeFiltersCount > 0 || searchInput) && ( + {activeFiltersCount > 0 && (