3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Twitter\Media\Metadata;
24 use Friendica\Core\Logger;
25 use Friendica\Model\Photo;
26 use Friendica\Module\BaseApi;
27 use Friendica\Network\HTTPException\BadRequestException;
28 use Friendica\Util\Network;
31 * Updates media meta data (picture descriptions)
33 * @see https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create
35 class Create extends BaseApi
37 protected function post(array $request = [])
39 BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
40 $uid = BaseApi::getCurrentUserID();
42 $postdata = Network::postdata();
44 if (empty($postdata)) {
45 throw new BadRequestException('No post data');
48 $data = json_decode($postdata, true);
50 throw new BadRequestException('Invalid post data');
53 if (empty($data['media_id']) || empty($data['alt_text'])) {
54 throw new BadRequestException('Missing post data values');
57 if (empty($data['alt_text']['text'])) {
58 throw new BadRequestException('No alt text.');
61 Logger::info('Updating metadata', ['media_id' => $data['media_id']]);
63 $condition = ['id' => $data['media_id'], 'uid' => $uid];
65 $photo = Photo::selectFirst(['resource-id'], $condition);
66 if (empty($photo['resource-id'])) {
67 throw new BadRequestException('Metadata not found.');
70 Photo::update(['desc' => $data['alt_text']['text']], ['resource-id' => $photo['resource-id']]);