Merge pull request #5710 from annando/fix-api
Fix for timeout issues when posting to the API
This commit is contained in:
commit
d5a3b0bd5e
|
@ -1059,10 +1059,10 @@ function api_statuses_mediap($type)
|
|||
|
||||
// now that we have the img url in bbcode we can add it to the status and insert the wall item.
|
||||
$_REQUEST['body'] = $txt . "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]";
|
||||
item_post($a);
|
||||
$item_id = item_post($a);
|
||||
|
||||
// this should output the last post (the one we just posted).
|
||||
return api_status_show($type);
|
||||
// output the post that we just posted.
|
||||
return api_status_show($type, $item_id);
|
||||
}
|
||||
|
||||
/// @TODO move this to top of file or somewhere better!
|
||||
|
@ -1078,7 +1078,6 @@ api_register_func('api/statuses/mediap', 'api_statuses_mediap', true, API_METHOD
|
|||
*/
|
||||
function api_statuses_update($type)
|
||||
{
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if (api_user() === false) {
|
||||
|
@ -1132,8 +1131,8 @@ function api_statuses_update($type)
|
|||
if ($throttle_day > 0) {
|
||||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
|
||||
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
|
||||
$posts_day = DBA::count('item', $condition);
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
|
||||
$posts_day = DBA::count('thread', $condition);
|
||||
|
||||
if ($posts_day > $throttle_day) {
|
||||
logger('Daily posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
|
@ -1146,8 +1145,8 @@ function api_statuses_update($type)
|
|||
if ($throttle_week > 0) {
|
||||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
|
||||
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
|
||||
$posts_week = DBA::count('item', $condition);
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
|
||||
$posts_week = DBA::count('thread', $condition);
|
||||
|
||||
if ($posts_week > $throttle_week) {
|
||||
logger('Weekly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
|
@ -1160,8 +1159,8 @@ function api_statuses_update($type)
|
|||
if ($throttle_month > 0) {
|
||||
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
|
||||
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
|
||||
$posts_month = DBA::count('item', $condition);
|
||||
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
|
||||
$posts_month = DBA::count('thread', $condition);
|
||||
|
||||
if ($posts_month > $throttle_month) {
|
||||
logger('Monthly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
|
@ -1203,10 +1202,10 @@ function api_statuses_update($type)
|
|||
}
|
||||
|
||||
// call out normal post function
|
||||
item_post($a);
|
||||
$item_id = item_post($a);
|
||||
|
||||
// this should output the last post (the one we just posted).
|
||||
return api_status_show($type);
|
||||
// output the post that we just posted.
|
||||
return api_status_show($type, $item_id);
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
|
@ -1263,7 +1262,7 @@ api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST)
|
|||
*
|
||||
* @return array|string
|
||||
*/
|
||||
function api_status_show($type)
|
||||
function api_status_show($type, $item_id = 0)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
|
@ -1277,9 +1276,14 @@ function api_status_show($type)
|
|||
$privacy_sql = "";
|
||||
}
|
||||
|
||||
if (!empty($item_id)) {
|
||||
// Get the item with the given id
|
||||
$condition = ['id' => $item_id];
|
||||
} else {
|
||||
// get last public wall message
|
||||
$condition = ['owner-id' => $user_info['pid'], 'uid' => api_user(),
|
||||
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
|
||||
}
|
||||
$lastwall = Item::selectFirst(Item::ITEM_FIELDLIST, $condition, ['order' => ['id' => true]]);
|
||||
|
||||
if (DBA::isResult($lastwall)) {
|
||||
|
@ -1996,14 +2000,14 @@ function api_statuses_repeat($type)
|
|||
$_REQUEST["source"] = api_source();
|
||||
}
|
||||
|
||||
item_post($a);
|
||||
$item_id = item_post($a);
|
||||
} else {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
// this should output the last post (the one we just posted).
|
||||
// output the post that we just posted.
|
||||
$called_api = [];
|
||||
return api_status_show($type);
|
||||
return api_status_show($type, $item_id);
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
|
|
10
mod/item.php
10
mod/item.php
|
@ -39,7 +39,7 @@ require_once 'include/items.php';
|
|||
|
||||
function item_post(App $a) {
|
||||
if (!local_user() && !remote_user()) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
require_once 'include/security.php';
|
||||
|
@ -154,7 +154,7 @@ function item_post(App $a) {
|
|||
if (($message_id != '') && ($profile_uid != 0)) {
|
||||
if (Item::exists(['uri' => $message_id, 'uid' => $profile_uid])) {
|
||||
logger("Message with URI ".$message_id." already exists for user ".$profile_uid, LOGGER_DEBUG);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ function item_post(App $a) {
|
|||
$user = DBA::selectFirst('user', [], ['uid' => $profile_uid]);
|
||||
|
||||
if (!DBA::isResult($user) && !$parent) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$categories = '';
|
||||
|
@ -843,6 +843,10 @@ function item_post(App $a) {
|
|||
|
||||
logger('post_complete');
|
||||
|
||||
if ($api_source) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
item_post_return(System::baseUrl(), $api_source, $return_path);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue