Файловое хранилище готово
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { uploadFile } from '../../services/storageService';
|
||||
import { addToast } from '../../lib/toasts';
|
||||
import { t } from '../../lib/i18n';
|
||||
// [/SECTION: IMPORTS]
|
||||
|
||||
// [DEF:handleUpload:Function]
|
||||
@@ -24,7 +25,8 @@
|
||||
*/
|
||||
const dispatch = createEventDispatcher();
|
||||
let fileInput;
|
||||
let category = 'backup';
|
||||
export let category = 'backups';
|
||||
export let path = '';
|
||||
let isUploading = false;
|
||||
let dragOver = false;
|
||||
|
||||
@@ -34,12 +36,18 @@
|
||||
|
||||
isUploading = true;
|
||||
try {
|
||||
await uploadFile(file, category);
|
||||
addToast(`File ${file.name} uploaded successfully.`, 'success');
|
||||
// path is relative to root, but upload endpoint expects path within category
|
||||
// FileList.path is like "backup/folder", we need just "folder"
|
||||
const subpath = path.startsWith(category)
|
||||
? path.substring(category.length).replace(/^\/+/, '')
|
||||
: path;
|
||||
|
||||
await uploadFile(file, category, subpath);
|
||||
addToast($t.storage.messages.upload_success.replace('{name}', file.name), 'success');
|
||||
fileInput.value = '';
|
||||
dispatch('uploaded');
|
||||
} catch (error) {
|
||||
addToast(`Upload failed: ${error.message}`, 'error');
|
||||
addToast($t.storage.messages.upload_failed.replace('{error}', error.message), 'error');
|
||||
} finally {
|
||||
isUploading = false;
|
||||
}
|
||||
@@ -65,17 +73,17 @@
|
||||
|
||||
<!-- [SECTION: TEMPLATE] -->
|
||||
<div class="bg-white p-6 rounded-lg border border-gray-200 shadow-sm">
|
||||
<h2 class="text-lg font-semibold mb-4">Upload File</h2>
|
||||
<h2 class="text-lg font-semibold mb-4">{$t.storage.upload_title}</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Target Category</label>
|
||||
<select
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">{$t.storage.target_category}</label>
|
||||
<select
|
||||
bind:value={category}
|
||||
class="block w-full border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
|
||||
>
|
||||
<option value="backup">Backup</option>
|
||||
<option value="repository">Repository</option>
|
||||
<option value="backups">{$t.storage.backups}</option>
|
||||
<option value="repositorys">{$t.storage.repositories}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -92,8 +100,8 @@
|
||||
</svg>
|
||||
<div class="flex text-sm text-gray-600">
|
||||
<label for="file-upload" class="relative cursor-pointer bg-white rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500">
|
||||
<span>Upload a file</span>
|
||||
<input
|
||||
<span>{$t.storage.upload_button}</span>
|
||||
<input
|
||||
id="file-upload"
|
||||
name="file-upload"
|
||||
type="file"
|
||||
@@ -103,16 +111,16 @@
|
||||
disabled={isUploading}
|
||||
>
|
||||
</label>
|
||||
<p class="pl-1">or drag and drop</p>
|
||||
<p class="pl-1">{$t.storage.drag_drop}</p>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500">ZIP, YAML, JSON up to 50MB</p>
|
||||
<p class="text-xs text-gray-500">{$t.storage.supported_formats}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if isUploading}
|
||||
<div class="flex items-center justify-center space-x-2 text-indigo-600">
|
||||
<div class="animate-spin rounded-full h-4 w-4 border-b-2 border-indigo-600"></div>
|
||||
<span class="text-sm font-medium">Uploading...</span>
|
||||
<span class="text-sm font-medium">{$t.storage.uploading}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user