summaryrefslogtreecommitdiff
path: root/controllers/controllers.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/controllers.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/controllers.php')
-rw-r--r--controllers/controllers.php28
1 files changed, 27 insertions, 1 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index 4373fcf..2a90892 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -76,6 +76,7 @@ $app->get('/new', function() use($app) {
'title' => 'New Post',
'in_reply_to' => $in_reply_to,
'micropub_endpoint' => $user->micropub_endpoint,
+ 'media_endpoint' => $user->micropub_media_endpoint,
'micropub_scope' => $user->micropub_scope,
'micropub_access_token' => $user->micropub_access_token,
'response_date' => $user->last_micropub_response_date,
@@ -452,7 +453,7 @@ $app->post('/repost', function() use($app) {
$app->get('/micropub/syndications', function() use($app) {
if($user=require_login($app)) {
- $data = get_syndication_targets($user);
+ $data = get_micropub_config($user, ['q'=>'syndicate-to']);
$app->response()->body(json_encode(array(
'targets' => $data['targets'],
'response' => $data['response']
@@ -522,6 +523,31 @@ $app->post('/micropub/multipart', function() use($app) {
}
});
+$app->post('/micropub/media', function() use($app) {
+ if($user=require_login($app)) {
+ $file = isset($_FILES['photo']) ? $_FILES['photo'] : null;
+ $error = validate_photo($file);
+ unset($_POST['null']);
+
+ if(!$error) {
+ $file_path = $file['tmp_name'];
+ correct_photo_rotation($file_path);
+ $r = micropub_media_post_for_user($user, $file_path);
+ } else {
+ $r = array('error' => $error);
+ }
+
+ if(empty($r['location']) && empty($r['error'])) {
+ $r['error'] = "No 'Location' header in response.";
+ }
+
+ $app->response()->body(json_encode(array(
+ 'location' => (isset($r['location']) ? $r['location'] : null),
+ 'error' => (isset($r['error']) ? $r['error'] : null),
+ )));
+ }
+});
+
$app->post('/micropub/postjson', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();