Merge pull request #12407 from HankG/friendica-api-photo-endpoint-updates
Friendica api photo endpoint updates
This commit is contained in:
commit
d26b0ed5a2
|
@ -64,7 +64,7 @@ class Create extends BaseApi
|
||||||
|
|
||||||
// do several checks on input parameters
|
// do several checks on input parameters
|
||||||
// we do not allow calls without album string
|
// we do not allow calls without album string
|
||||||
if ($album == null) {
|
if ($album === null) {
|
||||||
throw new HTTPException\BadRequestException('no album name specified');
|
throw new HTTPException\BadRequestException('no album name specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ class Create extends BaseApi
|
||||||
|
|
||||||
// return success of updating or error message
|
// return success of updating or error message
|
||||||
if (!empty($photo)) {
|
if (!empty($photo)) {
|
||||||
|
Photo::clearAlbumCache($uid);
|
||||||
$data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
|
$data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
|
||||||
$this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null);
|
$this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Delete extends BaseApi
|
||||||
// to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
|
// to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
|
||||||
$condition = ['uid' => $uid, 'resource-id' => $request['photo_id'], 'post-type' => Item::PT_IMAGE, 'origin' => true];
|
$condition = ['uid' => $uid, 'resource-id' => $request['photo_id'], 'post-type' => Item::PT_IMAGE, 'origin' => true];
|
||||||
Item::deleteForUser($condition, $uid);
|
Item::deleteForUser($condition, $uid);
|
||||||
|
Photo::clearAlbumCache($uid);
|
||||||
$result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.'];
|
$result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.'];
|
||||||
$this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null);
|
$this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,6 +135,7 @@ class Update extends BaseApi
|
||||||
|
|
||||||
// return success of updating or error message
|
// return success of updating or error message
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
Photo::clearAlbumCache($uid);
|
||||||
$answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.'];
|
$answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.'];
|
||||||
$this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
$this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -66,6 +66,7 @@ class Delete extends BaseApi
|
||||||
|
|
||||||
// return success of deletion or error message
|
// return success of deletion or error message
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
Photo::clearAlbumCache($uid);
|
||||||
$answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.'];
|
$answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.'];
|
||||||
$this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
$this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (C) 2010-2022, 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\Friendica\Photoalbum;
|
||||||
|
|
||||||
|
use Friendica\Model\Photo;
|
||||||
|
use Friendica\Module\BaseApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api/friendica/photoalbum
|
||||||
|
*
|
||||||
|
* @package Friendica\Module\Api\Friendica\Photoalbum
|
||||||
|
*/
|
||||||
|
class Index extends BaseApi
|
||||||
|
{
|
||||||
|
protected function rawContent(array $request = [])
|
||||||
|
{
|
||||||
|
self::checkAllowedScope(self::SCOPE_READ);
|
||||||
|
$uid = self::getCurrentUserID();
|
||||||
|
|
||||||
|
$albums = Photo::getAlbums($uid);
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
foreach ($albums as $album) {
|
||||||
|
$items[] = [
|
||||||
|
'name' => $album['album'],
|
||||||
|
'created' => $album['created'],
|
||||||
|
'count' => $album['total'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response->exit('albums', ['albums' => $items], $this->parameters['extension'] ?? null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (C) 2010-2022, 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\Friendica\Photoalbum;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
|
use Friendica\Core\L10n;
|
||||||
|
use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\Photo;
|
||||||
|
use Friendica\Module\Api\ApiResponse;
|
||||||
|
use Friendica\Module\BaseApi;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api/friendica/photoalbum/:name
|
||||||
|
*
|
||||||
|
* @package Friendica\Module\Api\Friendica\Photoalbum
|
||||||
|
*/
|
||||||
|
class Show extends BaseApi
|
||||||
|
{
|
||||||
|
/** @var FriendicaPhoto */
|
||||||
|
private $friendicaPhoto;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||||
|
{
|
||||||
|
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
|
$this->friendicaPhoto = $friendicaPhoto;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rawContent(array $request = [])
|
||||||
|
{
|
||||||
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||||
|
$uid = BaseApi::getCurrentUserID();
|
||||||
|
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
|
||||||
|
$request = $this->getRequest([
|
||||||
|
'album' => '', // Get pictures in this album
|
||||||
|
'offset' => 0, // Return results offset by this value
|
||||||
|
'limit' => 50, // Maximum number of results to return. Defaults to 50. Max 500
|
||||||
|
'latest_first' => false, // Whether to reverse the order so newest are first
|
||||||
|
], $request);
|
||||||
|
|
||||||
|
if (empty($request['album'])) {
|
||||||
|
throw new HTTPException\BadRequestException('No album name specified.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderDescending = $request['latest_first'];
|
||||||
|
$album = $request['album'];
|
||||||
|
$condition = ["`uid` = ? AND `album` = ?", $uid, $album];
|
||||||
|
$params = ['order' => ['id' => $orderDescending], 'group_by' => ['resource-id']];
|
||||||
|
|
||||||
|
$limit = $request['limit'];
|
||||||
|
if ($limit > 500) {
|
||||||
|
$limit = 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($limit <= 0) {
|
||||||
|
$limit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($request['offset'])) {
|
||||||
|
$params['limit'] = [$request['offset'], $limit];
|
||||||
|
} else {
|
||||||
|
$params['limit'] = $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$photos = Photo::selectToArray(['resource-id'], $condition, $params);
|
||||||
|
|
||||||
|
$data = ['photo' => []];
|
||||||
|
foreach ($photos as $photo) {
|
||||||
|
$element = $this->friendicaPhoto->createFromId($photo['resource-id'], null, $uid, 'json', false);
|
||||||
|
|
||||||
|
$element['thumb'] = end($element['link']);
|
||||||
|
unset($element['link']);
|
||||||
|
|
||||||
|
if ($type == 'xml') {
|
||||||
|
$thumb = $element['thumb'];
|
||||||
|
unset($element['thumb']);
|
||||||
|
$data['photo'][] = ['@attributes' => $element, '1' => $thumb];
|
||||||
|
} else {
|
||||||
|
$data['photo'][] = $element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,6 +58,7 @@ class Update extends BaseApi
|
||||||
|
|
||||||
// return success of updating or error message
|
// return success of updating or error message
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
Photo::clearAlbumCache($uid);
|
||||||
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
|
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
|
||||||
$this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
$this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -93,6 +93,8 @@ $apiRoutes = [
|
||||||
'/group_delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Delete::class, [ R::POST]],
|
'/group_delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Delete::class, [ R::POST]],
|
||||||
'/group_update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Update::class, [ R::POST]],
|
'/group_update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Update::class, [ R::POST]],
|
||||||
'/profile/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Profile\Show::class, [R::GET ]],
|
'/profile/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Profile\Show::class, [R::GET ]],
|
||||||
|
'/photoalbums[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Index::class, [R::GET ]],
|
||||||
|
'/photoalbum[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Show::class, [R::GET ]],
|
||||||
'/photoalbum/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Delete::class, [ R::POST]],
|
'/photoalbum/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Delete::class, [ R::POST]],
|
||||||
'/photoalbum/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Update::class, [ R::POST]],
|
'/photoalbum/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Update::class, [ R::POST]],
|
||||||
'/photos/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photo\Lists::class, [R::GET ]],
|
'/photos/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photo\Lists::class, [R::GET ]],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user