More parameter handling improved

This commit is contained in:
Michael 2022-01-16 18:04:05 +00:00
parent 6c767743d1
commit fd4926b0f3
11 changed files with 27 additions and 32 deletions

View file

@ -36,7 +36,7 @@ class Show extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->getRequestValue($this->parameters, 'extension', 'json');
// params // params
$gid = $this->getRequestValue($request, 'gid', 0); $gid = $this->getRequestValue($request, 'gid', 0);

View file

@ -48,7 +48,7 @@ class Photo extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->getRequestValue($this->parameters, 'extension', 'json');
if (empty($request['photo_id'])) { if (empty($request['photo_id'])) {
throw new HTTPException\BadRequestException('No photo id.'); throw new HTTPException\BadRequestException('No photo id.');

View file

@ -52,7 +52,7 @@ class Create extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->getRequestValue($this->parameters, 'extension', 'json');
// input params // input params
$desc = $this->getRequestValue($request, 'desc'); $desc = $this->getRequestValue($request, 'desc');

View file

@ -54,7 +54,7 @@ class Lists extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->getRequestValue($this->parameters, 'extension', 'json');
$photos = Photo::selectToArray(['resource-id'], ["`uid` = ? AND NOT `photo-type` IN (?, ?)", $uid, Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER], $photos = Photo::selectToArray(['resource-id'], ["`uid` = ? AND NOT `photo-type` IN (?, ?)", $uid, Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER],
['order' => ['id'], 'group_by' => ['resource-id']]); ['order' => ['id'], 'group_by' => ['resource-id']]);

View file

@ -52,7 +52,7 @@ class Update extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->getRequestValue($this->parameters, 'extension', 'json');
// input params // input params
$photo_id = $this->getRequestValue($request, 'photo_id'); $photo_id = $this->getRequestValue($request, 'photo_id');

View file

@ -40,7 +40,7 @@ class Conversation extends BaseApi
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
// params // params
$id = $this->parameters['id'] ?? 0; $id = $this->getRequestValue($this->parameters, 'id', 0);
$since_id = $this->getRequestValue($request, 'since_id', 0, 0); $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
$max_id = $this->getRequestValue($request, 'max_id', 0, 0); $max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$count = $this->getRequestValue($request, 'count', 20, 1, 100); $count = $this->getRequestValue($request, 'count', 20, 1, 100);

View file

@ -53,6 +53,11 @@ class Destroy extends BaseApi
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$id = $this->getRequestValue($request, 'id', 0); $id = $this->getRequestValue($request, 'id', 0);
$id = $this->getRequestValue($this->parameters, 'id', $id);
if (empty($id)) {
throw new BadRequestException('Message id not specified');
}
$verbose = $this->getRequestValue($request, 'friendica_verbose', false); $verbose = $this->getRequestValue($request, 'friendica_verbose', false);
$parenturi = $request['friendica_parenturi'] ?? ''; $parenturi = $request['friendica_parenturi'] ?? '';
@ -64,11 +69,6 @@ class Destroy extends BaseApi
return; return;
} }
// BadRequestException if no id specified (for clients using Twitter API)
if ($id == 0) {
throw new BadRequestException('Message id not specified');
}
// add parent-uri to sql command if specified by calling app // add parent-uri to sql command if specified by calling app
$sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : ""); $sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : "");

View file

@ -49,6 +49,7 @@ class Favorites extends BaseApi
$page = $this->getRequestValue($request, 'page', 1, 1); $page = $this->getRequestValue($request, 'page', 1, 1);
$since_id = $this->getRequestValue($request, 'since_id', 0, 0); $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
$max_id = $this->getRequestValue($request, 'max_id', 0, 0); $max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$include_entities = $this->getRequestValue($request, 'include_entities', false);
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
@ -64,8 +65,6 @@ class Favorites extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {
$ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray(); $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();

View file

@ -39,11 +39,9 @@ class Destroy extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
if (!empty($this->parameters['id'])) { $id = $this->getRequestValue($request, 'id', 0);
$id = (int)$this->parameters['id']; $id = $this->getRequestValue($this->parameters, 'id', $id);
} elseif (!empty($request['id'])) { if (empty($id)) {
$id = (int)$request['id'];
} else {
throw new BadRequestException('An id is missing.'); throw new BadRequestException('An id is missing.');
} }

View file

@ -44,11 +44,9 @@ class Retweet extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) { $id = $this->getRequestValue($request, 'id', 0);
$id = (int)$this->parameters['id']; $id = $this->getRequestValue($this->parameters, 'id', $id);
} elseif (!empty($request['id'])) { if (empty($id)) {
$id = (int)$request['id'];
} else {
throw new BadRequestException('An id is missing.'); throw new BadRequestException('An id is missing.');
} }

View file

@ -41,10 +41,10 @@ class Show extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
if (empty($this->parameters['id'])) { $id = $this->getRequestValue($request, 'id', 0);
$id = intval($request['id'] ?? 0); $id = $this->getRequestValue($this->parameters, 'id', $id);
} else { if (empty($id)) {
$id = (int)$this->parameters['id']; throw new BadRequestException('An id is missing.');
} }
Logger::notice('API: api_statuses_show: ' . $id); Logger::notice('API: api_statuses_show: ' . $id);