2024-01-17 20:18:04 +01:00
|
|
|
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
|
2024-04-17 13:55:07 +02:00
|
|
|
import { deleteAssets as deleteBulk, type AssetResponseDto } from '@immich/sdk';
|
2024-06-24 15:50:01 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
|
|
|
|
import { get } from 'svelte/store';
|
2024-01-17 20:18:04 +01:00
|
|
|
import { handleError } from './handle-error';
|
|
|
|
|
|
2024-03-02 01:49:31 +01:00
|
|
|
export type OnDelete = (assetIds: string[]) => void;
|
2024-01-17 20:18:04 +01:00
|
|
|
export type OnRestore = (ids: string[]) => void;
|
2024-09-11 16:26:29 -04:00
|
|
|
export type OnLink = (assets: { still: AssetResponseDto; motion: AssetResponseDto }) => void;
|
|
|
|
|
export type OnUnlink = (assets: { still: AssetResponseDto; motion: AssetResponseDto }) => void;
|
2024-01-17 20:18:04 +01:00
|
|
|
export type OnArchive = (ids: string[], isArchived: boolean) => void;
|
|
|
|
|
export type OnFavorite = (ids: string[], favorite: boolean) => void;
|
|
|
|
|
export type OnStack = (ids: string[]) => void;
|
2024-04-17 13:55:07 +02:00
|
|
|
export type OnUnstack = (assets: AssetResponseDto[]) => void;
|
2024-01-17 20:18:04 +01:00
|
|
|
|
|
|
|
|
export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids: string[]) => {
|
2024-06-24 15:50:01 +02:00
|
|
|
const $t = get(t);
|
2024-01-17 20:18:04 +01:00
|
|
|
try {
|
2024-02-14 08:09:49 -05:00
|
|
|
await deleteBulk({ assetBulkDeleteDto: { ids, force } });
|
2024-03-02 01:49:31 +01:00
|
|
|
onAssetDelete(ids);
|
2024-01-17 20:18:04 +01:00
|
|
|
|
|
|
|
|
notificationController.show({
|
2024-06-24 15:50:01 +02:00
|
|
|
message: force
|
|
|
|
|
? $t('assets_permanently_deleted_count', { values: { count: ids.length } })
|
|
|
|
|
: $t('assets_trashed_count', { values: { count: ids.length } }),
|
2024-01-17 20:18:04 +01:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.unable_to_delete_assets'));
|
2024-01-17 20:18:04 +01:00
|
|
|
}
|
|
|
|
|
};
|