@@ -31,7 +31,10 @@ import {
3131 type ImageDimensions ,
3232} from "@t3tools/shared/imageDimensions" ;
3333import { githubMediaFetchUrl , githubMediaFileName } from "@t3tools/shared/githubMedia" ;
34- import { PROJECT_FAVICON_FALLBACK_MARKER } from "@t3tools/shared/projectFavicon" ;
34+ import {
35+ isProjectFaviconPath ,
36+ PROJECT_FAVICON_FALLBACK_MARKER ,
37+ } from "@t3tools/shared/projectFavicon" ;
3538import { MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH , toolOutputImages } from "@t3tools/shared/toolOutput" ;
3639import * as Clock from "effect/Clock" ;
3740import * as Crypto from "effect/Crypto" ;
@@ -57,6 +60,7 @@ import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
5760import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts" ;
5861import * as WorkspacePaths from "../workspace/WorkspacePaths.ts" ;
5962import * as NativeAppIconResolver from "./NativeAppIconResolver.ts" ;
63+ import { extractIcnsPng } from "./icns.ts" ;
6064import { openMediaFile , readMediaFileHeader , type OpenMediaFile } from "./MediaFile.ts" ;
6165import * as HostProcess from "@t3tools/shared/HostProcess" ;
6266
@@ -66,6 +70,8 @@ const SIGNING_SECRET_NAME = "asset-access-signing-key";
6670const ASSET_TOKEN_TTL_MS = 60 * 60 * 1000 ;
6771const PROJECT_FAVICON_TOKEN_BUCKET_MS = 30 * 60 * 1000 ;
6872const PROJECT_FAVICON_VERSION_PREFIX = "v" ;
73+ // Clients draw project icons from a 96px thumbnail at most.
74+ const PROJECT_FAVICON_ICNS_MIN_SIZE = 96 ;
6975const INLINE_VIDEO_MIME_TYPE_PATTERN = / ^ v i d e o \/ [ \w ! # $ & ^ . + - ] + $ / i;
7076// Extensions a document viewer or audio player may request inline. The extension comes from
7177// the attachment id the server assigned, never from the client's mime type.
@@ -234,6 +240,26 @@ const readToolOutputImage = Effect.fn("AssetAccess.readToolOutputImage")(functio
234240 : { mimeType : image . mimeType , bytes : Buffer . from ( image . data , "base64" ) } ;
235241} ) ;
236242
243+ /** Serves an `.icns` favicon as its embedded PNG, since browsers cannot draw it. */
244+ const projectFaviconAsset = Effect . fn ( "AssetAccess.projectFaviconAsset" ) ( function * (
245+ filePath : string ,
246+ ) {
247+ if ( ! filePath . toLowerCase ( ) . endsWith ( ".icns" ) ) {
248+ return { kind : "file" , path : filePath } satisfies ResolvedAsset ;
249+ }
250+ const fileSystem = yield * FileSystem . FileSystem ;
251+ const bytes = yield * fileSystem . readFile ( filePath ) . pipe (
252+ Effect . tapError ( ( cause ) =>
253+ Effect . logError ( "Failed to read project icon image." , { filePath, cause } ) ,
254+ ) ,
255+ Effect . orElseSucceed ( ( ) => null ) ,
256+ ) ;
257+ const png = bytes ? extractIcnsPng ( bytes , PROJECT_FAVICON_ICNS_MIN_SIZE ) : null ;
258+ return png
259+ ? ( { kind : "bytes" , bytes : png , mimeType : "image/png" } satisfies ResolvedAsset )
260+ : null ;
261+ } ) ;
262+
237263const resolveCanonicalFile = Effect . fn ( "AssetAccess.resolveCanonicalFile" ) ( function * (
238264 filePath : string ,
239265) {
@@ -634,7 +660,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
634660 const relativePath =
635661 faviconPath && ! isExternalOverride ? path . relative ( workspaceRoot , faviconPath ) : null ;
636662 const sourceFaviconPath = isExternalOverride ? faviconPath : relativePath ;
637- if ( sourceFaviconPath && ! isWorkspaceImagePreviewPath ( sourceFaviconPath ) ) {
663+ if ( sourceFaviconPath && ! isProjectFaviconPath ( sourceFaviconPath ) ) {
638664 return yield * new AssetPreviewTypeValidationError ( { resource : input . resource } ) ;
639665 }
640666 sourcePath = sourceFaviconPath ?? undefined ;
@@ -837,7 +863,7 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
837863 workspaceRoot : claims . workspaceRoot ,
838864 relativePath : claims . relativePath ,
839865 } ) ;
840- return faviconPath ? ( { kind : "file" , path : faviconPath } satisfies ResolvedAsset ) : null ;
866+ return faviconPath ? yield * projectFaviconAsset ( faviconPath ) : null ;
841867 }
842868
843869 if ( claims . kind === "project-favicon-external" ) {
@@ -850,9 +876,7 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
850876 ) ,
851877 Effect . orElseSucceed ( ( ) => null ) ,
852878 ) ;
853- return faviconPath === claims . filePath
854- ? ( { kind : "file" , path : faviconPath } satisfies ResolvedAsset )
855- : null ;
879+ return faviconPath === claims . filePath ? yield * projectFaviconAsset ( faviconPath ) : null ;
856880 }
857881
858882 if ( claims . kind === "github-media" ) {
0 commit comments