diff options
-rw-r--r-- | controllers/controllers.php | 14 | ||||
-rw-r--r-- | lib/helpers.php | 4 |
2 files changed, 13 insertions, 5 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']; + } + } } } diff --git a/lib/helpers.php b/lib/helpers.php index 48ada12..ec23afa 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -120,8 +120,8 @@ function micropub_media_post_for_user(&$user, $file) { $r = micropub_post($user->micropub_media_endpoint, [], $user->micropub_access_token, $file, true, 'file'); // Check the response and look for a "Location" header containing the URL - if($r['response'] && preg_match('/Location: (.+)/', $r['response'], $match)) { - $r['location'] = trim($match[1]); + if($r['headers'] && $r['headers']['Location']) { + $r['location'] = $r['headers']['Location']; } else { $r['location'] = false; } |