@comapeo/core-react 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/hooks/projects.d.ts +4 -28
- package/dist/commonjs/hooks/projects.js +12 -9
- package/dist/commonjs/lib/react-query/projects.d.ts +5 -5
- package/dist/commonjs/lib/react-query/projects.js +9 -9
- package/dist/commonjs/lib/urls.d.ts +11 -8
- package/dist/commonjs/lib/urls.js +15 -21
- package/dist/esm/hooks/projects.d.ts +4 -28
- package/dist/esm/hooks/projects.js +13 -10
- package/dist/esm/lib/react-query/projects.d.ts +5 -5
- package/dist/esm/lib/react-query/projects.js +7 -7
- package/dist/esm/lib/urls.d.ts +11 -8
- package/dist/esm/lib/urls.js +15 -21
- package/package.json +1 -1
|
@@ -626,13 +626,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
626
626
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
627
627
|
path: string;
|
|
628
628
|
exportOptions: {
|
|
629
|
-
observations
|
|
630
|
-
/**
|
|
631
|
-
* Update the settings of a project.
|
|
632
|
-
*
|
|
633
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
634
|
-
*/
|
|
635
|
-
?: boolean;
|
|
629
|
+
observations?: boolean;
|
|
636
630
|
tracks?: boolean;
|
|
637
631
|
lang?: string;
|
|
638
632
|
};
|
|
@@ -640,13 +634,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
640
634
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
641
635
|
path: string;
|
|
642
636
|
exportOptions: {
|
|
643
|
-
observations
|
|
644
|
-
/**
|
|
645
|
-
* Update the settings of a project.
|
|
646
|
-
*
|
|
647
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
648
|
-
*/
|
|
649
|
-
?: boolean;
|
|
637
|
+
observations?: boolean;
|
|
650
638
|
tracks?: boolean;
|
|
651
639
|
lang?: string;
|
|
652
640
|
};
|
|
@@ -658,13 +646,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
658
646
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
659
647
|
path: string;
|
|
660
648
|
exportOptions: {
|
|
661
|
-
observations
|
|
662
|
-
/**
|
|
663
|
-
* Update the settings of a project.
|
|
664
|
-
*
|
|
665
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
666
|
-
*/
|
|
667
|
-
?: boolean;
|
|
649
|
+
observations?: boolean;
|
|
668
650
|
tracks?: boolean;
|
|
669
651
|
lang?: string;
|
|
670
652
|
};
|
|
@@ -672,13 +654,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
672
654
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
673
655
|
path: string;
|
|
674
656
|
exportOptions: {
|
|
675
|
-
observations
|
|
676
|
-
/**
|
|
677
|
-
* Update the settings of a project.
|
|
678
|
-
*
|
|
679
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
680
|
-
*/
|
|
681
|
-
?: boolean;
|
|
657
|
+
observations?: boolean;
|
|
682
658
|
tracks?: boolean;
|
|
683
659
|
lang?: string;
|
|
684
660
|
};
|
|
@@ -186,9 +186,13 @@ function useManyMembers({ projectId }) {
|
|
|
186
186
|
*/
|
|
187
187
|
function useIconUrl({ projectId, iconId, ...mimeBasedOpts }) {
|
|
188
188
|
const { data: projectApi } = useSingleProject({ projectId });
|
|
189
|
-
const { data:
|
|
190
|
-
const
|
|
191
|
-
|
|
189
|
+
const { data: serverOrigin, error, isRefetching, } = useMediaServerOrigin({ projectApi });
|
|
190
|
+
const iconUrl = (0, urls_js_1.getIconUrl)({
|
|
191
|
+
serverOrigin,
|
|
192
|
+
iconId,
|
|
193
|
+
projectId,
|
|
194
|
+
mimeBasedOpts,
|
|
195
|
+
});
|
|
192
196
|
return { data: iconUrl, error, isRefetching };
|
|
193
197
|
}
|
|
194
198
|
/**
|
|
@@ -244,17 +248,16 @@ function useIconUrl({ projectId, iconId, ...mimeBasedOpts }) {
|
|
|
244
248
|
*/
|
|
245
249
|
function useAttachmentUrl({ projectId, blobId, }) {
|
|
246
250
|
const { data: projectApi } = useSingleProject({ projectId });
|
|
247
|
-
const { data:
|
|
248
|
-
const
|
|
249
|
-
const blobUrl = (0, urls_js_1.getBlobUrl)(baseUrl, blobId);
|
|
251
|
+
const { data: serverOrigin, error, isRefetching, } = useMediaServerOrigin({ projectApi });
|
|
252
|
+
const blobUrl = (0, urls_js_1.getBlobUrl)({ serverOrigin, projectId, blobId });
|
|
250
253
|
return { data: blobUrl, error, isRefetching };
|
|
251
254
|
}
|
|
252
255
|
/**
|
|
253
256
|
* @internal
|
|
254
|
-
* Hack to retrieve the media server
|
|
257
|
+
* Hack to retrieve the media server origin (protocol + host).
|
|
255
258
|
*/
|
|
256
|
-
function
|
|
257
|
-
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.
|
|
259
|
+
function useMediaServerOrigin({ projectApi }) {
|
|
260
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, projects_js_1.mediaServerOriginQueryOptions)({
|
|
258
261
|
projectApi,
|
|
259
262
|
}));
|
|
260
263
|
return { data, error, isRefetching };
|
|
@@ -28,7 +28,7 @@ export declare function getDocumentCreatedByQueryKey({ projectId, originalVersio
|
|
|
28
28
|
* exposed right now, but it is the same for all projects, so no need for
|
|
29
29
|
* scoping the query key to the project
|
|
30
30
|
*/
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function getMediaServerOriginQueryKey(): readonly ["@comapeo/core-react", "media_server_origin"];
|
|
32
32
|
export declare function projectsQueryOptions({ clientApi, }: {
|
|
33
33
|
clientApi: MapeoClientApi;
|
|
34
34
|
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-manager.js", { with: { "resolution-mode": "import" } }).ListedProject[], Error, import("@comapeo/core/dist/mapeo-manager.js", { with: { "resolution-mode": "import" } }).ListedProject[], readonly ["@comapeo/core-react", "projects"]>, "queryFn"> & {
|
|
@@ -100,12 +100,12 @@ export declare function documentCreatedByQueryOptions({ projectApi, projectId, o
|
|
|
100
100
|
[dataTagErrorSymbol]: Error;
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
|
-
export declare function
|
|
103
|
+
export declare function mediaServerOriginQueryOptions({ projectApi, }: {
|
|
104
104
|
projectApi: MapeoProjectApi;
|
|
105
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "
|
|
106
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "
|
|
105
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "media_server_origin"]>, "queryFn"> & {
|
|
106
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "media_server_origin"], never> | undefined;
|
|
107
107
|
} & {
|
|
108
|
-
queryKey: readonly ["@comapeo/core-react", "
|
|
108
|
+
queryKey: readonly ["@comapeo/core-react", "media_server_origin"] & {
|
|
109
109
|
[dataTagSymbol]: string;
|
|
110
110
|
[dataTagErrorSymbol]: Error;
|
|
111
111
|
};
|
|
@@ -7,7 +7,7 @@ exports.getProjectRoleQueryKey = getProjectRoleQueryKey;
|
|
|
7
7
|
exports.getMembersQueryKey = getMembersQueryKey;
|
|
8
8
|
exports.getMemberByIdQueryKey = getMemberByIdQueryKey;
|
|
9
9
|
exports.getDocumentCreatedByQueryKey = getDocumentCreatedByQueryKey;
|
|
10
|
-
exports.
|
|
10
|
+
exports.getMediaServerOriginQueryKey = getMediaServerOriginQueryKey;
|
|
11
11
|
exports.projectsQueryOptions = projectsQueryOptions;
|
|
12
12
|
exports.projectByIdQueryOptions = projectByIdQueryOptions;
|
|
13
13
|
exports.projectSettingsQueryOptions = projectSettingsQueryOptions;
|
|
@@ -15,7 +15,7 @@ exports.projectMembersQueryOptions = projectMembersQueryOptions;
|
|
|
15
15
|
exports.projectMemberByIdQueryOptions = projectMemberByIdQueryOptions;
|
|
16
16
|
exports.projectOwnRoleQueryOptions = projectOwnRoleQueryOptions;
|
|
17
17
|
exports.documentCreatedByQueryOptions = documentCreatedByQueryOptions;
|
|
18
|
-
exports.
|
|
18
|
+
exports.mediaServerOriginQueryOptions = mediaServerOriginQueryOptions;
|
|
19
19
|
exports.addServerPeerMutationOptions = addServerPeerMutationOptions;
|
|
20
20
|
exports.removeServerPeerMutationOptions = removeServerPeerMutationOptions;
|
|
21
21
|
exports.createProjectMutationOptions = createProjectMutationOptions;
|
|
@@ -64,8 +64,8 @@ function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
|
|
|
64
64
|
* exposed right now, but it is the same for all projects, so no need for
|
|
65
65
|
* scoping the query key to the project
|
|
66
66
|
*/
|
|
67
|
-
function
|
|
68
|
-
return [shared_js_1.ROOT_QUERY_KEY, '
|
|
67
|
+
function getMediaServerOriginQueryKey() {
|
|
68
|
+
return [shared_js_1.ROOT_QUERY_KEY, 'media_server_origin'];
|
|
69
69
|
}
|
|
70
70
|
function projectsQueryOptions({ clientApi, }) {
|
|
71
71
|
return (0, react_query_1.queryOptions)({
|
|
@@ -142,17 +142,17 @@ const FAKE_BLOB_ID = {
|
|
|
142
142
|
name: 'name',
|
|
143
143
|
driveId: 'drive-id',
|
|
144
144
|
};
|
|
145
|
-
function
|
|
145
|
+
function mediaServerOriginQueryOptions({ projectApi, }) {
|
|
146
146
|
return (0, react_query_1.queryOptions)({
|
|
147
147
|
...(0, shared_js_1.baseQueryOptions)(),
|
|
148
|
-
// HACK: The server doesn't yet expose a method to get its
|
|
149
|
-
// the existing $blobs.getUrl() to get the
|
|
148
|
+
// HACK: The server doesn't yet expose a method to get its origin, so we use
|
|
149
|
+
// the existing $blobs.getUrl() to get the origin with a fake BlobId. The origin
|
|
150
150
|
// is the same regardless of the blobId, so it's not necessary to include it
|
|
151
151
|
// as a dep for the query key.
|
|
152
|
-
queryKey:
|
|
152
|
+
queryKey: getMediaServerOriginQueryKey(),
|
|
153
153
|
queryFn: async () => {
|
|
154
154
|
const url = await projectApi.$blobs.getUrl(FAKE_BLOB_ID);
|
|
155
|
-
return new URL(url).
|
|
155
|
+
return new URL(url).origin;
|
|
156
156
|
},
|
|
157
157
|
staleTime: 'static',
|
|
158
158
|
gcTime: Infinity,
|
|
@@ -2,11 +2,14 @@ import type { BlobApi, IconApi } from '@comapeo/core';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get a url for a blob based on its BlobId
|
|
4
4
|
*/
|
|
5
|
-
export declare function getBlobUrl(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export declare function getBlobUrl({ serverOrigin, projectId, blobId, }: {
|
|
6
|
+
serverOrigin: string;
|
|
7
|
+
projectId: string;
|
|
8
|
+
blobId: BlobApi.BlobId;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function getIconUrl({ serverOrigin, iconId, projectId, mimeBasedOpts, }: {
|
|
11
|
+
serverOrigin: string;
|
|
12
|
+
iconId: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
mimeBasedOpts: IconApi.BitmapOpts | IconApi.SvgOpts;
|
|
15
|
+
}): string;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// TODO: Move these into a separate "@comapeo/asset-server" module which can
|
|
3
3
|
// export them to be imported directly in a client.
|
|
4
|
+
//
|
|
5
|
+
// NB: The URL construction is fragile right now - it must match the
|
|
6
|
+
// implementation in the @comapeo/core fastify plugins
|
|
7
|
+
// [blobServerPlugin](https://github.com/digidem/comapeo-core/blob/main/src/fastify-plugins/blobs.js)
|
|
8
|
+
// and
|
|
9
|
+
// [iconServerPlugin](https://github.com/digidem/comapeo-core/blob/main/src/fastify-plugins/icons.js)
|
|
4
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
11
|
exports.getBlobUrl = getBlobUrl;
|
|
6
12
|
exports.getIconUrl = getIconUrl;
|
|
@@ -11,34 +17,22 @@ const MIME_TO_EXTENSION = {
|
|
|
11
17
|
/**
|
|
12
18
|
* Get a url for a blob based on its BlobId
|
|
13
19
|
*/
|
|
14
|
-
function getBlobUrl(
|
|
20
|
+
function getBlobUrl({ serverOrigin, projectId, blobId, }) {
|
|
15
21
|
const { driveId, type, variant, name } = blobId;
|
|
16
|
-
|
|
17
|
-
baseUrl += '/';
|
|
18
|
-
}
|
|
19
|
-
return baseUrl + `${driveId}/${type}/${variant}/${name}`;
|
|
22
|
+
return `${serverOrigin}/blobs/${projectId}/${driveId}/${type}/${variant}/${name}`;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
* @returns {Promise<string>}
|
|
26
|
-
*/
|
|
27
|
-
function getIconUrl(baseUrl, iconId, opts) {
|
|
28
|
-
if (!baseUrl.endsWith('/')) {
|
|
29
|
-
baseUrl += '/';
|
|
30
|
-
}
|
|
31
|
-
const mimeExtension = MIME_TO_EXTENSION[opts.mimeType];
|
|
32
|
-
const pixelDensity = opts.mimeType === 'image/svg+xml' ||
|
|
24
|
+
function getIconUrl({ serverOrigin, iconId, projectId, mimeBasedOpts, }) {
|
|
25
|
+
const mimeExtension = MIME_TO_EXTENSION[mimeBasedOpts.mimeType];
|
|
26
|
+
const pixelDensity = mimeBasedOpts.mimeType === 'image/svg+xml' ||
|
|
33
27
|
// if the pixel density is 1, we can omit the density suffix in the resulting url
|
|
34
28
|
// and assume the pixel density is 1 for applicable mime types when using the url
|
|
35
|
-
|
|
29
|
+
mimeBasedOpts.pixelDensity === 1
|
|
36
30
|
? undefined
|
|
37
|
-
:
|
|
38
|
-
return (
|
|
31
|
+
: mimeBasedOpts.pixelDensity;
|
|
32
|
+
return (`${serverOrigin}/icons/${projectId}/` +
|
|
39
33
|
constructIconPath({
|
|
40
34
|
pixelDensity,
|
|
41
|
-
size:
|
|
35
|
+
size: mimeBasedOpts.size,
|
|
42
36
|
extension: mimeExtension,
|
|
43
37
|
iconId,
|
|
44
38
|
}));
|
|
@@ -626,13 +626,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
626
626
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
627
627
|
path: string;
|
|
628
628
|
exportOptions: {
|
|
629
|
-
observations
|
|
630
|
-
/**
|
|
631
|
-
* Update the settings of a project.
|
|
632
|
-
*
|
|
633
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
634
|
-
*/
|
|
635
|
-
?: boolean;
|
|
629
|
+
observations?: boolean;
|
|
636
630
|
tracks?: boolean;
|
|
637
631
|
lang?: string;
|
|
638
632
|
};
|
|
@@ -640,13 +634,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
640
634
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
641
635
|
path: string;
|
|
642
636
|
exportOptions: {
|
|
643
|
-
observations
|
|
644
|
-
/**
|
|
645
|
-
* Update the settings of a project.
|
|
646
|
-
*
|
|
647
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
648
|
-
*/
|
|
649
|
-
?: boolean;
|
|
637
|
+
observations?: boolean;
|
|
650
638
|
tracks?: boolean;
|
|
651
639
|
lang?: string;
|
|
652
640
|
};
|
|
@@ -658,13 +646,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
658
646
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
659
647
|
path: string;
|
|
660
648
|
exportOptions: {
|
|
661
|
-
observations
|
|
662
|
-
/**
|
|
663
|
-
* Update the settings of a project.
|
|
664
|
-
*
|
|
665
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
666
|
-
*/
|
|
667
|
-
?: boolean;
|
|
649
|
+
observations?: boolean;
|
|
668
650
|
tracks?: boolean;
|
|
669
651
|
lang?: string;
|
|
670
652
|
};
|
|
@@ -672,13 +654,7 @@ export declare function useExportGeoJSON({ projectId }: {
|
|
|
672
654
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
673
655
|
path: string;
|
|
674
656
|
exportOptions: {
|
|
675
|
-
observations
|
|
676
|
-
/**
|
|
677
|
-
* Update the settings of a project.
|
|
678
|
-
*
|
|
679
|
-
* @param opts.projectId Public ID of the project to apply changes to.
|
|
680
|
-
*/
|
|
681
|
-
?: boolean;
|
|
657
|
+
observations?: boolean;
|
|
682
658
|
tracks?: boolean;
|
|
683
659
|
lang?: string;
|
|
684
660
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
2
|
import { useSyncExternalStore } from 'react';
|
|
3
|
-
import { addServerPeerMutationOptions, connectSyncServersMutationOptions, createBlobMutationOptions, createProjectMutationOptions, disconnectSyncServersMutationOptions, documentCreatedByQueryOptions, exportGeoJSONMutationOptions, exportZipFileMutationOptions, importProjectConfigMutationOptions, leaveProjectMutationOptions,
|
|
3
|
+
import { addServerPeerMutationOptions, connectSyncServersMutationOptions, createBlobMutationOptions, createProjectMutationOptions, disconnectSyncServersMutationOptions, documentCreatedByQueryOptions, exportGeoJSONMutationOptions, exportZipFileMutationOptions, importProjectConfigMutationOptions, leaveProjectMutationOptions, mediaServerOriginQueryOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectOwnRoleQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, removeServerPeerMutationOptions, setAutostopDataSyncTimeoutMutationOptions, startSyncMutationOptions, stopSyncMutationOptions, updateProjectSettingsMutationOptions, } from '../lib/react-query/projects.js';
|
|
4
4
|
import { SyncStore } from '../lib/sync.js';
|
|
5
5
|
import { getBlobUrl, getIconUrl } from '../lib/urls.js';
|
|
6
6
|
import { useClientApi } from './client.js';
|
|
@@ -159,9 +159,13 @@ export function useManyMembers({ projectId }) {
|
|
|
159
159
|
*/
|
|
160
160
|
export function useIconUrl({ projectId, iconId, ...mimeBasedOpts }) {
|
|
161
161
|
const { data: projectApi } = useSingleProject({ projectId });
|
|
162
|
-
const { data:
|
|
163
|
-
const
|
|
164
|
-
|
|
162
|
+
const { data: serverOrigin, error, isRefetching, } = useMediaServerOrigin({ projectApi });
|
|
163
|
+
const iconUrl = getIconUrl({
|
|
164
|
+
serverOrigin,
|
|
165
|
+
iconId,
|
|
166
|
+
projectId,
|
|
167
|
+
mimeBasedOpts,
|
|
168
|
+
});
|
|
165
169
|
return { data: iconUrl, error, isRefetching };
|
|
166
170
|
}
|
|
167
171
|
/**
|
|
@@ -217,17 +221,16 @@ export function useIconUrl({ projectId, iconId, ...mimeBasedOpts }) {
|
|
|
217
221
|
*/
|
|
218
222
|
export function useAttachmentUrl({ projectId, blobId, }) {
|
|
219
223
|
const { data: projectApi } = useSingleProject({ projectId });
|
|
220
|
-
const { data:
|
|
221
|
-
const
|
|
222
|
-
const blobUrl = getBlobUrl(baseUrl, blobId);
|
|
224
|
+
const { data: serverOrigin, error, isRefetching, } = useMediaServerOrigin({ projectApi });
|
|
225
|
+
const blobUrl = getBlobUrl({ serverOrigin, projectId, blobId });
|
|
223
226
|
return { data: blobUrl, error, isRefetching };
|
|
224
227
|
}
|
|
225
228
|
/**
|
|
226
229
|
* @internal
|
|
227
|
-
* Hack to retrieve the media server
|
|
230
|
+
* Hack to retrieve the media server origin (protocol + host).
|
|
228
231
|
*/
|
|
229
|
-
function
|
|
230
|
-
const { data, error, isRefetching } = useSuspenseQuery(
|
|
232
|
+
function useMediaServerOrigin({ projectApi }) {
|
|
233
|
+
const { data, error, isRefetching } = useSuspenseQuery(mediaServerOriginQueryOptions({
|
|
231
234
|
projectApi,
|
|
232
235
|
}));
|
|
233
236
|
return { data, error, isRefetching };
|
|
@@ -28,7 +28,7 @@ export declare function getDocumentCreatedByQueryKey({ projectId, originalVersio
|
|
|
28
28
|
* exposed right now, but it is the same for all projects, so no need for
|
|
29
29
|
* scoping the query key to the project
|
|
30
30
|
*/
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function getMediaServerOriginQueryKey(): readonly ["@comapeo/core-react", "media_server_origin"];
|
|
32
32
|
export declare function projectsQueryOptions({ clientApi, }: {
|
|
33
33
|
clientApi: MapeoClientApi;
|
|
34
34
|
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-manager.js").ListedProject[], Error, import("@comapeo/core/dist/mapeo-manager.js").ListedProject[], readonly ["@comapeo/core-react", "projects"]>, "queryFn"> & {
|
|
@@ -100,12 +100,12 @@ export declare function documentCreatedByQueryOptions({ projectApi, projectId, o
|
|
|
100
100
|
[dataTagErrorSymbol]: Error;
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
|
-
export declare function
|
|
103
|
+
export declare function mediaServerOriginQueryOptions({ projectApi, }: {
|
|
104
104
|
projectApi: MapeoProjectApi;
|
|
105
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "
|
|
106
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "
|
|
105
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "media_server_origin"]>, "queryFn"> & {
|
|
106
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "media_server_origin"], never> | undefined;
|
|
107
107
|
} & {
|
|
108
|
-
queryKey: readonly ["@comapeo/core-react", "
|
|
108
|
+
queryKey: readonly ["@comapeo/core-react", "media_server_origin"] & {
|
|
109
109
|
[dataTagSymbol]: string;
|
|
110
110
|
[dataTagErrorSymbol]: Error;
|
|
111
111
|
};
|
|
@@ -32,8 +32,8 @@ export function getDocumentCreatedByQueryKey({ projectId, originalVersionId, })
|
|
|
32
32
|
* exposed right now, but it is the same for all projects, so no need for
|
|
33
33
|
* scoping the query key to the project
|
|
34
34
|
*/
|
|
35
|
-
export function
|
|
36
|
-
return [ROOT_QUERY_KEY, '
|
|
35
|
+
export function getMediaServerOriginQueryKey() {
|
|
36
|
+
return [ROOT_QUERY_KEY, 'media_server_origin'];
|
|
37
37
|
}
|
|
38
38
|
export function projectsQueryOptions({ clientApi, }) {
|
|
39
39
|
return queryOptions({
|
|
@@ -110,17 +110,17 @@ const FAKE_BLOB_ID = {
|
|
|
110
110
|
name: 'name',
|
|
111
111
|
driveId: 'drive-id',
|
|
112
112
|
};
|
|
113
|
-
export function
|
|
113
|
+
export function mediaServerOriginQueryOptions({ projectApi, }) {
|
|
114
114
|
return queryOptions({
|
|
115
115
|
...baseQueryOptions(),
|
|
116
|
-
// HACK: The server doesn't yet expose a method to get its
|
|
117
|
-
// the existing $blobs.getUrl() to get the
|
|
116
|
+
// HACK: The server doesn't yet expose a method to get its origin, so we use
|
|
117
|
+
// the existing $blobs.getUrl() to get the origin with a fake BlobId. The origin
|
|
118
118
|
// is the same regardless of the blobId, so it's not necessary to include it
|
|
119
119
|
// as a dep for the query key.
|
|
120
|
-
queryKey:
|
|
120
|
+
queryKey: getMediaServerOriginQueryKey(),
|
|
121
121
|
queryFn: async () => {
|
|
122
122
|
const url = await projectApi.$blobs.getUrl(FAKE_BLOB_ID);
|
|
123
|
-
return new URL(url).
|
|
123
|
+
return new URL(url).origin;
|
|
124
124
|
},
|
|
125
125
|
staleTime: 'static',
|
|
126
126
|
gcTime: Infinity,
|
package/dist/esm/lib/urls.d.ts
CHANGED
|
@@ -2,11 +2,14 @@ import type { BlobApi, IconApi } from '@comapeo/core';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get a url for a blob based on its BlobId
|
|
4
4
|
*/
|
|
5
|
-
export declare function getBlobUrl(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export declare function getBlobUrl({ serverOrigin, projectId, blobId, }: {
|
|
6
|
+
serverOrigin: string;
|
|
7
|
+
projectId: string;
|
|
8
|
+
blobId: BlobApi.BlobId;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function getIconUrl({ serverOrigin, iconId, projectId, mimeBasedOpts, }: {
|
|
11
|
+
serverOrigin: string;
|
|
12
|
+
iconId: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
mimeBasedOpts: IconApi.BitmapOpts | IconApi.SvgOpts;
|
|
15
|
+
}): string;
|
package/dist/esm/lib/urls.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// TODO: Move these into a separate "@comapeo/asset-server" module which can
|
|
2
2
|
// export them to be imported directly in a client.
|
|
3
|
+
//
|
|
4
|
+
// NB: The URL construction is fragile right now - it must match the
|
|
5
|
+
// implementation in the @comapeo/core fastify plugins
|
|
6
|
+
// [blobServerPlugin](https://github.com/digidem/comapeo-core/blob/main/src/fastify-plugins/blobs.js)
|
|
7
|
+
// and
|
|
8
|
+
// [iconServerPlugin](https://github.com/digidem/comapeo-core/blob/main/src/fastify-plugins/icons.js)
|
|
3
9
|
const MIME_TO_EXTENSION = {
|
|
4
10
|
'image/png': '.png',
|
|
5
11
|
'image/svg+xml': '.svg',
|
|
@@ -7,34 +13,22 @@ const MIME_TO_EXTENSION = {
|
|
|
7
13
|
/**
|
|
8
14
|
* Get a url for a blob based on its BlobId
|
|
9
15
|
*/
|
|
10
|
-
export function getBlobUrl(
|
|
16
|
+
export function getBlobUrl({ serverOrigin, projectId, blobId, }) {
|
|
11
17
|
const { driveId, type, variant, name } = blobId;
|
|
12
|
-
|
|
13
|
-
baseUrl += '/';
|
|
14
|
-
}
|
|
15
|
-
return baseUrl + `${driveId}/${type}/${variant}/${name}`;
|
|
18
|
+
return `${serverOrigin}/blobs/${projectId}/${driveId}/${type}/${variant}/${name}`;
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @returns {Promise<string>}
|
|
22
|
-
*/
|
|
23
|
-
export function getIconUrl(baseUrl, iconId, opts) {
|
|
24
|
-
if (!baseUrl.endsWith('/')) {
|
|
25
|
-
baseUrl += '/';
|
|
26
|
-
}
|
|
27
|
-
const mimeExtension = MIME_TO_EXTENSION[opts.mimeType];
|
|
28
|
-
const pixelDensity = opts.mimeType === 'image/svg+xml' ||
|
|
20
|
+
export function getIconUrl({ serverOrigin, iconId, projectId, mimeBasedOpts, }) {
|
|
21
|
+
const mimeExtension = MIME_TO_EXTENSION[mimeBasedOpts.mimeType];
|
|
22
|
+
const pixelDensity = mimeBasedOpts.mimeType === 'image/svg+xml' ||
|
|
29
23
|
// if the pixel density is 1, we can omit the density suffix in the resulting url
|
|
30
24
|
// and assume the pixel density is 1 for applicable mime types when using the url
|
|
31
|
-
|
|
25
|
+
mimeBasedOpts.pixelDensity === 1
|
|
32
26
|
? undefined
|
|
33
|
-
:
|
|
34
|
-
return (
|
|
27
|
+
: mimeBasedOpts.pixelDensity;
|
|
28
|
+
return (`${serverOrigin}/icons/${projectId}/` +
|
|
35
29
|
constructIconPath({
|
|
36
30
|
pixelDensity,
|
|
37
|
-
size:
|
|
31
|
+
size: mimeBasedOpts.size,
|
|
38
32
|
extension: mimeExtension,
|
|
39
33
|
iconId,
|
|
40
34
|
}));
|