in lib/capi/src/lib/capitags.ts [15:54]
export function buildUriList(
tagIdList: string[],
capiBaseUrl: string,
capiKey: string,
tagIdListTail: string[] = [],
prevUrlList: string[] = [],
): string[] {
if (tagIdList.length == 0) {
//We reached the end!
return prevUrlList;
}
const joinedIdList = encodeURIComponent(tagIdList.join(','));
//page-size is 50 because the max tag ids that capi can accept for lookup at once is 50 therefore there cannot be more than that in the output
const testUri = `${capiBaseUrl}/tags?ids=${joinedIdList}&api-key=${capiKey}&page-size=50`;
//CAPI errors if we give it more than 50 tag ids
if (testUri.length > URL_MAX || tagIdList.length > 50) {
//uri is not usable, try again
const midpoint = tagIdList.length / 2;
const newTail = tagIdListTail.concat(tagIdList.slice(midpoint));
return buildUriList(
tagIdList.slice(0, midpoint),
capiBaseUrl,
capiKey,
newTail,
prevUrlList,
);
} else {
//we found a length that works.
return buildUriList(
tagIdListTail,
capiBaseUrl,
capiKey,
[],
prevUrlList.concat(testUri),
);
}
}