refactor: image path building (#9823)

This commit is contained in:
Jason Rasmussen 2024-05-28 13:15:02 -04:00 committed by GitHub
parent d400925aeb
commit db4c66094c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 16 deletions

View File

@ -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`;

View File

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