Skip to content

Commit a091f3e

Browse files
committed
Update Nodeinfo crawler
1 parent 760a43f commit a091f3e

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

app/Console/Commands/FetchNodeinfoCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class FetchNodeinfoCommand extends Command
3434
'/nodeinfo/2.1',
3535
],
3636
'loops' => [
37-
'/nodeinfo/2.0',
3837
'/nodeinfo/2.1',
38+
'/nodeinfo/2.0',
3939
],
4040
'peertube' => [
4141
'/nodeinfo/2.0.json',
@@ -46,6 +46,16 @@ class FetchNodeinfoCommand extends Command
4646
'writefreely' => [
4747
'/api/nodeinfo',
4848
],
49+
'nodebb' => [
50+
'/nodeinfo/2.0',
51+
],
52+
'gotosocial' => [
53+
'/nodeinfo/2.1',
54+
'/nodeinfo/2.0',
55+
],
56+
'socialhome' => [
57+
'/nodeinfo/1.0',
58+
],
4959
];
5060

5161
/**

app/Services/NodeinfoCrawlerService.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ protected function buildBaseUrl(string $input, string $scheme = 'https'): string
7272
}
7373

7474
/**
75-
* Pick the best NodeInfo URL, preferring 2.1 over 2.0 (aka "v2").
75+
* Pick the best NodeInfo URL, preferring 2.2 > 2.1 > 2.0 > 1.1 > 1.0.
7676
*
7777
* Spec rels typically look like:
78+
* http://nodeinfo.diaspora.software/ns/schema/2.2
7879
* http://nodeinfo.diaspora.software/ns/schema/2.1
7980
* http://nodeinfo.diaspora.software/ns/schema/2.0
81+
* http://nodeinfo.diaspora.software/ns/schema/1.1
82+
* http://nodeinfo.diaspora.software/ns/schema/1.0
8083
*/
8184
protected function pickBestNodeinfoUrl(array $links): ?string
8285
{
@@ -93,10 +96,16 @@ protected function pickBestNodeinfoUrl(array $links): ?string
9396
}
9497

9598
$preferredRels = [
99+
'http://nodeinfo.diaspora.software/ns/schema/2.2',
100+
'https://nodeinfo.diaspora.software/ns/schema/2.2',
96101
'http://nodeinfo.diaspora.software/ns/schema/2.1',
97102
'https://nodeinfo.diaspora.software/ns/schema/2.1',
98103
'http://nodeinfo.diaspora.software/ns/schema/2.0',
99104
'https://nodeinfo.diaspora.software/ns/schema/2.0',
105+
'http://nodeinfo.diaspora.software/ns/schema/1.1',
106+
'https://nodeinfo.diaspora.software/ns/schema/1.1',
107+
'http://nodeinfo.diaspora.software/ns/schema/1.0',
108+
'https://nodeinfo.diaspora.software/ns/schema/1.0',
100109
];
101110

102111
foreach ($preferredRels as $rel) {
@@ -106,12 +115,12 @@ protected function pickBestNodeinfoUrl(array $links): ?string
106115
}
107116

108117
$candidates = array_values(array_filter($byRel, function ($href) {
109-
return preg_match('~/nodeinfo/(2\.[01])~', $href);
118+
return preg_match('~/nodeinfo/([12]\.[012])~', $href);
110119
}));
111120

112121
usort($candidates, function ($a, $b) {
113-
$va = preg_match('~/nodeinfo/(2\.[01])~', $a, $ma) ? $ma[1] : '0.0';
114-
$vb = preg_match('~/nodeinfo/(2\.[01])~', $b, $mb) ? $mb[1] : '0.0';
122+
$va = preg_match('~/nodeinfo/([12]\.[012])~', $a, $ma) ? $ma[1] : '0.0';
123+
$vb = preg_match('~/nodeinfo/([12]\.[012])~', $b, $mb) ? $mb[1] : '0.0';
115124

116125
return version_compare($vb, $va);
117126
});

0 commit comments

Comments
 (0)