API: Support for deprecated API endpoints and OAuth removal

This commit is contained in:
Michael 2021-07-20 20:48:37 +00:00
parent a556b7c029
commit b5f59d5be0
12 changed files with 74 additions and 57 deletions

View file

@ -58,7 +58,7 @@ class Search extends BaseApi
'offset' => 0, // Offset in search results. Used for pagination. Defaults to 0.
'following' => false, // Only include accounts that the user is following. Defaults to false.
]);
if (empty($request['q'])) {
DI::mstdnError()->UnprocessableEntity();
}
@ -74,7 +74,7 @@ class Search extends BaseApi
$result['statuses'] = self::searchStatuses($uid, $request['q'], $request['account_id'], $request['max_id'], $request['min_id'], $limit, $request['offset']);
}
if ((empty($request['type']) || ($request['type'] == 'hashtags')) && (strpos($request['q'], '@') == false)) {
$result['hashtags'] = self::searchHashtags($request['q'], $request['exclude_unreviewed'], $limit, $request['offset']);
$result['hashtags'] = self::searchHashtags($request['q'], $request['exclude_unreviewed'], $limit, $request['offset'], $parameters['version']);
}
System::jsonExit($result);
@ -175,7 +175,7 @@ class Search extends BaseApi
return $statuses;
}
private static function searchHashtags(string $q, bool $exclude_unreviewed, int $limit, int $offset)
private static function searchHashtags(string $q, bool $exclude_unreviewed, int $limit, int $offset, int $version)
{
$q = ltrim($q, '#');
@ -187,7 +187,11 @@ class Search extends BaseApi
$hashtags = [];
foreach ($tags as $tag) {
$hashtags[] = new \Friendica\Object\Api\Mastodon\Tag(DI::baseUrl(), $tag);
if ($version == 1) {
$hashtags[] = $tag['name'];
} else {
$hashtags[] = new \Friendica\Object\Api\Mastodon\Tag(DI::baseUrl(), $tag);
}
}
return $hashtags;

View file

@ -0,0 +1,57 @@
<?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\Statuses;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Module\BaseApi;
/**
* @see https://docs.joinmastodon.org/methods/statuses/
*/
class Card extends BaseApi
{
/**
* @param array $parameters
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function rawContent(array $parameters = [])
{
$uid = self::getCurrentUserID();
if (empty($parameters['id'])) {
DI::mstdnError()->UnprocessableEntity();
}
$request = self::getRequest([
'limit' => 40, // Maximum number of results to return. Defaults to 40.
]);
$id = $parameters['id'];
$card = DI::mstdnCard()->createFromUriId($id);
System::jsonExit($card->toArray());
}
}