Files
shumai/packages/webui/components/top-nav.tsx
T
yiling b7367bb129 refactor(storage): use original filenames and fix download UX
- Store uploaded files as files/{ulid}/{original-name} instead of files/{ulid}/raw
- Store transcoded videos as {stem}-{resolution}.mp4 (e.g. foo-720p.mp4)
- Store transcoded images as {stem}-{width}p.webp (e.g. foo-1920p.webp)
- Add download?: boolean param to presign - only sets Content-Disposition: attachment when true
- Local storage handler only sets Content-Disposition when ?download=1 query param is present
- Add POST /api/files/download-url endpoint for key-based single file downloads
  - Uses ResourceType.Asset for permission check
  - Validates key belongs to the asset's storage directory
- Fix existing download-links API to pass download: true to presign
- Fix breadcrumb navbar download: video shows resolution submenu, others download directly
- Fix video player download: calls download-url API, shows correct file type label
- Remove filename query param hack from presign URLs
- Add sanitizeFilename() and stemFromKey() utility helpers
- Add key field to VideoTranscode DTO interface
2026-07-02 17:39:23 +08:00

105 lines
3.3 KiB
TypeScript

import { useTopNavStore } from '@/ui/stores/top-nav'
import { BreadcrumbNav } from './breadcrumb-nav'
import { ShumaiLogo } from '@/ui/components/ui/icons'
import { useUiStore } from '@/ui/stores/ui'
export function TopNav() {
const { projectState } = useTopNavStore()
const uiStore = useUiStore()
if (!projectState) {
return <TeamHeader />
}
const {
teamId,
projectId,
projectName,
ancestorFolders,
currentAsset,
isRootFolder,
fileId,
downloadInfo,
versions,
isPublic,
shareId,
onFolderClick,
} = projectState
const isFileView = !!fileId
const isShareConfig = !!shareId && !isFileView
const isLeftSidebarCollapsed = isFileView
? uiStore.fileViewLeftSidebarCollapsed
: isShareConfig
? uiStore.shareConfigLeftSidebarCollapsed
: uiStore.fileListLeftSidebarCollapsed
const onLeftSidebarToggle = isPublic
? undefined
: () =>
isFileView
? uiStore.setFileViewLeftSidebarCollapsed(!uiStore.fileViewLeftSidebarCollapsed)
: isShareConfig
? uiStore.setShareConfigLeftSidebarCollapsed(!uiStore.shareConfigLeftSidebarCollapsed)
: uiStore.setFileListLeftSidebarCollapsed(!uiStore.fileListLeftSidebarCollapsed)
const isRightSidebarCollapsed =
isPublic && projectState.isRightSidebarCollapsed !== undefined
? projectState.isRightSidebarCollapsed
: isFileView
? uiStore.fileViewRightSidebarCollapsed
: isShareConfig
? uiStore.shareConfigRightSidebarCollapsed
: uiStore.fileListRightSidebarCollapsed
const onRightSidebarToggle =
isPublic && projectState.onRightSidebarToggle
? projectState.onRightSidebarToggle
: () =>
isFileView
? uiStore.setFileViewRightSidebarCollapsed(!uiStore.fileViewRightSidebarCollapsed)
: isShareConfig
? uiStore.setShareConfigRightSidebarCollapsed(
!uiStore.shareConfigRightSidebarCollapsed,
)
: uiStore.setFileListRightSidebarCollapsed(!uiStore.fileListRightSidebarCollapsed)
const displayStyle = projectId ? (uiStore.viewModes[projectId] ?? 'card') : 'card'
const onDisplayStyleChange = isPublic
? undefined
: (style: 'card' | 'list') => {
if (projectId) uiStore.setViewMode(projectId, style)
}
return (
<BreadcrumbNav
teamId={teamId}
projectId={projectId}
projectName={projectName}
ancestorFolders={ancestorFolders}
currentAsset={currentAsset}
isRootFolder={isRootFolder}
displayStyle={isFileView || isShareConfig ? undefined : displayStyle}
onDisplayStyleChange={isFileView || isShareConfig ? undefined : onDisplayStyleChange}
isLeftSidebarCollapsed={isLeftSidebarCollapsed}
onLeftSidebarToggle={onLeftSidebarToggle}
isRightSidebarCollapsed={isRightSidebarCollapsed}
onRightSidebarToggle={onRightSidebarToggle}
isPublic={isPublic}
shareId={shareId}
fileId={fileId}
downloadInfo={downloadInfo}
versions={versions}
onFolderClick={onFolderClick}
/>
)
}
function TeamHeader() {
return (
<div className="flex h-14 flex-wrap items-center justify-center gap-2 border-b border-border bg-card px-4 py-2 flex-shrink-0">
<ShumaiLogo className="w-10 h-10 text-orange-600" />
</div>
)
}