Fix the return type in MastodonApiClient::getNextPage

This commit is contained in:
Natty 2023-10-31 17:21:11 +01:00
parent 473be10607
commit 9c681cd4f2

View file

@ -360,7 +360,7 @@ class MastodonApiClient extends ApiClient {
/** /**
* @param {Headers} headers * @param {Headers} headers
* @return {URL?} request URL for next page or null * @return {URL | null} request URL for next page or null
*/ */
static getNextPage(headers) static getNextPage(headers)
{ {
@ -379,10 +379,14 @@ class MastodonApiClient extends ApiClient {
return null; return null;
for (const link of links.split(",")) { for (const link of links.split(",")) {
const p = link.split(";").map(s => s.trim()); const [url_raw, rel] = link.split(";").map(s => s.trim());
if (p.length == 2 && p[1] === 'rel="next"') { if (url_raw && rel === 'rel="next"') {
// Remove enclosing angle brackets <...> try {
return p[0].substring(1, p[0].length - 1); // Remove enclosing angle brackets <...>
return new URL(url_raw.substring(1, url_raw.length - 1));
} catch (e) {
console.warn("Invalid URL: ", e);
}
} }
} }