Fetch “extended description” from “/api/v1/instance/extended_description”; fetch “domain count” from “/api/v1/instance”

This commit is contained in:
pezcurrel 2024-08-25 19:01:32 +02:00
parent a7402bbb02
commit a143bad33d

View file

@ -419,17 +419,14 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
} else {
eecho(2,'«'.$opts['hostname'].'»: could not fetch instance info from API v2: '.$buf['emsg'].'.'.N);
}
// "domain count" is only listed by /api/v1/instance (extended description is retrievable also from /api/v1/instance/extended_description)
eecho(0,'«'.$opts['hostname'].'»: trying to fetch domain count and instance extended description from API v1...'.N);
// "domain count" is only listed by /api/v1/instance
eecho(0,'«'.$opts['hostname'].'»: trying to fetch domain count from API v1...'.N);
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json'],$opts['proxy']);
if ($buf['cont']!==false) {
ckratelimit($buf['headers'],"«{$opts['hostname']}»");
$buf=@json_decode($buf['cont'],true);
if (is_array($buf)) {
eecho(1,'«'.$opts['hostname'].'»: got instance info from API v1 :-)'.N);
//print_r($buf);
if (isset($buf['description']) && is_string($buf['description']) && !isempty($buf['description']))
$idata['LongDesc']=trim($buf['description']);
if (isset($buf['stats']['domain_count']) && is_int($buf['stats']['domain_count']))
$idata['DomainCount']=$buf['stats']['domain_count'];
} else {
@ -438,6 +435,21 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
} else {
eecho(2,'«'.$opts['hostname'].'»: could not fetch instance info from API v1: '.$buf['emsg'].'.'.N);
}
eecho(0,'«'.$opts['hostname'].'»: trying to fetch extended description from API v1...'.N);
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/extended_description',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json'],$opts['proxy']);
if ($buf['cont']!==false) {
ckratelimit($buf['headers'],"«{$opts['hostname']}»");
$buf=@json_decode($buf['cont'],true);
if (is_array($buf)) {
eecho(1,'«'.$opts['hostname'].'»: got extended description from API v1 :-)'.N);
if (isset($buf['content']) && is_string($buf['content']) && !isempty($buf['content']))
$idata['LongDesc']=trim($buf['content']);
} else {
eecho(2,'«'.$opts['hostname'].'»: instance extended description fetched from API v1 was not good JSON.'.N);
}
} else {
eecho(2,'«'.$opts['hostname'].'»: could not fetch instance extended description from API v1: '.$buf['emsg'].'.'.N);
}
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance domain blocks from API v1...'.N);
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/domain_blocks',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json'],$opts['proxy']);
if ($buf['cont']!==false) {