Merge pull request #10220 from annando/api-timelines
API: We now support two more timeline api endpoints
This commit is contained in:
commit
a5d7662c97
|
@ -17,6 +17,7 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
|
|||
|
||||
- [`GET /api/v1//accounts/:id`](https://docs.joinmastodon.org/methods/accounts/#retrieve-information)
|
||||
- [`GET /api/v1//accounts/:id/statuses`](https://docs.joinmastodon.org/methods/accounts/#retrieve-information)
|
||||
- [`GET /api/v1//accounts/verify_credentials`](https://docs.joinmastodon.org/methods/accounts)
|
||||
- [`GET /api/v1/custom_emojis`](https://docs.joinmastodon.org/methods/instance/custom_emojis/)
|
||||
- Doesn't return unicode emojis since they aren't using an image URL
|
||||
|
||||
|
@ -36,7 +37,12 @@ These endpoints use the [Mastodon API entities](https://docs.joinmastodon.org/en
|
|||
|
||||
- [`GET /api/v1/instance`](https://docs.joinmastodon.org/methods/instance#fetch-instance)
|
||||
- [`GET /api/v1/instance/peers`](https://docs.joinmastodon.org/methods/instance#list-of-connected-domains)
|
||||
- [`GET /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/)
|
||||
- [`GET /api/v1/suggestions`](https://docs.joinmastodon.org/methods/accounts/suggestions/)
|
||||
- [`GET /api/v1/timelines/home`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
- [`GET /api/v1/timelines/list/:id`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
- [`GET /api/v1/timelines/public`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
- [`GET /api/v1/timelines/tag/:hashtag`](https://docs.joinmastodon.org/methods/timelines/)
|
||||
- [`GET /api/v1/trends`](https://docs.joinmastodon.org/methods/instance/trends/)
|
||||
|
||||
## Non-implemented endpoints
|
||||
|
|
|
@ -276,11 +276,23 @@ class Module
|
|||
|
||||
$profiler->set(microtime(true) - $timestamp, 'init');
|
||||
|
||||
if ($server['REQUEST_METHOD'] === 'POST') {
|
||||
if ($server['REQUEST_METHOD'] === Router::DELETE) {
|
||||
call_user_func([$this->module_class, 'delete'], $this->module_parameters);
|
||||
}
|
||||
|
||||
if ($server['REQUEST_METHOD'] === Router::PATCH) {
|
||||
call_user_func([$this->module_class, 'patch'], $this->module_parameters);
|
||||
}
|
||||
|
||||
if ($server['REQUEST_METHOD'] === Router::POST) {
|
||||
Core\Hook::callAll($this->module . '_mod_post', $post);
|
||||
call_user_func([$this->module_class, 'post'], $this->module_parameters);
|
||||
}
|
||||
|
||||
if ($server['REQUEST_METHOD'] === Router::PUT) {
|
||||
call_user_func([$this->module_class, 'put'], $this->module_parameters);
|
||||
}
|
||||
|
||||
Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder);
|
||||
call_user_func([$this->module_class, 'afterpost'], $this->module_parameters);
|
||||
|
||||
|
|
|
@ -72,6 +72,26 @@ abstract class BaseModule
|
|||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Module DELETE method to process submitted data
|
||||
*
|
||||
* Extend this method if the module is supposed to process DELETE requests.
|
||||
* Doesn't display any content
|
||||
*/
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Module PATCH method to process submitted data
|
||||
*
|
||||
* Extend this method if the module is supposed to process PATCH requests.
|
||||
* Doesn't display any content
|
||||
*/
|
||||
public static function patch(array $parameters = [])
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Module POST method to process submitted data
|
||||
*
|
||||
|
@ -92,6 +112,16 @@ abstract class BaseModule
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Module PUT method to process submitted data
|
||||
*
|
||||
* Extend this method if the module is supposed to process PUT requests.
|
||||
* Doesn't display any content
|
||||
*/
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions used to protect against Cross-Site Request Forgery
|
||||
* The security token has to base on at least one value that an attacker can't know - here it's the session ID and the private key.
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Factory\Api\Mastodon;
|
|||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -60,9 +61,9 @@ class Status extends BaseFactory
|
|||
*/
|
||||
public function createFromUriId(int $uriId, $uid = 0)
|
||||
{
|
||||
$fields = ['uri-id', 'uid', 'author-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created',
|
||||
$fields = ['uri-id', 'uid', 'author-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
|
||||
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => $uid]);
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
|
@ -70,21 +71,21 @@ class Status extends BaseFactory
|
|||
$account = DI::mstdnAccount()->createFromContactId($item['author-id']);
|
||||
|
||||
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
|
||||
Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]),
|
||||
Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]),
|
||||
Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)])
|
||||
Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT], [], false),
|
||||
Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)], [], false),
|
||||
Post::count(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)], [], false)
|
||||
);
|
||||
|
||||
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
|
||||
Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]),
|
||||
Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]),
|
||||
Post\ThreadUser::getIgnored($uriId, $item['uid']),
|
||||
Post\ThreadUser::getIgnored($uriId, $uid),
|
||||
(bool)$item['starred'],
|
||||
Post\ThreadUser::getPinned($uriId, $item['uid'])
|
||||
Post\ThreadUser::getPinned($uriId, $uid)
|
||||
);
|
||||
|
||||
$sensitive = DBA::exists('tag-view', ['uri-id' => $uriId, 'name' => 'nsfw']);
|
||||
$application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?? '');
|
||||
$application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: ContactSelector::networkToName($item['network'], $item['author-link']));
|
||||
$mentions = DI::mstdnMention()->createFromUriId($uriId);
|
||||
$tags = DI::mstdnTag()->createFromUriId($uriId);
|
||||
|
||||
|
@ -95,7 +96,7 @@ class Status extends BaseFactory
|
|||
|
||||
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
|
||||
$reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
|
||||
$reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]);
|
||||
$reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $uid]]);
|
||||
$item['title'] = $reshared_item['title'] ?? $item['title'];
|
||||
$item['body'] = $reshared_item['body'] ?? $item['body'];
|
||||
} else {
|
||||
|
|
|
@ -127,12 +127,13 @@ class Post
|
|||
* Check if post data exists
|
||||
*
|
||||
* @param array $condition array of fields for condition
|
||||
* @param bool $user_mode true = post-user-view, false = post-view
|
||||
*
|
||||
* @return boolean Are there rows for that condition?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function exists($condition) {
|
||||
return DBA::exists('post-user-view', $condition);
|
||||
public static function exists($condition, bool $user_mode = true) {
|
||||
return DBA::exists($user_mode ? 'post-user-view' : 'post-view', $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,6 +141,7 @@ class Post
|
|||
*
|
||||
* @param array $condition array of fields for condition
|
||||
* @param array $params Array of several parameters
|
||||
* @param bool $user_mode true = post-user-view, false = post-view
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
|
@ -151,9 +153,9 @@ class Post
|
|||
* $count = Post::count($condition);
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function count(array $condition = [], array $params = [])
|
||||
public static function count(array $condition = [], array $params = [], bool $user_mode = true)
|
||||
{
|
||||
return DBA::count('post-user-view', $condition, $params);
|
||||
return DBA::count($user_mode ? 'post-user-view' : 'post-view', $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Model\Post;
|
||||
|
||||
use Friendica\Content\PageInfo;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
|
@ -67,6 +66,11 @@ class Media
|
|||
return;
|
||||
}
|
||||
|
||||
if (DBA::exists('post-media', ['uri-id' => $media['uri-id'], 'preview' => $media['url']])) {
|
||||
Logger::info('Media already exists as preview', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'callstack' => System::callstack()]);
|
||||
return;
|
||||
}
|
||||
|
||||
// "document" has got the lowest priority. So when the same file is both attached as document
|
||||
// and embedded as picture then we only store the picture or replace the document
|
||||
$found = DBA::selectFirst('post-media', ['type'], ['uri-id' => $media['uri-id'], 'url' => $media['url']]);
|
||||
|
@ -499,6 +503,7 @@ class Media
|
|||
|
||||
$height = 0;
|
||||
$selected = '';
|
||||
$previews = [];
|
||||
|
||||
foreach ($media as $medium) {
|
||||
foreach ($links as $link) {
|
||||
|
@ -507,6 +512,17 @@ class Media
|
|||
}
|
||||
}
|
||||
|
||||
// Avoid adding separate media entries for previews
|
||||
foreach ($previews as $preview) {
|
||||
if (Strings::compareLink($preview, $medium['url'])) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($medium['preview'])) {
|
||||
$previews[] = $medium['preview'];
|
||||
}
|
||||
|
||||
$type = explode('/', current(explode(';', $medium['mimetype'])));
|
||||
if (count($type) < 2) {
|
||||
Logger::info('Unknown MimeType', ['type' => $type, 'media' => $medium]);
|
||||
|
|
|
@ -46,7 +46,7 @@ class Accounts extends BaseApi
|
|||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$account = DI::mstdnAccount()->createFromContactId($id);
|
||||
$account = DI::mstdnAccount()->createFromContactId($id, self::getCurrentUserID());
|
||||
System::jsonExit($account);
|
||||
}
|
||||
}
|
||||
|
|
86
src/Module/Api/Mastodon/Accounts/Followers.php
Normal file
86
src/Module/Api/Mastodon/Accounts/Followers.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Followers extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
// Return results older than this id
|
||||
$max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
|
||||
// Return results newer than this id
|
||||
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
|
||||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
|
||||
$params = ['order' => ['cid' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['relation-cid' => $id, 'follows' => true];
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['cid'];
|
||||
}
|
||||
|
||||
$followers = DBA::select('contact-relation', ['cid'], $condition, $parameters);
|
||||
while ($follower = DBA::fetch($followers)) {
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($follower['cid'], $uid);
|
||||
}
|
||||
DBA::close($followers);
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
86
src/Module/Api/Mastodon/Accounts/Following.php
Normal file
86
src/Module/Api/Mastodon/Accounts/Following.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class Following extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
// Return results older than this id
|
||||
$max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
|
||||
// Return results newer than this id
|
||||
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
|
||||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
|
||||
$params = ['order' => ['relation-cid' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['cid' => $id, 'follows' => true];
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['cid'];
|
||||
}
|
||||
|
||||
$followers = DBA::select('contact-relation', ['relation-cid'], $condition, $parameters);
|
||||
while ($follower = DBA::fetch($followers)) {
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($follower['relation-cid'], $uid);
|
||||
}
|
||||
DBA::close($followers);
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
|
@ -64,12 +64,23 @@ class Statuses extends BaseApi
|
|||
|
||||
$params = ['order' => ['uri-id' => true], 'limit' => $limit];
|
||||
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!$uid) {
|
||||
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
||||
'uid' => 0, 'network' => Protocol::FEDERATED];
|
||||
} else {
|
||||
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
||||
GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
||||
|
||||
if ($only_media) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
||||
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
|
||||
}
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
@ -83,11 +94,11 @@ class Statuses extends BaseApi
|
|||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$items = Post::selectForUser(0, ['uri-id', 'uid'], $condition, $params);
|
||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
while ($item = Post::fetch($items)) {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']);
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
|
||||
}
|
||||
DBA::close($items);
|
||||
|
||||
|
|
58
src/Module/Api/Mastodon/Accounts/VerifyCredentials.php
Normal file
58
src/Module/Api/Mastodon/Accounts/VerifyCredentials.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Accounts;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/
|
||||
*/
|
||||
class VerifyCredentials extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$self = User::getOwnerDataById($uid);
|
||||
if (empty($self)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContacID($self['id'], $uid);
|
||||
if (empty($cdata)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
// @todo Support the source property,
|
||||
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
|
||||
System::jsonExit($account);
|
||||
}
|
||||
}
|
50
src/Module/Api/Mastodon/Statuses.php
Normal file
50
src/Module/Api/Mastodon/Statuses.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/statuses/
|
||||
*/
|
||||
class Statuses extends BaseApi
|
||||
{
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
System::jsonExit(DI::mstdnStatus()->createFromUriId($parameters['id'], self::getCurrentUserID()));
|
||||
}
|
||||
}
|
56
src/Module/Api/Mastodon/Suggestions.php
Normal file
56
src/Module/Api/Mastodon/Suggestions.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/accounts/suggestions/
|
||||
*/
|
||||
class Suggestions extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
// Maximum number of results to return. Defaults to 40.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
|
||||
|
||||
$suggestions = Contact\Relation::getSuggestions($uid, 0, $limit);
|
||||
|
||||
$accounts = [];
|
||||
|
||||
foreach ($suggestions as $suggestion) {
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($suggestion['id'], $uid);
|
||||
}
|
||||
|
||||
System::jsonExit($accounts);
|
||||
}
|
||||
}
|
92
src/Module/Api/Mastodon/Timelines/Home.php
Normal file
92
src/Module/Api/Mastodon/Timelines/Home.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Timelines;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/
|
||||
*/
|
||||
class Home extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
// Return results older than id
|
||||
$max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
|
||||
// Return results newer than id
|
||||
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
|
||||
// Return results immediately newer than id
|
||||
$min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id'];
|
||||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
// Return only local statuses? Defaults to false.
|
||||
$local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true');
|
||||
|
||||
$params = ['order' => ['uri-id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'uid' => $uid];
|
||||
|
||||
if ($local) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
|
||||
}
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
while ($item = Post::fetch($items)) {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
|
||||
}
|
||||
DBA::close($items);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($statuses);
|
||||
}
|
||||
|
||||
System::jsonExit($statuses);
|
||||
}
|
||||
}
|
91
src/Module/Api/Mastodon/Timelines/ListTimeline.php
Normal file
91
src/Module/Api/Mastodon/Timelines/ListTimeline.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Timelines;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/
|
||||
*/
|
||||
class ListTimeline extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
// Return results older than id
|
||||
$max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
|
||||
// Return results newer than id
|
||||
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
|
||||
// Return results immediately newer than id
|
||||
$min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id'];
|
||||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
$params = ['order' => ['uri-id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)",
|
||||
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $parameters['id']];
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
while ($item = Post::fetch($items)) {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
|
||||
}
|
||||
DBA::close($items);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($statuses);
|
||||
}
|
||||
|
||||
System::jsonExit($statuses);
|
||||
}
|
||||
}
|
|
@ -69,6 +69,11 @@ class PublicTimeline extends BaseApi
|
|||
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
|
||||
}
|
||||
|
||||
if ($only_media) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
||||
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
|
||||
}
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
|
106
src/Module/Api/Mastodon/Timelines/Tag.php
Normal file
106
src/Module/Api/Mastodon/Timelines/Tag.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Api\Mastodon\Timelines;
|
||||
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/timelines/
|
||||
*/
|
||||
class Tag extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::login();
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['hashtag'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
// If true, return only local statuses. Defaults to false.
|
||||
$local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true');
|
||||
// If true, return only statuses with media attachments. Defaults to false.
|
||||
$only_media = (bool)!isset($_REQUEST['only_media']) ? false : ($_REQUEST['only_media'] == 'true'); // Currently not supported
|
||||
// Return results older than this ID.
|
||||
$max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
|
||||
// Return results newer than this ID.
|
||||
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
|
||||
// Return results immediately newer than this ID.
|
||||
$min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id'];
|
||||
// Maximum number of results to return. Defaults to 20.
|
||||
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit'];
|
||||
|
||||
$params = ['order' => ['uri-id' => true], 'limit' => $limit];
|
||||
|
||||
$condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
|
||||
AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
|
||||
$parameters['hashtag'], 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
|
||||
|
||||
if ($local) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)"]);
|
||||
}
|
||||
|
||||
if ($only_media) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
||||
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
|
||||
}
|
||||
|
||||
if (!empty($max_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]);
|
||||
|
||||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$items = DBA::select('tag-search-view', ['uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
while ($item = Post::fetch($items)) {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
|
||||
}
|
||||
DBA::close($items);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($statuses);
|
||||
}
|
||||
|
||||
System::jsonExit($statuses);
|
||||
}
|
||||
}
|
|
@ -21,9 +21,6 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -31,17 +28,48 @@ use Friendica\Module\BaseApi;
|
|||
*/
|
||||
class Unimplemented extends BaseApi
|
||||
{
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::unsupported('delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function patch(array $parameters = [])
|
||||
{
|
||||
self::unsupported('patch');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
self::unsupported('post');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
self::unsupported('put');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
$path = DI::args()->getQueryString();
|
||||
Logger::info('Unimplemented API call', ['path' => $path]);
|
||||
$error = DI::l10n()->t('API endpoint "%s" is not implemented', $path);
|
||||
$error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.');;
|
||||
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||
System::jsonError(501, $errorobj->toArray());
|
||||
self::unsupported('get');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
|
@ -53,6 +55,32 @@ class BaseApi extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function patch(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
|
@ -66,6 +94,29 @@ class BaseApi extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
public static function unsupported(string $method = 'all')
|
||||
{
|
||||
$path = DI::args()->getQueryString();
|
||||
Logger::info('Unimplemented API call', ['path' => $path, 'method' => $method]);
|
||||
$error = DI::l10n()->t('API endpoint %s %s is not implemented', strtoupper($method), $path);
|
||||
$error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.');;
|
||||
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||
System::jsonError(501, $errorobj->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in user via OAuth1 or Simple HTTP Auth.
|
||||
*
|
||||
|
|
|
@ -60,8 +60,8 @@ return [
|
|||
'/accounts' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/accounts/{id:\d+}' => [Module\Api\Mastodon\Accounts::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/statuses' => [Module\Api\Mastodon\Accounts\Statuses::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/followers' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/following' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/followers' => [Module\Api\Mastodon\Accounts\Followers::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/following' => [Module\Api\Mastodon\Accounts\Followers::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/lists' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/identity_proofs' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/{id:\d+}/follow' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
|
@ -75,7 +75,7 @@ return [
|
|||
'/accounts/{id:\d+}/note' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/accounts/relationships' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/search' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/verify_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/accounts/verify_credentials' => [Module\Api\Mastodon\Accounts\VerifyCredentials::class, [R::GET ]],
|
||||
'/accounts/update_credentials' => [Module\Api\Mastodon\Unimplemented::class, [R::PATCH ]],
|
||||
'/admin/accounts' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/admin/accounts/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
|
@ -126,7 +126,7 @@ return [
|
|||
'/scheduled_statuses' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/scheduled_statuses/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::PUT, R::DELETE]],
|
||||
'/statuses' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/statuses/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET, R::DELETE]],
|
||||
'/statuses/{id:\d+}' => [Module\Api\Mastodon\Statuses::class, [R::GET, R::DELETE]],
|
||||
'/statuses/{id:\d+}/context' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/statuses/{id:\d+}/reblogged_by' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/statuses/{id:\d+}/favourited_by' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
|
@ -140,12 +140,12 @@ return [
|
|||
'/statuses/{id:\d+}/unmute' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/statuses/{id:\d+}/pin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/statuses/{id:\d+}/unpin' => [Module\Api\Mastodon\Unimplemented::class, [ R::POST]],
|
||||
'/suggestions' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/suggestions' => [Module\Api\Mastodon\Suggestions::class, [R::GET ]],
|
||||
'/suggestions/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::DELETE ]],
|
||||
'/timelines/home' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/timelines/list/{id:\d+}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/timelines/home' => [Module\Api\Mastodon\Timelines\Home::class, [R::GET ]],
|
||||
'/timelines/list/{id:\d+}' => [Module\Api\Mastodon\Timelines\ListTimeline::class, [R::GET ]],
|
||||
'/timelines/public' => [Module\Api\Mastodon\Timelines\PublicTimeline::class, [R::GET ]],
|
||||
'/timelines/tag/{hashtag}' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]],
|
||||
'/timelines/tag/{hashtag}' => [Module\Api\Mastodon\Timelines\Tag::class, [R::GET ]],
|
||||
'/trends' => [Module\Api\Mastodon\Trends::class, [R::GET ]],
|
||||
],
|
||||
'/v2' => [
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 2021.06-dev\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-05-04 09:08-0400\n"
|
||||
"POT-Creation-Date: 2021-05-08 12:25+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -829,7 +829,10 @@ msgstr ""
|
|||
#: mod/unfollow.php:82 mod/wall_attach.php:78 mod/wall_attach.php:81
|
||||
#: mod/wall_upload.php:99 mod/wall_upload.php:102 mod/wallmessage.php:35
|
||||
#: mod/wallmessage.php:59 mod/wallmessage.php:96 mod/wallmessage.php:120
|
||||
#: src/Module/Attach.php:56 src/Module/BaseApi.php:59 src/Module/BaseApi.php:65
|
||||
#: src/Module/Attach.php:56 src/Module/BaseApi.php:61 src/Module/BaseApi.php:67
|
||||
#: src/Module/BaseApi.php:74 src/Module/BaseApi.php:80
|
||||
#: src/Module/BaseApi.php:87 src/Module/BaseApi.php:93
|
||||
#: src/Module/BaseApi.php:100 src/Module/BaseApi.php:106
|
||||
#: src/Module/BaseNotifications.php:88 src/Module/Contact.php:385
|
||||
#: src/Module/Contact/Advanced.php:43 src/Module/Delegation.php:118
|
||||
#: src/Module/FollowConfirm.php:16 src/Module/FriendSuggest.php:44
|
||||
|
@ -1163,8 +1166,8 @@ msgstr ""
|
|||
#: mod/dfrn_request.php:600 mod/display.php:179 mod/photos.php:836
|
||||
#: mod/videos.php:129 src/Module/Conversation/Community.php:188
|
||||
#: src/Module/Debug/Probe.php:39 src/Module/Debug/WebFinger.php:38
|
||||
#: src/Module/Directory.php:49 src/Module/Search/Index.php:51
|
||||
#: src/Module/Search/Index.php:56
|
||||
#: src/Module/Directory.php:49 src/Module/Search/Index.php:50
|
||||
#: src/Module/Search/Index.php:55
|
||||
msgid "Public access denied."
|
||||
msgstr ""
|
||||
|
||||
|
@ -3043,31 +3046,31 @@ msgstr ""
|
|||
msgid "Page not found."
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:150
|
||||
#: src/BaseModule.php:180
|
||||
msgid ""
|
||||
"The form security token was not correct. This probably happened because the "
|
||||
"form has been opened for too long (>3 hours) before submitting it."
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:179
|
||||
#: src/BaseModule.php:209
|
||||
msgid "All contacts"
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:184 src/Content/Widget.php:238 src/Core/ACL.php:183
|
||||
#: src/BaseModule.php:214 src/Content/Widget.php:238 src/Core/ACL.php:183
|
||||
#: src/Module/Contact.php:860 src/Module/PermissionTooltip.php:77
|
||||
#: src/Module/PermissionTooltip.php:99
|
||||
msgid "Followers"
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:189 src/Content/Widget.php:239 src/Module/Contact.php:861
|
||||
#: src/BaseModule.php:219 src/Content/Widget.php:239 src/Module/Contact.php:861
|
||||
msgid "Following"
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:194 src/Content/Widget.php:240 src/Module/Contact.php:862
|
||||
#: src/BaseModule.php:224 src/Content/Widget.php:240 src/Module/Contact.php:862
|
||||
msgid "Mutual friends"
|
||||
msgstr ""
|
||||
|
||||
#: src/BaseModule.php:202
|
||||
#: src/BaseModule.php:232
|
||||
msgid "Common"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3504,7 +3507,7 @@ msgid "Addon applications, utilities, games"
|
|||
msgstr ""
|
||||
|
||||
#: src/Content/Nav.php:220 src/Content/Text/HTML.php:899
|
||||
#: src/Module/Search/Index.php:100
|
||||
#: src/Module/Search/Index.php:99
|
||||
msgid "Search"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3662,39 +3665,39 @@ msgstr ""
|
|||
msgid "last"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:941 src/Content/Text/BBCode.php:1615
|
||||
#: src/Content/Text/BBCode.php:1616
|
||||
#: src/Content/Text/BBCode.php:942 src/Content/Text/BBCode.php:1605
|
||||
#: src/Content/Text/BBCode.php:1606
|
||||
msgid "Image/photo"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1063
|
||||
#: src/Content/Text/BBCode.php:1064
|
||||
#, php-format
|
||||
msgid ""
|
||||
"<a href=\"%1$s\" target=\"_blank\" rel=\"noopener noreferrer\">%2$s</a> %3$s"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1088 src/Model/Item.php:3020
|
||||
#: src/Model/Item.php:3026
|
||||
#: src/Content/Text/BBCode.php:1089 src/Model/Item.php:3024
|
||||
#: src/Model/Item.php:3030
|
||||
msgid "link to source"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1533 src/Content/Text/HTML.php:951
|
||||
#: src/Content/Text/BBCode.php:1523 src/Content/Text/HTML.php:951
|
||||
msgid "Click to open/close"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1564
|
||||
#: src/Content/Text/BBCode.php:1554
|
||||
msgid "$1 wrote:"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1618 src/Content/Text/BBCode.php:1619
|
||||
#: src/Content/Text/BBCode.php:1608 src/Content/Text/BBCode.php:1609
|
||||
msgid "Encrypted content"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1832
|
||||
#: src/Content/Text/BBCode.php:1822
|
||||
msgid "Invalid source protocol"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Text/BBCode.php:1847
|
||||
#: src/Content/Text/BBCode.php:1837
|
||||
msgid "Invalid link protocol"
|
||||
msgstr ""
|
||||
|
||||
|
@ -4846,15 +4849,15 @@ msgstr ""
|
|||
msgid "Content warning: %s"
|
||||
msgstr ""
|
||||
|
||||
#: src/Model/Item.php:2985
|
||||
#: src/Model/Item.php:2989
|
||||
msgid "bytes"
|
||||
msgstr ""
|
||||
|
||||
#: src/Model/Item.php:3014
|
||||
#: src/Model/Item.php:3018
|
||||
msgid "View on separate page"
|
||||
msgstr ""
|
||||
|
||||
#: src/Model/Item.php:3015
|
||||
#: src/Model/Item.php:3019
|
||||
msgid "view on separate page"
|
||||
msgstr ""
|
||||
|
||||
|
@ -7218,16 +7221,6 @@ msgstr ""
|
|||
msgid "Deny"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Api/Mastodon/Unimplemented.php:42
|
||||
#, php-format
|
||||
msgid "API endpoint \"%s\" is not implemented"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Api/Mastodon/Unimplemented.php:43
|
||||
msgid ""
|
||||
"The API endpoint is currently not implemented but might be in the future."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Api/Twitter/ContactEndpoint.php:65 src/Module/Contact.php:400
|
||||
msgid "Contact not found"
|
||||
msgstr ""
|
||||
|
@ -7330,6 +7323,16 @@ msgstr ""
|
|||
msgid "User registrations waiting for confirmation"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/BaseApi.php:114
|
||||
#, php-format
|
||||
msgid "API endpoint %s %s is not implemented"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/BaseApi.php:115
|
||||
msgid ""
|
||||
"The API endpoint is currently not implemented but might be in the future."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/BaseProfile.php:55 src/Module/Contact.php:947
|
||||
msgid "Profile Details"
|
||||
msgstr ""
|
||||
|
@ -7684,7 +7687,7 @@ msgstr ""
|
|||
msgid "Search your contacts"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Contact.php:883 src/Module/Search/Index.php:193
|
||||
#: src/Module/Contact.php:883 src/Module/Search/Index.php:192
|
||||
#, php-format
|
||||
msgid "Results for: %s"
|
||||
msgstr ""
|
||||
|
@ -7924,8 +7927,8 @@ msgstr ""
|
|||
msgid "Hide"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Conversation/Community.php:149 src/Module/Search/Index.php:140
|
||||
#: src/Module/Search/Index.php:180
|
||||
#: src/Module/Conversation/Community.php:149 src/Module/Search/Index.php:139
|
||||
#: src/Module/Search/Index.php:179
|
||||
msgid "No results."
|
||||
msgstr ""
|
||||
|
||||
|
@ -9107,15 +9110,15 @@ msgid ""
|
|||
"or <strong>%s</strong> directly on your system."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Search/Index.php:55
|
||||
#: src/Module/Search/Index.php:54
|
||||
msgid "Only logged in users are permitted to perform a search."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Search/Index.php:77
|
||||
#: src/Module/Search/Index.php:76
|
||||
msgid "Only one search per minute is permitted for not logged in users."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Search/Index.php:191
|
||||
#: src/Module/Search/Index.php:190
|
||||
#, php-format
|
||||
msgid "Items tagged with: %s"
|
||||
msgstr ""
|
||||
|
|
Loading…
Reference in a new issue