From a143bad33da7424edf247c752eff62a1d99f0890 Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Sun, 25 Aug 2024 19:01:32 +0200 Subject: [PATCH] =?UTF-8?q?Fetch=20=E2=80=9Cextended=20description?= =?UTF-8?q?=E2=80=9D=20from=20=E2=80=9C/api/v1/instance/extended=5Fdescrip?= =?UTF-8?q?tion=E2=80=9D;=20fetch=20=E2=80=9Cdomain=20count=E2=80=9D=20fro?= =?UTF-8?q?m=20=E2=80=9C/api/v1/instance=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/clitools/getinstinfo.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/web/clitools/getinstinfo.php b/web/clitools/getinstinfo.php index 63d2a45..77eaee5 100755 --- a/web/clitools/getinstinfo.php +++ b/web/clitools/getinstinfo.php @@ -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) {