Merge pull request #1081 from Drakulix/nodeinfo-fix
Fix nodeinfo query on split-domain instances
This commit is contained in:
commit
c9818df37b
1 changed files with 19 additions and 6 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,12 +115,24 @@ 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' &&
|
||||||
if (nodeInfoUrl && nodeInfoUrl.startsWith(urlBase)) {
|
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) {
|
||||||
nodeInfo = await (await fetch(nodeInfoUrl)).json();
|
nodeInfo = await (await fetch(nodeInfoUrl)).json();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue