summaryrefslogtreecommitdiff
path: root/controllers/editor.php
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2016-05-11 17:47:17 +0200
committerAaron Parecki <aaron@parecki.com>2016-05-11 17:47:17 +0200
commit542aa812f8606dad16ab456c3e5da438cc501644 (patch)
tree1a5b071eda488c11d6958a8c6cde83a5e09c8d4c /controllers/editor.php
parent29f0c9b0543cdbf7780ce6e45204bd62a4ba4f52 (diff)
support media endpoint, autosave notes in local storage
* looks for a media endpoint in the micropub config * if media endpoint is available, both the note interface and the editor will upload files to it instead of posting the photo directly * the note interface autosaves in-progress notes in localstorage
Diffstat (limited to 'controllers/editor.php')
-rw-r--r--controllers/editor.php33
1 files changed, 22 insertions, 11 deletions
diff --git a/controllers/editor.php b/controllers/editor.php
index a3c0496..fbb72cf 100644
--- a/controllers/editor.php
+++ b/controllers/editor.php
@@ -35,19 +35,30 @@ $app->post('/editor/publish', function() use($app) {
});
$app->post('/editor/upload', function() use($app) {
- // Fake a file uploader by echo'ing back the data URI
- $fn = $_FILES['files']['tmp_name'][0];
- $imageData = base64_encode(file_get_contents($fn));
- $src = 'data:'.mime_content_type($fn).';base64,'.$imageData;
+ if($user=require_login($app)) {
+ $fn = $_FILES['files']['tmp_name'][0];
+ $imageURL = false;
- $app->response()['Content-type'] = 'application/json';
- $app->response()->body(json_encode([
- 'files' => [
- [
- 'url'=>$src
+ if($user->micropub_media_endpoint) {
+ // If the user has a media endpoint, upload to that and return that URL
+ correct_photo_rotation($fn);
+ $r = micropub_media_post_for_user($user, $fn);
+ if(!empty($r['location'])) {
+ $imageURL = $r['location'];
+ }
+ }
+ if(!$imageURL) {
+ // Otherwise, fake a file uploader by echo'ing back the data URI
+ $imageData = base64_encode(file_get_contents($fn));
+ $imageURL = 'data:'.mime_content_type($fn).';base64,'.$imageData;
+ }
+ $app->response()['Content-type'] = 'application/json';
+ $app->response()->body(json_encode([
+ 'files' => [
+ ['url'=>$imageURL]
]
- ]
- ]));
+ ]));
+ }
});
$app->post('/editor/delete-file', function() use($app) {