mirror of
https://github.com/immich-app/immich.git
synced 2025-01-16 16:56:46 +01:00
refactor: image path building (#9823)
This commit is contained in:
parent
d400925aeb
commit
db4c66094c
2 changed files with 18 additions and 16 deletions
|
@ -23,3 +23,13 @@ export const setApiKey = (apiKey: string) => {
|
|||
defaults.headers = defaults.headers || {};
|
||||
defaults.headers['x-api-key'] = apiKey;
|
||||
};
|
||||
|
||||
export const getAssetOriginalPath = (id: string) => `/asset/file/${id}`;
|
||||
|
||||
export const getAssetThumbnailPath = (id: string) => `/asset/thumbnail/${id}`;
|
||||
|
||||
export const getUserProfileImagePath = (userId: string) =>
|
||||
`/users/${userId}/profile-image`;
|
||||
|
||||
export const getPeopleThumbnailPath = (personId: string) =>
|
||||
`/people/${personId}/thumbnail`;
|
||||
|
|
|
@ -6,7 +6,11 @@ import {
|
|||
JobName,
|
||||
ThumbnailFormat,
|
||||
finishOAuth,
|
||||
getAssetOriginalPath,
|
||||
getAssetThumbnailPath,
|
||||
getBaseUrl,
|
||||
getPeopleThumbnailPath,
|
||||
getUserProfileImagePath,
|
||||
linkOAuthAccount,
|
||||
startOAuth,
|
||||
unlinkOAuthAccount,
|
||||
|
@ -162,31 +166,19 @@ export const getAssetFileUrl = (
|
|||
...[assetId, isWeb, isThumb, checksum]:
|
||||
| [assetId: string, isWeb: boolean, isThumb: boolean]
|
||||
| [assetId: string, isWeb: boolean, isThumb: boolean, checksum: string]
|
||||
) => {
|
||||
const path = `/asset/file/${assetId}`;
|
||||
return createUrl(path, { isThumb, isWeb, key: getKey(), c: checksum });
|
||||
};
|
||||
) => createUrl(getAssetOriginalPath(assetId), { isThumb, isWeb, key: getKey(), c: checksum });
|
||||
|
||||
export const getAssetThumbnailUrl = (
|
||||
...[assetId, format, checksum]:
|
||||
| [assetId: string, format: ThumbnailFormat | undefined]
|
||||
| [assetId: string, format: ThumbnailFormat | undefined, checksum: string]
|
||||
) => {
|
||||
// checksum (optional) is used as a cache-buster param, since thumbs are
|
||||
// served with static resource cache headers
|
||||
const path = `/asset/thumbnail/${assetId}`;
|
||||
return createUrl(path, { format, key: getKey(), c: checksum });
|
||||
return createUrl(getAssetThumbnailPath(assetId), { format, key: getKey(), c: checksum });
|
||||
};
|
||||
|
||||
export const getProfileImageUrl = (userId: string) => {
|
||||
const path = `/users/${userId}/profile-image`;
|
||||
return createUrl(path);
|
||||
};
|
||||
export const getProfileImageUrl = (userId: string) => createUrl(getUserProfileImagePath(userId));
|
||||
|
||||
export const getPeopleThumbnailUrl = (personId: string) => {
|
||||
const path = `/people/${personId}/thumbnail`;
|
||||
return createUrl(path);
|
||||
};
|
||||
export const getPeopleThumbnailUrl = (personId: string) => createUrl(getPeopleThumbnailPath(personId));
|
||||
|
||||
export const getAssetJobName = (job: AssetJobName) => {
|
||||
const names: Record<AssetJobName, string> = {
|
||||
|
|
Loading…
Reference in a new issue