|
|
|
|
@ -3,20 +3,22 @@ import { downloadManager } from '$lib/stores/download';
|
|
|
|
|
import { api, BulkIdResponseDto, AssetResponseDto, DownloadResponseDto, DownloadInfoDto } from '@api';
|
|
|
|
|
import { handleError } from './handle-error';
|
|
|
|
|
|
|
|
|
|
export const addAssetsToAlbum = async (
|
|
|
|
|
albumId: string,
|
|
|
|
|
assetIds: Array<string>,
|
|
|
|
|
key: string | undefined = undefined,
|
|
|
|
|
): Promise<BulkIdResponseDto[]> =>
|
|
|
|
|
api.albumApi.addAssetsToAlbum({ id: albumId, bulkIdsDto: { ids: assetIds }, key }).then(({ data: results }) => {
|
|
|
|
|
const count = results.filter(({ success }) => success).length;
|
|
|
|
|
notificationController.show({
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
message: `Added ${count} asset${count === 1 ? '' : 's'}`,
|
|
|
|
|
});
|
|
|
|
|
export const addAssetsToAlbum = async (albumId: string, assetIds: Array<string>): Promise<BulkIdResponseDto[]> =>
|
|
|
|
|
api.albumApi
|
|
|
|
|
.addAssetsToAlbum({
|
|
|
|
|
id: albumId,
|
|
|
|
|
bulkIdsDto: { ids: assetIds },
|
|
|
|
|
key: api.getKey(),
|
|
|
|
|
})
|
|
|
|
|
.then(({ data: results }) => {
|
|
|
|
|
const count = results.filter(({ success }) => success).length;
|
|
|
|
|
notificationController.show({
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
message: `Added ${count} asset${count === 1 ? '' : 's'}`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
});
|
|
|
|
|
return results;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const downloadBlob = (data: Blob, filename: string) => {
|
|
|
|
|
const url = URL.createObjectURL(data);
|
|
|
|
|
@ -32,11 +34,11 @@ const downloadBlob = (data: Blob, filename: string) => {
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const downloadArchive = async (fileName: string, options: DownloadInfoDto, key?: string) => {
|
|
|
|
|
export const downloadArchive = async (fileName: string, options: DownloadInfoDto) => {
|
|
|
|
|
let downloadInfo: DownloadResponseDto | null = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await api.assetApi.getDownloadInfo({ downloadInfoDto: options, key });
|
|
|
|
|
const { data } = await api.assetApi.getDownloadInfo({ downloadInfoDto: options, key: api.getKey() });
|
|
|
|
|
downloadInfo = data;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to download files');
|
|
|
|
|
@ -61,7 +63,7 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await api.assetApi.downloadArchive(
|
|
|
|
|
{ assetIdsDto: { assetIds: archive.assetIds }, key },
|
|
|
|
|
{ assetIdsDto: { assetIds: archive.assetIds }, key: api.getKey() },
|
|
|
|
|
{
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
signal: abort.signal,
|
|
|
|
|
@ -80,7 +82,7 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const downloadFile = async (asset: AssetResponseDto, key?: string) => {
|
|
|
|
|
export const downloadFile = async (asset: AssetResponseDto) => {
|
|
|
|
|
const assets = [
|
|
|
|
|
{
|
|
|
|
|
filename: `${asset.originalFileName}.${getFilenameExtension(asset.originalPath)}`,
|
|
|
|
|
@ -104,7 +106,7 @@ export const downloadFile = async (asset: AssetResponseDto, key?: string) => {
|
|
|
|
|
downloadManager.add(downloadKey, size, abort);
|
|
|
|
|
|
|
|
|
|
const { data } = await api.assetApi.downloadFile(
|
|
|
|
|
{ id, key },
|
|
|
|
|
{ id, key: api.getKey() },
|
|
|
|
|
{
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
onDownloadProgress: (event: ProgressEvent) => {
|
|
|
|
|
|