mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
List page meta links in the context of a space or change request
This commit is contained in:
@@ -321,11 +321,17 @@ async function resolvePageMetaLinks(
|
||||
pageId: string
|
||||
): Promise<PageMetaLinks> {
|
||||
const pageMetaLinks = await getDataOrNull(
|
||||
context.dataFetcher.listRevisionPageMetaLinks({
|
||||
spaceId: context.space.id,
|
||||
revisionId: context.revisionId,
|
||||
pageId,
|
||||
})
|
||||
context.changeRequest
|
||||
? context.dataFetcher.listChangeRequestPageMetaLinks({
|
||||
spaceId: context.space.id,
|
||||
changeRequestId: context.changeRequest.id,
|
||||
pageId,
|
||||
})
|
||||
: context.dataFetcher.listSpacePageMetaLinks({
|
||||
spaceId: context.space.id,
|
||||
|
||||
pageId,
|
||||
})
|
||||
);
|
||||
|
||||
if (pageMetaLinks) {
|
||||
|
||||
@@ -159,6 +159,21 @@ export function createDataFetcher(
|
||||
pageId: params.pageId,
|
||||
});
|
||||
},
|
||||
|
||||
listSpacePageMetaLinks(params) {
|
||||
return listSpacePageMetaLinks(input, {
|
||||
spaceId: params.spaceId,
|
||||
pageId: params.pageId,
|
||||
});
|
||||
},
|
||||
|
||||
listChangeRequestPageMetaLinks(params) {
|
||||
return listChangeRequestPageMetaLinks(input, {
|
||||
spaceId: params.spaceId,
|
||||
changeRequestId: params.changeRequestId,
|
||||
pageId: params.pageId,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -744,6 +759,64 @@ const listRevisionPageMetaLinks = cache(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* List all the meta links for a given page in a space.
|
||||
*/
|
||||
const listSpacePageMetaLinks = cache(
|
||||
async (input: DataFetcherInput, params: { spaceId: string; pageId: string }) => {
|
||||
'use cache';
|
||||
return wrapCacheDataFetcherError(async () => {
|
||||
return trace(
|
||||
`listSpacePageMetaLinks(${params.spaceId}, ${params.pageId})`,
|
||||
async () => {
|
||||
const api = apiClient(input);
|
||||
const res = await api.spaces.listSpacePageMetaLinks(
|
||||
params.spaceId,
|
||||
params.pageId,
|
||||
{
|
||||
...noCacheFetchOptions,
|
||||
}
|
||||
);
|
||||
cacheTag(...getCacheTagsFromResponse(res));
|
||||
cacheLife('days');
|
||||
return res.data;
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* List all the meta links for a given page in a change request.
|
||||
*/
|
||||
const listChangeRequestPageMetaLinks = cache(
|
||||
async (
|
||||
input: DataFetcherInput,
|
||||
params: { spaceId: string; changeRequestId: string; pageId: string }
|
||||
) => {
|
||||
'use cache';
|
||||
return wrapCacheDataFetcherError(async () => {
|
||||
return trace(
|
||||
`listChangeRequestPageMetaLinks(${params.spaceId}, ${params.changeRequestId}, ${params.pageId})`,
|
||||
async () => {
|
||||
const api = apiClient(input);
|
||||
const res = await api.spaces.listChangeRequestPageMetaLinks(
|
||||
params.spaceId,
|
||||
params.changeRequestId,
|
||||
params.pageId,
|
||||
{
|
||||
...noCacheFetchOptions,
|
||||
}
|
||||
);
|
||||
cacheTag(...getCacheTagsFromResponse(res));
|
||||
cacheLife('days');
|
||||
return res.data;
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new API client.
|
||||
*/
|
||||
|
||||
@@ -182,4 +182,21 @@ export interface GitBookDataFetcher {
|
||||
revisionId: string;
|
||||
pageId: string;
|
||||
}): Promise<DataFetcherResponse<api.RevisionPageMetaLinks>>;
|
||||
|
||||
/**
|
||||
* List change request meta links.
|
||||
*/
|
||||
listChangeRequestPageMetaLinks(params: {
|
||||
spaceId: string;
|
||||
changeRequestId: string;
|
||||
pageId: string;
|
||||
}): Promise<DataFetcherResponse<api.RevisionPageMetaLinks>>;
|
||||
|
||||
/**
|
||||
* List space meta links.
|
||||
*/
|
||||
listSpacePageMetaLinks(params: {
|
||||
spaceId: string;
|
||||
pageId: string;
|
||||
}): Promise<DataFetcherResponse<api.RevisionPageMetaLinks>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user