Skip to content

Commit a29e812

Browse files
committed
fix mobile remote asset urls
1 parent 77ab029 commit a29e812

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

apps/mobile/src/components/ProjectFavicon.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SymbolView } from "expo-symbols";
22
import { useState } from "react";
33
import { Image, View } from "react-native";
4+
import { resolveRemoteHttpUrl } from "../lib/remoteUrl";
45
import { useThemeColor } from "../lib/useThemeColor";
56

67
/* ─── Favicon cache (matches web pattern) ────────────────────────────── */
@@ -19,7 +20,11 @@ export function ProjectFavicon(props: {
1920

2021
const faviconUrl =
2122
props.httpBaseUrl && props.workspaceRoot
22-
? `${props.httpBaseUrl}/api/project-favicon?cwd=${encodeURIComponent(props.workspaceRoot)}`
23+
? resolveRemoteHttpUrl({
24+
httpBaseUrl: props.httpBaseUrl,
25+
pathname: "/api/project-favicon",
26+
searchParams: { cwd: props.workspaceRoot },
27+
})
2328
: null;
2429

2530
const [status, setStatus] = useState<"loading" | "loaded" | "error">(() =>

apps/mobile/src/features/threads/threadPresentation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { StatusTone } from "../../components/StatusPill";
22
import { EnvironmentScopedThreadShell } from "@t3tools/client-runtime";
3+
import { resolveRemoteHttpUrl } from "../../lib/remoteUrl";
34

45
export function threadSortValue(thread: EnvironmentScopedThreadShell): number {
56
const candidate = Date.parse(thread.updatedAt ?? thread.createdAt);
@@ -48,6 +49,8 @@ export function messageImageUrl(httpBaseUrl: string | null, attachmentId: string
4849
return null;
4950
}
5051

51-
const url = new URL(`/attachments/${encodeURIComponent(attachmentId)}`, httpBaseUrl);
52-
return url.toString();
52+
return resolveRemoteHttpUrl({
53+
httpBaseUrl,
54+
pathname: `/attachments/${encodeURIComponent(attachmentId)}`,
55+
});
5356
}

apps/mobile/src/lib/remoteUrl.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as Effect from "effect/Effect";
2+
3+
import { normalizeBasePath } from "@t3tools/shared/basePath";
4+
5+
export function resolveRemoteHttpUrl(input: {
6+
readonly httpBaseUrl: string;
7+
readonly pathname: string;
8+
readonly searchParams?: Readonly<Record<string, string | null | undefined>>;
9+
}): string {
10+
const url = new URL(input.httpBaseUrl);
11+
const basePath = Effect.runSync(normalizeBasePath(url.pathname));
12+
const pathname = input.pathname.startsWith("/") ? input.pathname : `/${input.pathname}`;
13+
14+
url.pathname = `${basePath}${pathname}`;
15+
url.search = "";
16+
url.hash = "";
17+
18+
for (const [key, value] of Object.entries(input.searchParams ?? {})) {
19+
if (value !== null && value !== undefined) {
20+
url.searchParams.set(key, value);
21+
}
22+
}
23+
24+
return url.toString();
25+
}

0 commit comments

Comments
 (0)