Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: image path building #9823

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions open-api/typescript-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
24 changes: 8 additions & 16 deletions web/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
JobName,
ThumbnailFormat,
finishOAuth,
getAssetOriginalPath,
getAssetThumbnailPath,
getBaseUrl,
getPeopleThumbnailPath,
getUserProfileImagePath,
linkOAuthAccount,
startOAuth,
unlinkOAuthAccount,
Expand Down Expand Up @@ -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> = {
Expand Down
Loading