mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
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:
@@ -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>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user