mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 06:24:30 +00:00
fix(share): resolve symlinks for download URLs and enable card download action (#274)
This commit is contained in:
@@ -91,6 +91,7 @@ interface FileBrowserProps {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onUpdateCollection?: (updates: { name?: string; filter?: any }) => void
|
||||
rootFolderId?: string
|
||||
shareId?: string
|
||||
}
|
||||
|
||||
type FileWithId = {
|
||||
@@ -136,6 +137,7 @@ export function FileBrowser({
|
||||
collection,
|
||||
onUpdateCollection,
|
||||
rootFolderId,
|
||||
shareId,
|
||||
}: FileBrowserProps) {
|
||||
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
|
||||
const [moveCopyMode, setMoveCopyMode] = useState<'move' | 'copy' | null>(null)
|
||||
@@ -418,6 +420,8 @@ export function FileBrowser({
|
||||
folders,
|
||||
files: displayedFiles,
|
||||
selectedIds,
|
||||
isPublic,
|
||||
shareId,
|
||||
})
|
||||
|
||||
const [isEmptyTrashDialogOpen, setIsEmptyTrashDialogOpen] = useState(false)
|
||||
@@ -666,6 +670,8 @@ export function FileBrowser({
|
||||
? [...folders, ...files].filter((i) => selectedIds.has(i.id!))
|
||||
: [item]
|
||||
onRemoveFromShare?.(targetItems)
|
||||
} else if (action === 'download') {
|
||||
handleAction('download', item)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ interface UseFileActionsProps {
|
||||
folders: AssetInfo[]
|
||||
files: AssetInfo[]
|
||||
selectedIds: Set<string>
|
||||
isPublic?: boolean
|
||||
shareId?: string
|
||||
}
|
||||
|
||||
export function useFileActions({
|
||||
@@ -25,6 +27,8 @@ export function useFileActions({
|
||||
folders,
|
||||
files,
|
||||
selectedIds,
|
||||
isPublic,
|
||||
shareId,
|
||||
}: UseFileActionsProps) {
|
||||
const [editingItemId, setEditingItemId] = useState<string | null>(null)
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
||||
@@ -215,10 +219,35 @@ export function useFileActions({
|
||||
setIsLoadingLinks(true)
|
||||
setResolvedFiles([])
|
||||
try {
|
||||
const res = await getDownloadLinks({
|
||||
json: { ids: items.map((i) => i.id!) },
|
||||
})
|
||||
setResolvedFiles(res.files)
|
||||
if (isPublic && shareId) {
|
||||
const password = localStorage.getItem(`share_pwd_${shareId}`) || ''
|
||||
const links: Array<{ id: string; name: string; url: string }> = []
|
||||
for (const item of items) {
|
||||
const key = item.media?.original?.key
|
||||
if (!key || !item.id) continue
|
||||
const res = await client.api.shares[':shareId'].files[':fileId']['download-url'].$post(
|
||||
{
|
||||
param: { shareId, fileId: item.id },
|
||||
json: { key },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'x-share-password': password,
|
||||
},
|
||||
},
|
||||
)
|
||||
if (res.ok) {
|
||||
const { url } = await res.json()
|
||||
links.push({ id: item.id, name: item.name || 'download', url })
|
||||
}
|
||||
}
|
||||
setResolvedFiles(links)
|
||||
} else {
|
||||
const res = await getDownloadLinks({
|
||||
json: { ids: items.map((i) => i.id!) },
|
||||
})
|
||||
setResolvedFiles(res.files)
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error('Failed to prepare download links')
|
||||
setIsDownloadDialogOpen(false)
|
||||
|
||||
@@ -618,6 +618,7 @@ export function PublicShareManager({
|
||||
isFetchingNextFilesPage={isFetchingNextFilesPage}
|
||||
isShareView={true}
|
||||
isPublic={true}
|
||||
shareId={shareId}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user