mirror of
https://github.com/friendica/friendica
synced 2025-01-25 15:39:47 +00:00
Merge pull request #14675 from annando/get
New function to handle "get" requests
This commit is contained in:
commit
f6afc5a2bb
9 changed files with 52 additions and 37 deletions
|
@ -164,6 +164,19 @@ abstract class BaseModule implements ICanHandleRequests
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Module GET method to process submitted data
|
||||
*
|
||||
* Extend this method if the module is supposed to process GET requests.
|
||||
* Doesn't display any content
|
||||
*
|
||||
* @param string[] $request The $_REQUEST content
|
||||
* @return void
|
||||
*/
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -221,6 +234,9 @@ abstract class BaseModule implements ICanHandleRequests
|
|||
case Router::PUT:
|
||||
$this->put($request);
|
||||
return $this->response->generate();
|
||||
case Router::GET:
|
||||
$this->get($request);
|
||||
break;
|
||||
}
|
||||
|
||||
$timestamp = microtime(true);
|
||||
|
|
|
@ -99,7 +99,7 @@ class Lists extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon\Lists;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Circle;
|
||||
|
@ -40,7 +39,7 @@ class Accounts extends BaseApi
|
|||
$this->checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
$request = $this->getRequest([
|
||||
'account_ids' => [], // Array of account IDs to add to the list
|
||||
'account_ids' => [], // Array of account IDs to add to the list
|
||||
], $request);
|
||||
|
||||
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
||||
|
@ -53,7 +52,7 @@ class Accounts extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
|
|
@ -36,7 +36,7 @@ class Markers extends BaseApi
|
|||
}
|
||||
|
||||
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
|
||||
$marker = DBA::selectFirst('application-marker', [], $condition);
|
||||
$marker = DBA::selectFirst('application-marker', [], $condition);
|
||||
if (!empty($marker['version'])) {
|
||||
$version = $marker['version'] + 1;
|
||||
} else {
|
||||
|
@ -51,7 +51,7 @@ class Markers extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
@ -62,7 +62,7 @@ class Markers extends BaseApi
|
|||
|
||||
private function fetchTimelines(int $application_id, int $uid): \stdClass
|
||||
{
|
||||
$values = new \stdClass();
|
||||
$values = new \stdClass();
|
||||
$markers = DBA::select('application-marker', [], ['application-id' => $application_id, 'uid' => $uid]);
|
||||
while ($marker = DBA::fetch($markers)) {
|
||||
$values->{$marker['timeline']} = [
|
||||
|
|
|
@ -116,7 +116,7 @@ class Media extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
|
|
@ -49,9 +49,9 @@ class PushSubscription extends BaseApi
|
|||
$subscription = [
|
||||
'application-id' => $application['id'],
|
||||
'uid' => $uid,
|
||||
'endpoint' => $request['subscription']['endpoint'] ?? '',
|
||||
'endpoint' => $request['subscription']['endpoint'] ?? '',
|
||||
'pubkey' => $request['subscription']['keys']['p256dh'] ?? '',
|
||||
'secret' => $request['subscription']['keys']['auth'] ?? '',
|
||||
'secret' => $request['subscription']['keys']['auth'] ?? '',
|
||||
Notification::TYPE_FOLLOW => filter_var($request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_LIKE => filter_var($request['data']['alerts'][Notification::TYPE_LIKE] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_RESHARE => filter_var($request['data']['alerts'][Notification::TYPE_RESHARE] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
|
@ -133,7 +133,7 @@ class PushSubscription extends BaseApi
|
|||
$this->response->addJsonContent([]);
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = []): void
|
||||
protected function get(array $request = []): void
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_PUSH);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\App\Router;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
|
@ -48,7 +47,7 @@ class ScheduledStatuses extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
@ -58,10 +57,10 @@ class ScheduledStatuses extends BaseApi
|
|||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
'limit' => 20, // Max number of results to return. Defaults to 20.
|
||||
'max_id' => 0, // Return results older than ID
|
||||
'since_id' => 0, // Return results newer than ID
|
||||
'min_id' => 0, // Return results immediately newer than ID
|
||||
'limit' => 20, // Max number of results to return. Defaults to 20.
|
||||
'max_id' => 0, // Return results older than ID
|
||||
'since_id' => 0, // Return results newer than ID
|
||||
'min_id' => 0, // Return results immediately newer than ID
|
||||
], $request);
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => $request['limit']];
|
||||
|
@ -77,7 +76,7 @@ class ScheduledStatuses extends BaseApi
|
|||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
||||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
|
|
|
@ -64,18 +64,18 @@ class Statuses extends BaseApi
|
|||
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.');
|
||||
}
|
||||
|
||||
$item['title'] = '';
|
||||
$item['uid'] = $post['uid'];
|
||||
$item['body'] = $this->formatStatus($request['status'], $uid);
|
||||
$item['network'] = $post['network'];
|
||||
$item['gravity'] = $post['gravity'];
|
||||
$item['verb'] = $post['verb'];
|
||||
$item['allow_cid'] = $post['allow_cid'];
|
||||
$item['allow_gid'] = $post['allow_gid'];
|
||||
$item['deny_cid'] = $post['deny_cid'];
|
||||
$item['deny_gid'] = $post['deny_gid'];
|
||||
$item['app'] = $this->getApp();
|
||||
$item['sensitive'] = $request['sensitive'];
|
||||
$item['title'] = '';
|
||||
$item['uid'] = $post['uid'];
|
||||
$item['body'] = $this->formatStatus($request['status'], $uid);
|
||||
$item['network'] = $post['network'];
|
||||
$item['gravity'] = $post['gravity'];
|
||||
$item['verb'] = $post['verb'];
|
||||
$item['allow_cid'] = $post['allow_cid'];
|
||||
$item['allow_gid'] = $post['allow_gid'];
|
||||
$item['deny_cid'] = $post['deny_cid'];
|
||||
$item['deny_gid'] = $post['deny_gid'];
|
||||
$item['app'] = $this->getApp();
|
||||
$item['sensitive'] = $request['sensitive'];
|
||||
|
||||
if (!empty($request['language'])) {
|
||||
$item['language'] = json_encode([$request['language'] => 1]);
|
||||
|
@ -91,7 +91,7 @@ class Statuses extends BaseApi
|
|||
if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) {
|
||||
$item['title'] = $spoiler_text;
|
||||
} else {
|
||||
$item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];
|
||||
$item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];
|
||||
$item['content-warning'] = BBCode::toPlaintext($spoiler_text);
|
||||
}
|
||||
}
|
||||
|
@ -307,7 +307,8 @@ class Statuses extends BaseApi
|
|||
|
||||
if (!empty($request['scheduled_at'])) {
|
||||
$item['guid'] = Item::guid($item, true);
|
||||
$item['uri'] = Item::newURI($item['guid']);
|
||||
$item['uri'] = Item::newURI($item['guid']);
|
||||
|
||||
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
|
||||
if (empty($id)) {
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
|
@ -350,7 +351,7 @@ class Statuses extends BaseApi
|
|||
/**
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
|
@ -385,7 +386,7 @@ class Statuses extends BaseApi
|
|||
|
||||
foreach ($media_ids as $id) {
|
||||
if (DI::mstdnAttachment()->isAttach($id) && Attach::exists(['id' => substr($id, 7)])) {
|
||||
$attach = Attach::selectFirst([], ['id' => substr($id, 7)]);
|
||||
$attach = Attach::selectFirst([], ['id' => substr($id, 7)]);
|
||||
$attachment = [
|
||||
'type' => Post\Media::getType($attach['filetype']),
|
||||
'mimetype' => $attach['filetype'],
|
||||
|
@ -422,8 +423,8 @@ class Statuses extends BaseApi
|
|||
];
|
||||
|
||||
if (count($media) > 1) {
|
||||
$attachment['preview'] = DI::baseUrl() . '/photo/' . $media[1]['resource-id'] . '-' . $media[1]['scale'] . $ext;
|
||||
$attachment['preview-width'] = $media[1]['width'];
|
||||
$attachment['preview'] = DI::baseUrl() . '/photo/' . $media[1]['resource-id'] . '-' . $media[1]['scale'] . $ext;
|
||||
$attachment['preview-width'] = $media[1]['width'];
|
||||
$attachment['preview-height'] = $media[1]['height'];
|
||||
}
|
||||
$item['attachments'][] = $attachment;
|
||||
|
|
|
@ -18,7 +18,7 @@ use Friendica\Module\BaseApi;
|
|||
*/
|
||||
class Inbox extends DirectMessagesEndpoint
|
||||
{
|
||||
protected function rawContent(array $request = [])
|
||||
protected function get(array $request = [])
|
||||
{
|
||||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
|
Loading…
Add table
Reference in a new issue