2024-01-17 20:18:04 +01:00
|
|
|
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
|
2024-02-14 14:09:49 +01:00
|
|
|
import { deleteAssets as deleteBulk } from '@immich/sdk';
|
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;
|
|
|
|
export type OnArchive = (ids: string[], isArchived: boolean) => void;
|
|
|
|
export type OnFavorite = (ids: string[], favorite: boolean) => void;
|
|
|
|
export type OnStack = (ids: string[]) => void;
|
|
|
|
|
|
|
|
export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids: string[]) => {
|
|
|
|
try {
|
2024-02-14 14:09:49 +01: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({
|
|
|
|
message: `${force ? 'Permanently deleted' : 'Trashed'} ${ids.length} assets`,
|
|
|
|
type: NotificationType.Info,
|
|
|
|
});
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
|
|
|
handleError(error, 'Error deleting assets');
|
2024-01-17 20:18:04 +01:00
|
|
|
}
|
|
|
|
};
|