verbose/post.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2023-11-20 12:42:57 +01:00
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require 'lib/mastodon.php';
require 'lib/ckratelimit.php';
$resp=[
'ok'=>false,
'error'=>null,
'remaining'=>null,
'secstoreset'=>null,
'id'=>null
];
if (isset($_COOKIE['verbose_host']) && isset($_COOKIE['verbose_token']) && isset($_POST['visibility']) && in_array($_POST['visibility'],['public','unlisted','private','direct']) && isset($_POST['language']) && isset($_POST['status'])) {
$timeout=5;
$res=mastpost($_COOKIE['verbose_host'],$_COOKIE['verbose_token'],'/api/v1/statuses',$_POST,$timeout);
//$res=['ok'=>true, 'data'=>['id'=>999], 'error'=>'server exploded'];// test
if ($res['ok']) {
$resp['ok']=true;
$resp['id']=$res['data']['id'];
$rls=ckratelimit($res['headers']);
2024-09-28 06:06:22 +02:00
//$rls=['ok'=>true,'remaining'=>20,'sleep'=>5];// test
if ($rls['ok']) {
2023-11-20 12:42:57 +01:00
$resp['remaining']=$rls['remaining'];
$resp['secstoreset']=$rls['sleep'];
2023-11-20 12:42:57 +01:00
}
} else {
$resp['error']=htmlentities($res['error']);
}
} else {
$resp['error']='malformed POST request';
}
header('Content-Type: application/json');
$resp=json_encode($resp);
echo $resp;
//echo '<pre>'.print_r($_POST,true).'</pre>';
?>