From cdbc6aa4f305529f618e19b5af31ed896fb0a673 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 26 Jul 2020 17:27:31 +0000 Subject: switch to q=source for querying the media endpoint https://github.com/indieweb/micropub-extensions/issues/14 --- controllers/controllers.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/controllers/controllers.php b/controllers/controllers.php index f9fad25..0917315 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -86,9 +86,17 @@ $app->get('/new/last-photo.json', function() use($app) { if($user->micropub_media_endpoint) { // Request the last file uploaded from the media endpoint - $response = micropub_get($user->micropub_media_endpoint, ['q'=>'last'], $user->micropub_access_token); - if(isset($response['data']['url'])) { - $url = $response['data']['url']; + $response = micropub_get($user->micropub_media_endpoint, ['q'=>'source', 'limit'=>1], $user->micropub_access_token); + if(isset($response['data']['items'])) { + $items = $response['data']['items']; + if(isset($items[0])) { + $item = $items[0]; + // Only show the file if it was uploaded in the last 5 minutes or if no published date available + $show = !isset($item['published']) || (strtotime($item['published']) >= (time()-300)); + if($show && isset($item['url'])) { + $url = $item['url']; + } + } } } -- cgit v1.2.3