refactor(web) open api client (#7103)

* refactor: person api

* refactor: shared link and others
This commit is contained in:
Jason Rasmussen
2024-02-14 08:09:49 -05:00
committed by GitHub
parent 5fc1d43012
commit d8631a00bb
81 changed files with 638 additions and 656 deletions

View File

@@ -1,5 +1,5 @@
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
import { api } from '@api';
import { deleteAssets as deleteBulk } from '@immich/sdk';
import { handleError } from './handle-error';
export type OnDelete = (assetId: string) => void;
@@ -10,7 +10,7 @@ export type OnStack = (ids: string[]) => void;
export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids: string[]) => {
try {
await api.assetApi.deleteAssets({ assetBulkDeleteDto: { ids, force } });
await deleteBulk({ assetBulkDeleteDto: { ids, force } });
for (const id of ids) {
onAssetDelete(id);
}

View File

@@ -3,6 +3,7 @@ import { downloadManager } from '$lib/stores/download';
import { api } from '@api';
import {
addAssetsToAlbum as addAssets,
getDownloadInfo,
type AssetResponseDto,
type AssetTypeEnum,
type BulkIdResponseDto,
@@ -11,13 +12,14 @@ import {
type UserResponseDto,
} from '@immich/sdk';
import { DateTime } from 'luxon';
import { getKey } from '../utils';
import { handleError } from './handle-error';
export const addAssetsToAlbum = async (albumId: string, assetIds: Array<string>): Promise<BulkIdResponseDto[]> =>
addAssets({
id: albumId,
bulkIdsDto: { ids: assetIds },
key: api.getKey(),
key: getKey(),
}).then((results) => {
const count = results.filter(({ success }) => success).length;
notificationController.show({
@@ -46,8 +48,7 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
let downloadInfo: DownloadResponseDto | null = null;
try {
const { data } = await api.downloadApi.getDownloadInfo({ downloadInfoDto: options, key: api.getKey() });
downloadInfo = data;
downloadInfo = await getDownloadInfo({ downloadInfoDto: options, key: getKey() });
} catch (error) {
handleError(error, 'Unable to download files');
return;
@@ -71,7 +72,7 @@ export const downloadArchive = async (fileName: string, options: DownloadInfoDto
try {
const { data } = await api.downloadApi.downloadArchive(
{ assetIdsDto: { assetIds: archive.assetIds }, key: api.getKey() },
{ assetIdsDto: { assetIds: archive.assetIds }, key: getKey() },
{
responseType: 'blob',
signal: abort.signal,
@@ -121,7 +122,7 @@ export const downloadFile = async (asset: AssetResponseDto) => {
downloadManager.add(downloadKey, size, abort);
const { data } = await api.downloadApi.downloadFile(
{ id, key: api.getKey() },
{ id, key: getKey() },
{
responseType: 'blob',
onDownloadProgress: ({ event }) => {

View File

@@ -1,5 +1,6 @@
import { UploadState } from '$lib/models/upload-asset';
import { uploadAssetsStore } from '$lib/stores/upload';
import { getKey } from '$lib/utils';
import { addAssetsToAlbum } from '$lib/utils/asset-utils';
import { ExecutorQueue } from '$lib/utils/executor-queue';
import { api, type AssetFileUploadResponseDto } from '@api';
@@ -81,7 +82,7 @@ async function fileUploader(asset: File, albumId: string | undefined = undefined
isFavorite: false,
duration: '0:00:00.000000',
assetData: new File([asset], asset.name),
key: api.getKey(),
key: getKey(),
},
{
onUploadProgress: ({ event }) => {