diff options
| -rw-r--r-- | controllers/controllers.php | 19 | ||||
| -rw-r--r-- | views/new-post.php | 12 | 
2 files changed, 31 insertions, 0 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index b028193..b263164 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -90,6 +90,25 @@ $app->get('/new', function() use($app) {    }  }); +$app->get('/new/last-photo.json', function() use($app) { +  if($user=require_login($app)) { +    $url = null; + +    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']; +      } +    } + +    $app->response()['Content-type'] = 'application/json'; +    $app->response()->body(json_encode(array( +      'url' => $url +    ))); +  } +}); +  $app->get('/bookmark', function() use($app) {    if($user=require_login($app)) {      $params = $app->request()->params(); diff --git a/views/new-post.php b/views/new-post.php index 726a671..7040308 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -340,6 +340,18 @@ function addNewPhoto() {  }  $(function(){ +  // Check if there's a pending file at the media endpoint +  $.getJSON("/new/last-photo.json", function(response){ +    if(response.url) { +      photos.push({ +        url: response.url, +        alt: null, +        external: true +      }); +      refreshPhotoPreviews(); +    } +  }); +    $("#note_photo").on("change", function(e){      // If the user has a media endpoint, upload the photo to it right now  | 
