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