feat(share): add allow download config to share links (#275)

* feat(share): add allow download config to share links

* fix(share): hide download in public share list page when disabled
This commit is contained in:
Yiling-J
2026-08-08 10:25:02 +08:00
committed by GitHub
parent 70b6c33204
commit d3f5892dd2
39 changed files with 572 additions and 208 deletions
+58 -55
View File
@@ -63,6 +63,7 @@ interface BreadcrumbNavProps {
onChatbotToggle?: () => void
isPublic?: boolean
shareId?: string
allowDownload?: boolean
onFolderClick?: (folderId: string) => void
fileId?: string
downloadInfo?: {
@@ -104,6 +105,7 @@ export function BreadcrumbNav({
onFolderClick,
fileId,
shareId,
allowDownload = true,
downloadInfo,
versions,
compareMode = false,
@@ -232,61 +234,62 @@ export function BreadcrumbNav({
<ChevronDown className="h-4 w-4" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
{hasVideoTranscodes ? (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2">
<span>{m.download()}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent className="w-48">
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{downloadInfo?.videoTranscodes?.map((t) => {
const longSide = Math.max(t.width, t.height)
let resolution = `${t.height}p`
if (longSide >= 3840) resolution = '2160p'
else if (longSide >= 1920) resolution = '1080p'
else if (longSide >= 1280) resolution = '720p'
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
return (
<DropdownMenuItem
key={resolution}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{downloadInfo?.originalKey && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(downloadInfo.originalKey!)}
className="flex items-center justify-between"
>
<span>Original</span>
<span className="text-xs text-muted-foreground">
{currentAsset.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
) : (
<DropdownMenuItem
onClick={() =>
downloadInfo?.originalKey && handleDownload(downloadInfo.originalKey)
}
disabled={!downloadInfo?.originalKey}
>
{m.download()}
</DropdownMenuItem>
)}
{allowDownload &&
(hasVideoTranscodes ? (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2">
<span>{m.download()}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent className="w-48">
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{downloadInfo?.videoTranscodes?.map((t) => {
const longSide = Math.max(t.width, t.height)
let resolution = `${t.height}p`
if (longSide >= 3840) resolution = '2160p'
else if (longSide >= 1920) resolution = '1080p'
else if (longSide >= 1280) resolution = '720p'
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
return (
<DropdownMenuItem
key={resolution}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{downloadInfo?.originalKey && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(downloadInfo.originalKey!)}
className="flex items-center justify-between"
>
<span>Original</span>
<span className="text-xs text-muted-foreground">
{currentAsset.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
) : (
<DropdownMenuItem
onClick={() =>
downloadInfo?.originalKey && handleDownload(downloadInfo.originalKey)
}
disabled={!downloadInfo?.originalKey}
>
{m.download()}
</DropdownMenuItem>
))}
{canEdit && (
<DropdownMenuItem onClick={() => console.log('Rename')}>
Rename
@@ -25,6 +25,8 @@ interface CompareControlBarProps {
onFit: () => void
onDownload: (key?: string) => void
onToggleFullScreen: () => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export function CompareControlBar({
@@ -44,6 +46,7 @@ export function CompareControlBar({
onFit,
onDownload,
onToggleFullScreen,
allowDownload = true,
}: CompareControlBarProps) {
// Active side is a video: reuse the shared VideoControlBar.
if (activeState?.kind === 'video' && activeState.video && activeAsset) {
@@ -94,6 +97,7 @@ export function CompareControlBar({
totalFrames={v.totalFrames}
currentFrame={v.currentFrame}
seekToFrame={onSeek}
allowDownload={allowDownload}
/>
)
}
@@ -109,6 +113,7 @@ export function CompareControlBar({
onDownload={() => onDownload()}
canDownload={!!activeAsset?.media?.original?.key}
fullscreen={{ isFullScreen, onToggle: onToggleFullScreen }}
allowDownload={allowDownload}
/>
)
}
@@ -33,6 +33,8 @@ interface CompareViewerProps {
onActiveAssetChange: (asset: AssetInfo | null) => void
onPlay?: () => void
onTimeUpdate?: (second: number) => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
function useCompareAsset(id: string, isPublic: boolean, shareId?: string) {
@@ -73,6 +75,7 @@ export function CompareViewer({
onActiveAssetChange,
onPlay,
onTimeUpdate,
allowDownload = true,
}: CompareViewerProps) {
const rootRef = useRef<HTMLDivElement>(null)
const leftRef = useRef<ComparePaneHandle | null>(null)
@@ -378,6 +381,7 @@ export function CompareViewer({
onFit={handleFit}
onDownload={handleDownload}
onToggleFullScreen={handleToggleFullScreen}
allowDownload={allowDownload}
/>
</div>
)
@@ -92,6 +92,8 @@ interface FileBrowserProps {
onUpdateCollection?: (updates: { name?: string; filter?: any }) => void
rootFolderId?: string
shareId?: string
/** When false, hides download affordances (used by public share views). Defaults to true. */
allowDownload?: boolean
}
type FileWithId = {
@@ -138,6 +140,7 @@ export function FileBrowser({
onUpdateCollection,
rootFolderId,
shareId,
allowDownload = true,
}: FileBrowserProps) {
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
const [moveCopyMode, setMoveCopyMode] = useState<'move' | 'copy' | null>(null)
@@ -680,6 +683,7 @@ export function FileBrowser({
isRecentlyDeleted,
selectedCount: selectedIds.size,
isShareView,
allowDownload,
fields: displayedFields,
canEdit,
isExternalDragging,
@@ -1136,19 +1140,21 @@ export function FileBrowser({
</span>
)}
</div>
<Button
variant="ghost"
size="sm"
onClick={() =>
handleDownload(
[...folders, ...displayedFiles].filter((i) => selectedIds.has(i.id!)),
)
}
className="gap-2"
>
<Download className="h-4 w-4" />
Download
</Button>
{allowDownload && (
<Button
variant="ghost"
size="sm"
onClick={() =>
handleDownload(
[...folders, ...displayedFiles].filter((i) => selectedIds.has(i.id!)),
)
}
className="gap-2"
>
<Download className="h-4 w-4" />
Download
</Button>
)}
</div>
)}
{isExternalDragging && !externalOverFolderId && (
@@ -55,6 +55,8 @@ interface FileCardProps {
fields: MetadataFieldInfo[]
isShareView?: boolean
canEdit?: boolean
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
}
export function FileCard({
@@ -81,6 +83,7 @@ export function FileCard({
fields,
isShareView,
canEdit = true,
allowDownload = true,
}: FileCardProps) {
const [name, setName] = useState(item.name)
const inputRef = useRef<HTMLInputElement>(null)
@@ -314,15 +317,17 @@ export function FileCard({
<DropdownMenuContent align="end">
{isShareView ? (
<>
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<DropdownMenuItem
onClick={(e) => {
@@ -359,15 +364,17 @@ export function FileCard({
<span>{m.rename()}</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<>
<DropdownMenuSeparator />
@@ -45,6 +45,8 @@ interface FolderCardProps {
setExternalOverFolderId?: (id: string | null) => void
resetExternalDragState?: () => void
onExternalDrop?: (files: File[], folderId: string) => void
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
}
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
@@ -126,6 +128,7 @@ export function FolderCard({
setExternalOverFolderId,
resetExternalDragState,
onExternalDrop,
allowDownload = true,
}: FolderCardProps) {
const [name, setName] = useState(item.name || '')
const inputRef = useRef<HTMLInputElement>(null)
@@ -361,15 +364,17 @@ export function FolderCard({
<DropdownMenuContent align="end">
{isShareView ? (
<>
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<DropdownMenuItem
onClick={(e) => {
@@ -406,15 +411,17 @@ export function FolderCard({
<span>{m.rename()}</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<>
<DropdownMenuSeparator />
@@ -15,6 +15,7 @@ export function FileViewer({
annotations,
startTime,
shareId,
allowDownload,
children,
}: OuterFileViewerProps) {
const viewerDef = getViewerForFile(file)
@@ -31,6 +32,7 @@ export function FileViewer({
annotations={annotations}
startTime={startTime}
shareId={shareId}
allowDownload={allowDownload}
>
{children}
</ViewerComponent>
@@ -42,6 +42,7 @@ interface PublicShareInfo {
isDisabled: boolean
isExpired: boolean
hasPassword: boolean
allowDownload: boolean
rootFolderId: string
projectId: string
viewMode?: string | null
@@ -418,6 +419,7 @@ export function PublicShareManager({
isPublic: true,
shareId,
fileId: viewingFileId || undefined,
allowDownload: shareInfo.allowDownload,
downloadInfo: viewingFileData
? {
originalKey: viewingFileData.media?.original?.key,
@@ -561,6 +563,7 @@ export function PublicShareManager({
activeSide={compareActiveSide}
annotations={annotations}
seekRequest={seekRequest}
allowDownload={shareInfo.allowDownload}
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
onSwitchVersion={(side, versionId) =>
updateCompareSearch(
@@ -582,6 +585,7 @@ export function PublicShareManager({
annotations={annotations}
startTime={startTime}
shareId={shareId}
allowDownload={shareInfo.allowDownload}
/>
)
)}
@@ -619,6 +623,7 @@ export function PublicShareManager({
isShareView={true}
isPublic={true}
shareId={shareId}
allowDownload={shareInfo.allowDownload}
/>
)
)}
@@ -4,34 +4,34 @@ import { Button } from '@/ui/components/ui/button'
import { Input } from '@/ui/components/ui/input'
import { Label } from '@/ui/components/ui/label'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/ui/components/ui/select'
import { Switch } from '@/ui/components/ui/switch'
import { WatermarkEditorDialog } from '@/ui/components/watermark-editor-dialog'
import { copyToClipboard as copyTextToClipboard } from '@/ui/lib/clipboard'
import { m } from '@/ui/paraglide/messages.js'
import {
ShareLinkInfo,
UpdateShareLinkRequest,
type FieldInfo as MetadataFieldInfo,
ShareLinkInfo,
UpdateShareLinkRequest,
type FieldInfo as MetadataFieldInfo,
} from '@shumai/dtos'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
ArrowDownUp,
ChevronRight,
Copy,
ExternalLink,
LayoutGrid,
List,
ListFilter,
Loader2,
Palette,
Shield,
SortAsc,
ArrowDownUp,
ChevronRight,
Copy,
ExternalLink,
LayoutGrid,
List,
ListFilter,
Loader2,
Palette,
Shield,
SortAsc,
} from 'lucide-react'
import React, { useState } from 'react'
import { toast } from 'sonner'
@@ -186,7 +186,7 @@ export function ShareSettingsSidebar({
<div className="space-y-1">
<SidebarAccordionItem title={m.security()} icon={<Shield className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0">
<div className="p-3 space-y-4 pt-2">
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.password()}</Label>
@@ -241,6 +241,17 @@ export function ShareSettingsSidebar({
)}
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.allow_download()}</Label>
<Switch
checked={shareLink.allowDownload}
onCheckedChange={(checked) => updateShare({ allowDownload: checked })}
/>
</div>
<p className="text-xs text-muted-foreground">{m.allow_download_description()}</p>
</div>
<div className="space-y-2 pt-2 border-t border-border/50">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.watermark()}</Label>
@@ -278,7 +289,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.appearance()} icon={<Palette className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0 flex gap-2">
<div className="p-3 space-y-3 pt-2 flex gap-2">
<Button
variant={viewMode === 'card' ? 'secondary' : 'outline'}
size="sm"
@@ -300,7 +311,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.fields()} icon={<ListFilter className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0">
<div className="p-3 space-y-3 pt-2">
{(fields as MetadataFieldInfo[])?.map((field) => (
<div key={field.id} className="flex items-center justify-between">
<Label className="text-xs">{field.config?.name}</Label>
@@ -313,7 +324,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.sort_by()} icon={<SortAsc className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0">
<div className="p-3 space-y-4 pt-2">
<div className="space-y-2">
<Label className="text-xs text-muted-foreground">{m.field()}</Label>
<Select
+2
View File
@@ -25,6 +25,7 @@ export function TopNav() {
versions,
isPublic,
shareId,
allowDownload,
onFolderClick,
compareMode,
canCompareVersions,
@@ -112,6 +113,7 @@ export function TopNav() {
onChatbotToggle={onChatbotToggle}
isPublic={isPublic}
shareId={shareId}
allowDownload={allowDownload}
fileId={fileId}
downloadInfo={downloadInfo}
versions={versions}
@@ -4,7 +4,7 @@ import React, { useImperativeHandle } from 'react'
import { FileViewerProps, MediaController } from '../types'
export const DefaultViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, shareId, children }, ref) => {
({ file, shareId, children, allowDownload = true }, ref) => {
// Implement no-op media controller
useImperativeHandle(ref, () => ({
play: () => {},
@@ -46,15 +46,17 @@ export const DefaultViewer = React.forwardRef<MediaController, FileViewerProps>(
</div>
</div>
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
<button
onClick={handleDownload}
disabled={!file.media?.original?.key}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title="Download original file"
>
<Download size={14} />
Download
</button>
{allowDownload && (
<button
onClick={handleDownload}
disabled={!file.media?.original?.key}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title="Download original file"
>
<Download size={14} />
Download
</button>
)}
</div>
</div>
)
@@ -11,6 +11,8 @@ export interface ImageControlBarProps {
onCopy?: () => void
copied?: boolean
canCopy?: boolean
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
/** When provided, renders a fullscreen toggle (used by compare mode). */
fullscreen?: { isFullScreen: boolean; onToggle: () => void }
}
@@ -25,6 +27,7 @@ export function ImageControlBar({
onCopy,
copied = false,
canCopy = true,
allowDownload = true,
fullscreen,
}: ImageControlBarProps) {
return (
@@ -65,15 +68,17 @@ export function ImageControlBar({
{copied ? m.copied() : m.copy()}
</button>
)}
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title={m.download_original_image()}
>
<Download size={14} />
{m.download()}
</button>
{allowDownload && (
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title={m.download_original_image()}
>
<Download size={14} />
{m.download()}
</button>
)}
{fullscreen && (
<button
onClick={fullscreen.onToggle}
@@ -8,7 +8,7 @@ import { useAnnotationStore } from '@/ui/stores/annotation-store'
import { FileViewerProps, MediaController } from '../types'
export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, annotations, shareId, children }, ref) => {
({ file, annotations, shareId, children, allowDownload }, ref) => {
// Implement no-op media controller since images are static
useImperativeHandle(ref, () => ({
play: () => {},
@@ -215,6 +215,7 @@ export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
onCopy={handleCopy}
copied={copied}
canCopy={!!bestUrl}
allowDownload={allowDownload}
/>
</div>
)
@@ -11,6 +11,8 @@ export interface PdfControlBarProps {
onFit: () => void
onDownload: () => void
canDownload: boolean
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export function PdfControlBar({
@@ -23,6 +25,7 @@ export function PdfControlBar({
onFit,
onDownload,
canDownload,
allowDownload = true,
}: PdfControlBarProps) {
return (
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-between gap-2 transition-colors duration-200">
@@ -76,15 +79,17 @@ export function PdfControlBar({
>
{m.fit()}
</button>
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50"
title={m.download_original_file()}
>
<Download size={14} />
{m.download()}
</button>
{allowDownload && (
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50"
title={m.download_original_file()}
>
<Download size={14} />
{m.download()}
</button>
)}
</div>
</div>
)
@@ -19,7 +19,20 @@ if (typeof window !== 'undefined' && pdfjsLib.GlobalWorkerOptions) {
}
export const PdfViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, annotations, shareId, children, onPlay, onPause, onTimeUpdate, startTime }, ref) => {
(
{
file,
annotations,
shareId,
children,
onPlay,
onPause,
onTimeUpdate,
startTime,
allowDownload,
},
ref,
) => {
const {
isDrawing,
currentTool,
@@ -347,6 +360,7 @@ export const PdfViewer = React.forwardRef<MediaController, FileViewerProps>(
onFit={handleFit}
onDownload={handleDownload}
canDownload={!!file.media?.original?.key}
allowDownload={allowDownload}
/>
</div>
)
@@ -19,6 +19,8 @@ export interface FileViewerProps {
onTimeUpdate?: (time: number) => void
startTime?: number
shareId?: string
/** When false, the viewer hides its download affordances. Defaults to true. */
allowDownload?: boolean
children?: React.ReactNode
}
@@ -78,6 +78,8 @@ export interface ControlBarProps {
/** Fired when the cursor enters/leaves the bar (used to pin it visible). */
onMouseEnter?: () => void
onMouseLeave?: () => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export const VideoControlBar: React.FC<ControlBarProps> = ({
@@ -104,6 +106,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
floatOverlayInFullScreen = true,
onMouseEnter,
onMouseLeave,
allowDownload = true,
}) => {
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
@@ -348,51 +351,52 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
)}
{/* Download */}
{isAudio ? (
<button
onClick={() => handleDownload(data.media?.original?.key || '')}
className="transition-colors hover:text-primary"
title={m.download()}
disabled={!data.media?.original?.key}
>
<Download className="h-5 w-5" />
</button>
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="transition-colors hover:text-primary" title={m.download()}>
<Download className="h-5 w-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
))}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
{allowDownload &&
(isAudio ? (
<button
onClick={() => handleDownload(data.media?.original?.key || '')}
className="transition-colors hover:text-primary"
title={m.download()}
disabled={!data.media?.original?.key}
>
<Download className="h-5 w-5" />
</button>
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="transition-colors hover:text-primary" title={m.download()}>
<Download className="h-5 w-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
onClick={() => handleDownload(data.media?.original?.key ?? '')}
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{m.original()}</span>
<span className="text-xs text-muted-foreground">
{data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)}
))}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(data.media?.original?.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{m.original()}</span>
<span className="text-xs text-muted-foreground">
{data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
))}
{/* Fullscreen */}
<button
@@ -13,7 +13,17 @@ import { FileViewerProps, MediaController } from '../types'
const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
(
{ file: data, onPlay, onPause, onTimeUpdate, annotations, startTime, shareId, children },
{
file: data,
onPlay,
onPause,
onTimeUpdate,
annotations,
startTime,
shareId,
children,
allowDownload,
},
ref,
) => {
const localPlayerRef = useRef<Player | null>(null)
@@ -683,6 +693,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
seekToFrame={seekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
/>
</div>
)