Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectFavicon.ts

37 lines1.0 KB

1export const PROJECT_FAVICON_FALLBACK_MARKER = "project-favicon-missing";
2​
3export function getProjectFaviconResourceKey(
4 environmentId: string,
5 workspaceRoot: string,
6 faviconPath?: string | null,
7) {
8 return JSON.stringify([environmentId, workspaceRoot, faviconPath || null]);
9}
10​
11export function getProjectFaviconCacheKey(
12 environmentId: string,
13 workspaceRoot: string,
14 url: string,
15) {
16 let revision = url;
17​
18 try {
19 const pathname = new URL(url, "https://t3.invalid").pathname;
20 revision = pathname.slice(pathname.lastIndexOf("/") + 1);
21 } catch {
22 // Keep the full value as a safe fallback for malformed URLs.
23 }
24​
25 return JSON.stringify([environmentId, workspaceRoot, revision]);
27​
28export function isProjectFaviconFallbackUrl(url: string | null | undefined): boolean {
29 if (!url) return false;
30​
31 try {
32 const pathname = new URL(url, "https://t3.invalid").pathname;
33 return pathname.slice(pathname.lastIndexOf("/") + 1) === PROJECT_FAVICON_FALLBACK_MARKER;
34 } catch {
35 return false;
36 }