1import type { AssetResource, EnvironmentId } from "@t3tools/contracts";
2import type { ImageSource } from "expo-image";
3
4/**
5 * expo-image source for a signed asset URL. Every mint signs a new URL, and a
6 * reconnect mints again, so a URL-keyed cache misses each time. Attachments
7 * never change once stored, so they cache under their id instead.
8 */
9export function assetImageSource(
10 environmentId: EnvironmentId,
11 resource: AssetResource,
12 uri: string,
13): ImageSource {
14 return resource._tag === "attachment"
15 ? {
16 uri,
17 cacheKey: `t3-attachment:${JSON.stringify([environmentId, resource.attachmentId])}`,
18 }
19 : { uri };
20}