@@ -12,17 +12,16 @@ import { useSyncExternalStore } from 'react'
12
12
13
13
import {
14
14
addServerPeerMutationOptions ,
15
- attachmentUrlQueryOptions ,
16
15
connectSyncServersMutationOptions ,
17
16
createBlobMutationOptions ,
18
17
createProjectMutationOptions ,
19
18
disconnectSyncServersMutationOptions ,
20
19
documentCreatedByQueryOptions ,
21
20
exportGeoJSONMutationOptions ,
22
21
exportZipFileMutationOptions ,
23
- iconUrlQueryOptions ,
24
22
importProjectConfigMutationOptions ,
25
23
leaveProjectMutationOptions ,
24
+ mediaServerPortQueryOptions ,
26
25
projectByIdQueryOptions ,
27
26
projectMemberByIdQueryOptions ,
28
27
projectMembersQueryOptions ,
@@ -36,6 +35,7 @@ import {
36
35
updateProjectSettingsMutationOptions ,
37
36
} from '../lib/react-query/projects.js'
38
37
import { SyncStore , type SyncState } from '../lib/sync.js'
38
+ import { getBlobUrl , getIconUrl } from '../lib/urls.js'
39
39
import { useClientApi } from './client.js'
40
40
41
41
/**
@@ -237,16 +237,11 @@ export function useIconUrl({
237
237
} & ( IconApi . BitmapOpts | IconApi . SvgOpts ) ) {
238
238
const { data : projectApi } = useSingleProject ( { projectId } )
239
239
240
- const { data, error, isRefetching } = useSuspenseQuery (
241
- iconUrlQueryOptions ( {
242
- ...mimeBasedOpts ,
243
- projectApi,
244
- projectId,
245
- iconId,
246
- } ) ,
247
- )
240
+ const { data : port , error, isRefetching } = useMediaServerPort ( { projectApi } )
241
+ const baseUrl = `http://127.0.0.1:${ port } `
242
+ const iconUrl = getIconUrl ( baseUrl , iconId , mimeBasedOpts )
248
243
249
- return { data, error, isRefetching }
244
+ return { data : iconUrl , error, isRefetching }
250
245
}
251
246
252
247
/**
@@ -309,11 +304,21 @@ export function useAttachmentUrl({
309
304
} ) {
310
305
const { data : projectApi } = useSingleProject ( { projectId } )
311
306
307
+ const { data : port , error, isRefetching } = useMediaServerPort ( { projectApi } )
308
+ const baseUrl = `http://127.0.0.1:${ port } `
309
+ const blobUrl = getBlobUrl ( baseUrl , blobId )
310
+
311
+ return { data : blobUrl , error, isRefetching }
312
+ }
313
+
314
+ /**
315
+ * @internal
316
+ * Hack to retrieve the media server port.
317
+ */
318
+ function useMediaServerPort ( { projectApi } : { projectApi : MapeoProjectApi } ) {
312
319
const { data, error, isRefetching } = useSuspenseQuery (
313
- attachmentUrlQueryOptions ( {
320
+ mediaServerPortQueryOptions ( {
314
321
projectApi,
315
- projectId,
316
- blobId,
317
322
} ) ,
318
323
)
319
324
0 commit comments