Browse Source

query the media endpoint for the last photo uploaded

pull/96/head
Aaron Parecki 7 years ago
parent
commit
97ba7d0347
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 19
      controllers/controllers.php
  2. 12
      views/new-post.php

19
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();

12
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

Loading…
Cancel
Save