Fix nodeinfo query just using the first entry
This commit is contained in:
parent
d6cd60fe6e
commit
90dff99608
1 changed files with 18 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { compareVersions, satisfies, validate } from 'compare-versions';
|
||||||
import { createRestAPIClient, createStreamingAPIClient } from 'masto';
|
import { createRestAPIClient, createStreamingAPIClient } from 'masto';
|
||||||
|
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
@ -114,11 +115,23 @@ export async function initInstance(client, instance) {
|
||||||
await fetch(`${urlBase}/.well-known/nodeinfo`)
|
await fetch(`${urlBase}/.well-known/nodeinfo`)
|
||||||
).json();
|
).json();
|
||||||
if (Array.isArray(wellKnown?.links)) {
|
if (Array.isArray(wellKnown?.links)) {
|
||||||
const nodeInfoUrl = wellKnown.links.find(
|
const schema = 'http://nodeinfo.diaspora.software/ns/schema/';
|
||||||
(link) =>
|
const nodeInfoUrl = wellKnown.links
|
||||||
typeof link.rel === 'string' &&
|
.filter(
|
||||||
link.rel.startsWith('http://nodeinfo.diaspora.software/ns/schema/'),
|
(link) =>
|
||||||
)?.href;
|
typeof link.rel === 'string' &&
|
||||||
|
link.rel.startsWith(schema) &&
|
||||||
|
validate(link.rel.slice(schema.length)),
|
||||||
|
)
|
||||||
|
.map((link) => {
|
||||||
|
let version = link.rel.slice(schema.length);
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
href: link.href,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.sort((a, b) => -compareVersions(a.version, b.version))
|
||||||
|
.find((x) => satisfies(x.version, '<=2'))?.href;
|
||||||
if (nodeInfoUrl) {
|
if (nodeInfoUrl) {
|
||||||
nodeInfo = await (await fetch(nodeInfoUrl)).json();
|
nodeInfo = await (await fetch(nodeInfoUrl)).json();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue