mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 21:49:19 +00:00
* feat(storage): add archive storage support for assets * fix(webui): show archive icon in front of file name in breadcrumb bar * fix(webui): display archive icon in breadcrumbs when restoring * refactor(transcode): simplify restore asset workflow to single while loop * docs(configuration): add archive storage documentation and readme entries * fix(webui): show archive icon in front of version names and prevent version card overflow * fix(webui): fix overflow in manage versions dialog scroll area * fix(webui): prevent manage versions dialog overflow on long file names * docs(configuration): fix archive storage environment variables and defaults * fix(storage): address code review findings for archive storage
102 lines
3.9 KiB
TypeScript
102 lines
3.9 KiB
TypeScript
import { client } from '@/ui/api/client'
|
|
import { m } from '@/ui/paraglide/messages.js'
|
|
import { Download, AlertCircle } from 'lucide-react'
|
|
import React, { useImperativeHandle } from 'react'
|
|
import { FileViewerProps, MediaController } from '../types'
|
|
|
|
export const DefaultViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|
({ file, shareId, children, allowDownload = true }, ref) => {
|
|
// Implement no-op media controller
|
|
useImperativeHandle(ref, () => ({
|
|
play: () => {},
|
|
pause: () => {},
|
|
seekTo: () => {},
|
|
}))
|
|
|
|
const handleDownload = async () => {
|
|
const key = file.media?.original?.key
|
|
if (!key || !file.id) return
|
|
try {
|
|
const res = shareId
|
|
? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({
|
|
param: { shareId, fileId: file.id },
|
|
json: { key },
|
|
})
|
|
: await client.api.files['download-url'].$post({
|
|
json: { key, assetId: file.id },
|
|
})
|
|
if (!res.ok) return
|
|
const { url } = await res.json()
|
|
const link = document.createElement('a')
|
|
link.href = url
|
|
link.download = ''
|
|
document.body.appendChild(link)
|
|
link.click()
|
|
document.body.removeChild(link)
|
|
} catch {
|
|
// silently fail
|
|
}
|
|
}
|
|
|
|
const isFailed = file.status === 'failed'
|
|
const errorMessage = file.media?.error
|
|
|
|
return (
|
|
<div className="flex flex-col flex-1 h-full overflow-hidden bg-gray-100 dark:bg-gray-950 relative">
|
|
<div className="flex-1 flex flex-col-reverse md:flex-row min-h-0 relative">
|
|
{children}
|
|
<div className="flex-1 flex items-center justify-center p-6 text-center">
|
|
{isFailed ? (
|
|
<div
|
|
data-testid="default-viewer-failed-state"
|
|
className="flex flex-col items-center justify-center gap-3 max-w-md"
|
|
>
|
|
<AlertCircle className="h-12 w-12 text-destructive/80" />
|
|
<div className="space-y-1">
|
|
<h3 className="text-base font-semibold text-foreground">
|
|
{m.media_processing_failed()}
|
|
</h3>
|
|
<p className="text-sm text-muted-foreground">
|
|
{m.media_processing_failed_desc()}
|
|
</p>
|
|
{errorMessage && (
|
|
<div
|
|
title={errorMessage}
|
|
className="mt-3 rounded-lg border border-destructive/20 bg-destructive/10 p-3 text-xs text-destructive text-left line-clamp-3 break-words"
|
|
>
|
|
{errorMessage}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<p className="text-muted-foreground">Preview unavailable</p>
|
|
)}
|
|
</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">
|
|
{allowDownload && (
|
|
<button
|
|
data-testid="default-viewer-download-button"
|
|
onClick={handleDownload}
|
|
disabled={
|
|
!file.media?.original?.key ||
|
|
file.status === 'archived' ||
|
|
file.status === 'archiving' ||
|
|
file.status === 'restoring'
|
|
}
|
|
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>
|
|
)
|
|
},
|
|
)
|
|
|
|
export default DefaultViewer
|