mirror of
https://github.com/friendica/friendica
synced 2024-11-14 04:22:55 +00:00
Merge pull request #7450 from annando/api-alt-description
We can now set image descriptions via API
This commit is contained in:
commit
70b9359c38
8 changed files with 103 additions and 7 deletions
21
doc/api.md
21
doc/api.md
|
@ -393,6 +393,27 @@ Object of:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### media/metadata/create (POST,PUT; AUTH)
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
Parameters are sent as JSON object:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"media_id":"1234",
|
||||||
|
"alt_text": {
|
||||||
|
"text":"Here comes the description"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Return values
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### oauth/request_token (*)
|
### oauth/request_token (*)
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
|
@ -1158,15 +1158,16 @@ function api_statuses_update($type)
|
||||||
// To-Do: Multiple IDs
|
// To-Do: Multiple IDs
|
||||||
if (requestdata('media_ids')) {
|
if (requestdata('media_ids')) {
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `resource-id`, `scale`, `nickname`, `type` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
|
"SELECT `resource-id`, `scale`, `nickname`, `type`, `desc` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
|
||||||
intval(requestdata('media_ids')),
|
intval(requestdata('media_ids')),
|
||||||
api_user()
|
api_user()
|
||||||
);
|
);
|
||||||
if (DBA::isResult($r)) {
|
if (DBA::isResult($r)) {
|
||||||
$phototypes = Image::supportedTypes();
|
$phototypes = Image::supportedTypes();
|
||||||
$ext = $phototypes[$r[0]['type']];
|
$ext = $phototypes[$r[0]['type']];
|
||||||
|
$description = $r[0]['desc'] ?? '';
|
||||||
$_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
|
$_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
|
||||||
$_REQUEST['body'] .= '[img]' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . '[/img][/url]';
|
$_REQUEST['body'] .= '[img=' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . ']' . $description . '[/img][/url]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,6 +1240,65 @@ function api_media_upload()
|
||||||
/// @TODO move to top of file or somewhere better
|
/// @TODO move to top of file or somewhere better
|
||||||
api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST);
|
api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates media meta data (picture descriptions)
|
||||||
|
*
|
||||||
|
* @param string $type Return type (atom, rss, xml, json)
|
||||||
|
*
|
||||||
|
* @return array|string
|
||||||
|
* @throws BadRequestException
|
||||||
|
* @throws ForbiddenException
|
||||||
|
* @throws ImagickException
|
||||||
|
* @throws InternalServerErrorException
|
||||||
|
* @throws TooManyRequestsException
|
||||||
|
* @throws UnauthorizedException
|
||||||
|
* @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
|
||||||
|
*
|
||||||
|
* @todo Compare the corresponding Twitter function for correct return values
|
||||||
|
*/
|
||||||
|
function api_media_metadata_create($type)
|
||||||
|
{
|
||||||
|
$a = \get_app();
|
||||||
|
|
||||||
|
if (api_user() === false) {
|
||||||
|
Logger::info('no user');
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
api_get_user($a);
|
||||||
|
|
||||||
|
$postdata = Network::postdata();
|
||||||
|
|
||||||
|
if (empty($postdata)) {
|
||||||
|
throw new BadRequestException("No post data");
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($postdata, true);
|
||||||
|
if (empty($data)) {
|
||||||
|
throw new BadRequestException("Invalid post data");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data['media_id']) || empty($data['alt_text'])) {
|
||||||
|
throw new BadRequestException("Missing post data values");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data['alt_text']['text'])) {
|
||||||
|
throw new BadRequestException("No alt text.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::info('Updating metadata', ['media_id' => $data['media_id']]);
|
||||||
|
|
||||||
|
$condition = ['id' => $data['media_id'], 'uid' => api_user()];
|
||||||
|
$photo = DBA::selectFirst('photo', ['resource-id'], $condition);
|
||||||
|
if (!DBA::isResult($photo)) {
|
||||||
|
throw new BadRequestException("Metadata not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
DBA::update('photo', ['desc' => $data['alt_text']['text']], ['resource-id' => $photo['resource-id']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
api_register_func('api/media/metadata/create', 'api_media_metadata_create', true, API_METHOD_POST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type Return format (atom, rss, xml, json)
|
* @param string $type Return format (atom, rss, xml, json)
|
||||||
* @param int $item_id
|
* @param int $item_id
|
||||||
|
|
|
@ -16,11 +16,12 @@ use Friendica\Model\User;
|
||||||
use Friendica\Protocol\DFRN;
|
use Friendica\Protocol\DFRN;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
function dfrn_notify_post(App $a) {
|
function dfrn_notify_post(App $a) {
|
||||||
Logger::log(__function__, Logger::TRACE);
|
Logger::log(__function__, Logger::TRACE);
|
||||||
|
|
||||||
$postdata = file_get_contents('php://input');
|
$postdata = Network::postdata();
|
||||||
|
|
||||||
if (empty($_POST) || !empty($postdata)) {
|
if (empty($_POST) || !empty($postdata)) {
|
||||||
$data = json_decode($postdata);
|
$data = json_decode($postdata);
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use Friendica\Util\Network;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
|
||||||
function hub_return($valid, $body)
|
function hub_return($valid, $body)
|
||||||
|
@ -83,7 +84,7 @@ function pubsub_init(App $a)
|
||||||
|
|
||||||
function pubsub_post(App $a)
|
function pubsub_post(App $a)
|
||||||
{
|
{
|
||||||
$xml = file_get_contents('php://input');
|
$xml = Network::postdata();
|
||||||
|
|
||||||
Logger::log('Feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd . ' with user-agent: ' . $_SERVER['HTTP_USER_AGENT']);
|
Logger::log('Feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd . ' with user-agent: ' . $_SERVER['HTTP_USER_AGENT']);
|
||||||
Logger::log('Data: ' . $xml, Logger::DATA);
|
Logger::log('Data: ' . $xml, Logger::DATA);
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param App $a App
|
* @param App $a App
|
||||||
|
@ -47,7 +48,7 @@ function receive_post(App $a)
|
||||||
Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
|
Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
|
||||||
|
|
||||||
if (empty($_POST['xml'])) {
|
if (empty($_POST['xml'])) {
|
||||||
$postdata = file_get_contents("php://input");
|
$postdata = Network::postdata();
|
||||||
if ($postdata == '') {
|
if ($postdata == '') {
|
||||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,12 @@ use Friendica\Protocol\OStatus;
|
||||||
use Friendica\Protocol\Salmon;
|
use Friendica\Protocol\Salmon;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
function salmon_post(App $a, $xml = '') {
|
function salmon_post(App $a, $xml = '') {
|
||||||
|
|
||||||
if (empty($xml)) {
|
if (empty($xml)) {
|
||||||
$xml = file_get_contents('php://input');
|
$xml = Network::postdata();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::log('new salmon ' . $xml, Logger::DATA);
|
Logger::log('new salmon ' . $xml, Logger::DATA);
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
use Friendica\Util\Network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Inbox
|
* ActivityPub Inbox
|
||||||
|
@ -22,7 +23,7 @@ class Inbox extends BaseModule
|
||||||
{
|
{
|
||||||
$a = self::getApp();
|
$a = self::getApp();
|
||||||
|
|
||||||
$postdata = file_get_contents('php://input');
|
$postdata = Network::postdata();
|
||||||
|
|
||||||
if (empty($postdata)) {
|
if (empty($postdata)) {
|
||||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||||
|
|
|
@ -342,6 +342,16 @@ class Network
|
||||||
return $curlResponse;
|
return $curlResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return raw post data from a post request
|
||||||
|
*
|
||||||
|
* @return string post data
|
||||||
|
*/
|
||||||
|
public static function postdata()
|
||||||
|
{
|
||||||
|
return file_get_contents('php://input');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check URL to see if it's real
|
* @brief Check URL to see if it's real
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue