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);
$uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? '';
$type = $this->getRequestValue($this->parameters, 'extension', 'json');
// params
$gid = $this->getRequestValue($request, 'gid', 0);

View File

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

View File

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

View File

@ -54,7 +54,7 @@ class Lists extends BaseApi
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$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],
['order' => ['id'], 'group_by' => ['resource-id']]);

View File

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

View File

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

View File

@ -52,7 +52,12 @@ class Destroy extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$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);
$parenturi = $request['friendica_parenturi'] ?? '';
@ -64,11 +69,6 @@ class Destroy extends BaseApi
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
$sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : "");

View File

@ -45,10 +45,11 @@ class Favorites extends BaseApi
Logger::info(BaseApi::LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites']);
// params
$count = $this->getRequestValue($request, 'count', 20, 1, 100);
$page = $this->getRequestValue($request, 'page', 1, 1);
$since_id = $this->getRequestValue($request, 'since_id', 0, 0);
$max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$count = $this->getRequestValue($request, 'count', 20, 1, 100);
$page = $this->getRequestValue($request, 'page', 1, 1);
$since_id = $this->getRequestValue($request, 'since_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);
@ -64,8 +65,6 @@ class Favorites extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$ret = [];
while ($status = DBA::fetch($statuses)) {
$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);
$uid = BaseApi::getCurrentUserID();
if (!empty($this->parameters['id'])) {
$id = (int)$this->parameters['id'];
} elseif (!empty($request['id'])) {
$id = (int)$request['id'];
} else {
$id = $this->getRequestValue($request, 'id', 0);
$id = $this->getRequestValue($this->parameters, 'id', $id);
if (empty($id)) {
throw new BadRequestException('An id is missing.');
}

View File

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

View File

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