{"action":"created","comment":{"url":"https://api.github.com/repos/vinidy/food/pulls/comments/35033210","id":35033210,"diff_hunk":"@@ -65,37 +67,63 @@ module.exports = function(app, passport) {\n \t});\n \n   // Posts\n-  app.post('/api/user/post', isLoggedIn, function(req, res, next) {\n+  app.post('/api/user/post', isLoggedIn, multer({limits: {fileSize:5*1024*1024}}), function(req, res, next) {\n     var newPost = new Post();\n     newPost.created = newPost.updated = moment();\n     newPost.user = req.user;\n-    newPost.url = ''; // Add image to S3 and Store image reference to Post model [url]\n \n-    // Need to find a better way to insert comment, if it exists, into a post\n-    if(req.body.comment) {\n-      var newComment = new Comment();\n-      newComment.created = newComment.updated = moment();\n-      newComment.text = req.body.comment;\n-      newComment.save();\n+    // get bucket\n+    var bucket = new AWS.S3({params: {Bucket: 'lemonapp'}});\n \n-      newComment.save(function(err, comment) {\n-        newPost.comments.push(comment);\n-\n-        newPost.save(function(err, post) {\n-          if(err)\n-            throw err;\n+    if (!req.files) {\n+        return res.status(403).send('expect 1 file upload named upload').end();\n+    }\n \n-          res.redirect('/user/post/' + post._id);\n-        });\n-      });\n-    } else {\n-      newPost.save(function(err, post) {\n-        if(err)\n-          throw err;\n+    var file = req.files.photo;\n \n-        res.redirect('/user/post/' + post._id);\n-      });\n+    if (!/^image\\/(jpe?g|png|gif)$/i.test(file.mimetype)) {\n+      return res.status(403).send('expect image file').end();\n     }\n+\n+    var pid = '10000' + parseInt(Math.random() * 10000000);\n+\n+    // upload\n+    bucket.upload({\n+      ACL: 'public-read',\n+      Body: fs.createReadStream(file.path),\n+      Key: pid.toString(),","path":"app/routes.js","position":67,"original_position":67,"commit_id":"38c805488f5517367ed7017b5c46c27685bd5049","original_commit_id":"38c805488f5517367ed7017b5c46c27685bd5049","user":{"login":"vinidy","id":580090,"avatar_url":"https://avatars.githubusercontent.com/u/580090?v=3","gravatar_id":"","url":"https://api.github.com/users/vinidy","html_url":"https://github.com/vinidy","followers_url":"https://api.github.com/users/vinidy/followers","following_url":"https://api.github.com/users/vinidy/following{/other_user}","gists_url":"https://api.github.com/users/vinidy/gists{/gist_id}","starred_url":"https://api.github.com/users/vinidy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinidy/subscriptions","organizations_url":"https://api.github.com/users/vinidy/orgs","repos_url":"https://api.github.com/users/vinidy/repos","events_url":"https://api.github.com/users/vinidy/events{/privacy}","received_events_url":"https://api.github.com/users/vinidy/received_events","type":"User","site_admin":false},"body":"Why?","created_at":"2015-07-20T19:25:54Z","updated_at":"2015-07-20T19:25:54Z","html_url":"https://github.com/vinidy/food/pull/13#discussion_r35033210","pull_request_url":"https://api.github.com/repos/vinidy/food/pulls/13","_links":{"self":{"href":"https://api.github.com/repos/vinidy/food/pulls/comments/35033210"},"html":{"href":"https://github.com/vinidy/food/pull/13#discussion_r35033210"},"pull_request":{"href":"https://api.github.com/repos/vinidy/food/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/vinidy/food/pulls/13","id":40384272,"html_url":"https://github.com/vinidy/food/pull/13","diff_url":"https://github.com/vinidy/food/pull/13.diff","patch_url":"https://github.com/vinidy/food/pull/13.patch","issue_url":"https://api.github.com/repos/vinidy/food/issues/13","number":13,"state":"open","locked":false,"title":"S3 Post Integration","user":{"login":"johnstew","id":2146973,"avatar_url":"https://avatars.githubusercontent.com/u/2146973?v=3","gravatar_id":"","url":"https://api.github.com/users/johnstew","html_url":"https://github.com/johnstew","followers_url":"https://api.github.com/users/johnstew/followers","following_url":"https://api.github.com/users/johnstew/following{/other_user}","gists_url":"https://api.github.com/users/johnstew/gists{/gist_id}","starred_url":"https://api.github.com/users/johnstew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnstew/subscriptions","organizations_url":"https://api.github.com/users/johnstew/orgs","repos_url":"https://api.github.com/users/johnstew/repos","events_url":"https://api.github.com/users/johnstew/events{/privacy}","received_events_url":"https://api.github.com/users/johnstew/received_events","type":"User","site_admin":false},"body":"S3 Post Integration","created_at":"2015-07-20T18:50:30Z","updated_at":"2015-07-20T19:25:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"020a94f1dbaf318607ca40fcaefeb49dbe350aa0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vinidy/food/pulls/13/commits","review_comments_url":"https://api.github.com/repos/vinidy/food/pulls/13/comments","review_comment_url":"https://api.github.com/repos/vinidy/food/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vinidy/food/issues/13/comments","statuses_url":"https://api.github.com/repos/vinidy/food/statuses/38c805488f5517367ed7017b5c46c27685bd5049","head":{"label":"johnstew:master","ref":"master","sha":"38c805488f5517367ed7017b5c46c27685bd5049","user":{"login":"johnstew","id":2146973,"avatar_url":"https://avatars.githubusercontent.com/u/2146973?v=3","gravatar_id":"","url":"https://api.github.com/users/johnstew","html_url":"https://github.com/johnstew","followers_url":"https://api.github.com/users/johnstew/followers","following_url":"https://api.github.com/users/johnstew/following{/other_user}","gists_url":"https://api.github.com/users/johnstew/gists{/gist_id}","starred_url":"https://api.github.com/users/johnstew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnstew/subscriptions","organizations_url":"https://api.github.com/users/johnstew/orgs","repos_url":"https://api.github.com/users/johnstew/repos","events_url":"https://api.github.com/users/johnstew/events{/privacy}","received_events_url":"https://api.github.com/users/johnstew/received_events","type":"User","site_admin":false},"repo":{"id":39154208,"name":"food","full_name":"johnstew/food","owner":{"login":"johnstew","id":2146973,"avatar_url":"https://avatars.githubusercontent.com/u/2146973?v=3","gravatar_id":"","url":"https://api.github.com/users/johnstew","html_url":"https://github.com/johnstew","followers_url":"https://api.github.com/users/johnstew/followers","following_url":"https://api.github.com/users/johnstew/following{/other_user}","gists_url":"https://api.github.com/users/johnstew/gists{/gist_id}","starred_url":"https://api.github.com/users/johnstew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnstew/subscriptions","organizations_url":"https://api.github.com/users/johnstew/orgs","repos_url":"https://api.github.com/users/johnstew/repos","events_url":"https://api.github.com/users/johnstew/events{/privacy}","received_events_url":"https://api.github.com/users/johnstew/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/johnstew/food","description":"","fork":true,"url":"https://api.github.com/repos/johnstew/food","forks_url":"https://api.github.com/repos/johnstew/food/forks","keys_url":"https://api.github.com/repos/johnstew/food/keys{/key_id}","collaborators_url":"https://api.github.com/repos/johnstew/food/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/johnstew/food/teams","hooks_url":"https://api.github.com/repos/johnstew/food/hooks","issue_events_url":"https://api.github.com/repos/johnstew/food/issues/events{/number}","events_url":"https://api.github.com/repos/johnstew/food/events","assignees_url":"https://api.github.com/repos/johnstew/food/assignees{/user}","branches_url":"https://api.github.com/repos/johnstew/food/branches{/branch}","tags_url":"https://api.github.com/repos/johnstew/food/tags","blobs_url":"https://api.github.com/repos/johnstew/food/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/johnstew/food/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/johnstew/food/git/refs{/sha}","trees_url":"https://api.github.com/repos/johnstew/food/git/trees{/sha}","statuses_url":"https://api.github.com/repos/johnstew/food/statuses/{sha}","languages_url":"https://api.github.com/repos/johnstew/food/languages","stargazers_url":"https://api.github.com/repos/johnstew/food/stargazers","contributors_url":"https://api.github.com/repos/johnstew/food/contributors","subscribers_url":"https://api.github.com/repos/johnstew/food/subscribers","subscription_url":"https://api.github.com/repos/johnstew/food/subscription","commits_url":"https://api.github.com/repos/johnstew/food/commits{/sha}","git_commits_url":"https://api.github.com/repos/johnstew/food/git/commits{/sha}","comments_url":"https://api.github.com/repos/johnstew/food/comments{/number}","issue_comment_url":"https://api.github.com/repos/johnstew/food/issues/comments{/number}","contents_url":"https://api.github.com/repos/johnstew/food/contents/{+path}","compare_url":"https://api.github.com/repos/johnstew/food/compare/{base}...{head}","merges_url":"https://api.github.com/repos/johnstew/food/merges","archive_url":"https://api.github.com/repos/johnstew/food/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/johnstew/food/downloads","issues_url":"https://api.github.com/repos/johnstew/food/issues{/number}","pulls_url":"https://api.github.com/repos/johnstew/food/pulls{/number}","milestones_url":"https://api.github.com/repos/johnstew/food/milestones{/number}","notifications_url":"https://api.github.com/repos/johnstew/food/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/johnstew/food/labels{/name}","releases_url":"https://api.github.com/repos/johnstew/food/releases{/id}","created_at":"2015-07-15T18:36:02Z","updated_at":"2015-07-15T18:36:03Z","pushed_at":"2015-07-20T18:49:29Z","git_url":"git://github.com/johnstew/food.git","ssh_url":"git@github.com:johnstew/food.git","clone_url":"https://github.com/johnstew/food.git","svn_url":"https://github.com/johnstew/food","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"vinidy:master","ref":"master","sha":"8f3b1d840d3a1613da00786e98ec4753f936e254","user":{"login":"vinidy","id":580090,"avatar_url":"https://avatars.githubusercontent.com/u/580090?v=3","gravatar_id":"","url":"https://api.github.com/users/vinidy","html_url":"https://github.com/vinidy","followers_url":"https://api.github.com/users/vinidy/followers","following_url":"https://api.github.com/users/vinidy/following{/other_user}","gists_url":"https://api.github.com/users/vinidy/gists{/gist_id}","starred_url":"https://api.github.com/users/vinidy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinidy/subscriptions","organizations_url":"https://api.github.com/users/vinidy/orgs","repos_url":"https://api.github.com/users/vinidy/repos","events_url":"https://api.github.com/users/vinidy/events{/privacy}","received_events_url":"https://api.github.com/users/vinidy/received_events","type":"User","site_admin":false},"repo":{"id":39098863,"name":"food","full_name":"vinidy/food","owner":{"login":"vinidy","id":580090,"avatar_url":"https://avatars.githubusercontent.com/u/580090?v=3","gravatar_id":"","url":"https://api.github.com/users/vinidy","html_url":"https://github.com/vinidy","followers_url":"https://api.github.com/users/vinidy/followers","following_url":"https://api.github.com/users/vinidy/following{/other_user}","gists_url":"https://api.github.com/users/vinidy/gists{/gist_id}","starred_url":"https://api.github.com/users/vinidy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinidy/subscriptions","organizations_url":"https://api.github.com/users/vinidy/orgs","repos_url":"https://api.github.com/users/vinidy/repos","events_url":"https://api.github.com/users/vinidy/events{/privacy}","received_events_url":"https://api.github.com/users/vinidy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vinidy/food","description":"","fork":false,"url":"https://api.github.com/repos/vinidy/food","forks_url":"https://api.github.com/repos/vinidy/food/forks","keys_url":"https://api.github.com/repos/vinidy/food/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vinidy/food/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vinidy/food/teams","hooks_url":"https://api.github.com/repos/vinidy/food/hooks","issue_events_url":"https://api.github.com/repos/vinidy/food/issues/events{/number}","events_url":"https://api.github.com/repos/vinidy/food/events","assignees_url":"https://api.github.com/repos/vinidy/food/assignees{/user}","branches_url":"https://api.github.com/repos/vinidy/food/branches{/branch}","tags_url":"https://api.github.com/repos/vinidy/food/tags","blobs_url":"https://api.github.com/repos/vinidy/food/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vinidy/food/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vinidy/food/git/refs{/sha}","trees_url":"https://api.github.com/repos/vinidy/food/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vinidy/food/statuses/{sha}","languages_url":"https://api.github.com/repos/vinidy/food/languages","stargazers_url":"https://api.github.com/repos/vinidy/food/stargazers","contributors_url":"https://api.github.com/repos/vinidy/food/contributors","subscribers_url":"https://api.github.com/repos/vinidy/food/subscribers","subscription_url":"https://api.github.com/repos/vinidy/food/subscription","commits_url":"https://api.github.com/repos/vinidy/food/commits{/sha}","git_commits_url":"https://api.github.com/repos/vinidy/food/git/commits{/sha}","comments_url":"https://api.github.com/repos/vinidy/food/comments{/number}","issue_comment_url":"https://api.github.com/repos/vinidy/food/issues/comments{/number}","contents_url":"https://api.github.com/repos/vinidy/food/contents/{+path}","compare_url":"https://api.github.com/repos/vinidy/food/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vinidy/food/merges","archive_url":"https://api.github.com/repos/vinidy/food/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vinidy/food/downloads","issues_url":"https://api.github.com/repos/vinidy/food/issues{/number}","pulls_url":"https://api.github.com/repos/vinidy/food/pulls{/number}","milestones_url":"https://api.github.com/repos/vinidy/food/milestones{/number}","notifications_url":"https://api.github.com/repos/vinidy/food/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vinidy/food/labels{/name}","releases_url":"https://api.github.com/repos/vinidy/food/releases{/id}","created_at":"2015-07-14T20:31:47Z","updated_at":"2015-07-14T20:35:03Z","pushed_at":"2015-07-20T18:50:31Z","git_url":"git://github.com/vinidy/food.git","ssh_url":"git@github.com:vinidy/food.git","clone_url":"https://github.com/vinidy/food.git","svn_url":"https://github.com/vinidy/food","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vinidy/food/pulls/13"},"html":{"href":"https://github.com/vinidy/food/pull/13"},"issue":{"href":"https://api.github.com/repos/vinidy/food/issues/13"},"comments":{"href":"https://api.github.com/repos/vinidy/food/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/vinidy/food/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/vinidy/food/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vinidy/food/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/vinidy/food/statuses/38c805488f5517367ed7017b5c46c27685bd5049"}}}}