1
0
mirror of https://github.com/immich-app/immich.git synced 2025-06-24 04:46:50 +02:00

refactor(web): shared link key auth (#3855)

This commit is contained in:
Jason Rasmussen
2023-08-25 00:03:28 -04:00
committed by GitHub
parent 10c2bda3a9
commit 9bbef4a97b
21 changed files with 115 additions and 108 deletions

View File

@ -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) => {