починили скачивание

This commit is contained in:
2026-03-06 15:22:14 +03:00
parent 985168efb3
commit 1704b0f878
5 changed files with 7679 additions and 2452 deletions

View File

@@ -13,8 +13,9 @@
<script lang="ts">
// [SECTION: IMPORTS]
import { createEventDispatcher } from 'svelte';
import { downloadFileUrl } from '../../services/storageService';
import { downloadFile } from '../../services/storageService';
import { t } from '../../lib/i18n';
import { addToast } from '../../lib/toasts';
// [/SECTION: IMPORTS]
let {
@@ -68,6 +69,21 @@
return new Date(dateStr).toLocaleString();
}
// [/DEF:formatDate:Function]
// [DEF:handleDownload:Function]
/**
* @purpose Downloads selected file through authenticated API request.
* @pre file is a non-directory storage entry with category/path.
* @post Browser download starts or user sees toast on failure.
*/
async function handleDownload(file) {
try {
await downloadFile(file.category, file.path, file.name);
} catch (error) {
addToast(error?.message || 'Download failed', 'error');
}
}
// [/DEF:handleDownload:Function]
</script>
<!-- [SECTION: TEMPLATE] -->
@@ -112,13 +128,13 @@
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{formatDate(file.created_at)}</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
{#if !isDirectory(file)}
<a
href={downloadFileUrl(file.category, file.path)}
download={file.name}
<button
type="button"
on:click={() => handleDownload(file)}
class="text-indigo-600 hover:text-indigo-900 mr-4"
>
{$t.storage.table.download}
</a>
</button>
{/if}
<button
on:click={() => dispatch('delete', { category: file.category, path: file.path, name: file.name })}
@@ -141,4 +157,4 @@
<!-- [/SECTION: TEMPLATE] -->
<!-- [/DEF:FileList:Component] -->
<!-- [/DEF:FileList:Component] -->