feat(photos): fix trash permanent delete and add empty trash

Permanently deleting a photo whose album was deleted failed because
authorization resolved through the album. Fall back to uploader
ownership when the photo is albumless. Add a bulk DELETE /trash that
removes every trashed photo the caller may delete (uncapped listing)
and returns the deleted count, with an «Очистить корзину» action on the
trash screen.
This commit is contained in:
iu
2026-10-11 20:54:54 +03:00
parent d5d3f55db8
commit 3b745fa737
16 changed files with 643 additions and 13 deletions
@@ -4,6 +4,7 @@
import { portal } from '$lib/actions/portal';
import { photosApi, ApiError } from '$lib/api';
import { albums } from '$lib/stores/albums.svelte';
import { trash } from '$lib/stores/trash.svelte';
import type { Photo } from '$lib/types';
let photos = $state<Photo[]>([]);
@@ -12,6 +13,9 @@
let pending = $state<Photo | null>(null);
let busy = $state(false);
let confirmingEmpty = $state(false);
let emptyBusy = $state(false);
let restoring = $state<Photo | null>(null);
let targetId = $state('');
let createNew = $state(false);
@@ -92,12 +96,37 @@
busy = false;
}
}
async function emptyAll() {
if (emptyBusy) return;
emptyBusy = true;
try {
await photosApi.emptyTrash();
await load();
await trash.load();
confirmingEmpty = false;
} catch (e) {
error = (e as Error).message;
} finally {
emptyBusy = false;
}
}
</script>
<div class="p-4 sm:p-6">
<div class="mb-4 flex items-center gap-2">
<Icon name="delete" class="size-5 text-text-muted" />
<h1 class="text-xl font-semibold">Корзина</h1>
{#if photos.length > 0}
<button
type="button"
class="border-border text-danger hover:bg-bg-muted ml-auto inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm"
onclick={() => (confirmingEmpty = true)}
>
<Icon name="delete_forever" class="size-4" />
Очистить корзину
</button>
{/if}
</div>
{#if error}<p class="text-danger mb-3 text-sm">{error}</p>{/if}
@@ -166,6 +195,17 @@
/>
{/if}
{#if confirmingEmpty}
<ConfirmDialog
title="Очистить корзину?"
message="Все доступные вам для удаления элементы корзины будут удалены без возможности восстановления. Файлы хранилища удаляются, если на них нет ссылок в других альбомах."
confirmLabel="Очистить"
busy={emptyBusy}
onConfirm={emptyAll}
onClose={() => (confirmingEmpty = false)}
/>
{/if}
{#if restoring}
<div
use:portal