Skip to content

Commit

Permalink
perf: github image link
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jul 17, 2024
1 parent bcee3d9 commit 112006c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ export const getImportFileUrl = (importId: number | string) => {
return `https://github.com/user-attachments/files/${importId}/file.zip`;
};

export const githubImageUrlReg =
const githubImageUrlReg =
/^https:\/\/github\.com\/gkd-kit\/inspect\/assets\/([0-9]+)\/([0-9a-z-]+)$/;

const assetBaseUrl = `https://github.com/user-attachments/assets/`;

export const githubUrlToSelfUrl = (u: string): string => {
if (u.startsWith(assetBaseUrl)) {
return `https://e.gkd.li/` + u.substring(assetBaseUrl.length);
}
const { 1: userId, 2: imgAssetId } = u.match(githubImageUrlReg) || [];
if (userId && imgAssetId) {
return `https://m.gkd.li/${userId}/${imgAssetId}`;
} else {
throw new Error(
console.error(
`github url ${u} should come from gkd-kit/inspect files/assets`,
);
}
return u;
};

export const isValidUrl = (url: string): URL | undefined => {
Expand Down

0 comments on commit 112006c

Please sign in to comment.