{"action":"created","comment":{"url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/comments/38631833","id":38631833,"diff_hunk":"@@ -17,13 +21,43 @@\n                (.setParameterValue \"file-name\" fname)\n                (.setParameterValue \"mime-type\" fmime))))\n \n-(defn sign-file [server-url file ch]\n-  (let [fmap    (file->map file)\n-        edn-ize #(reader/read-string (.getResponseText (.-target %)))]\n-    (xhr/send (signing-url server-url (:name fmap) (:type fmap))\n-           (fn [res]\n-             (put! ch {:f file :signature (edn-ize res)})\n-             (close! ch)))))\n+(defn sign-file\n+  \"Takes a `server-url`, either an input map (with keys :file and optionally :identifier and :key),\n+  as `input-map-or-file` and a channel `ch`. Also takes a fn `edn-ize` which is for interpreting\n+  the server response text into edn.\n+  Takes a `key-fn` function that takes one argument (the filename) and generates a object-key to\n+  use to create the file on S3.\n+  Alternatively, if a :key key exists in the input-map, use that in preference to the key-fn as an object-key.\n+  Sends the request to the server-url to be signed.\"\n+  [server-url edn-ize key-fn input-map-or-file ch]\n+  (let [xhr      (XhrIo.)\n+        {:keys [file identifier] :as input-map}\n+                 (if (map? input-map-or-file)\n+                   input-map-or-file\n+                   {:file input-map-or-file})\n+        fmap     (file->map file)\n+        fmap     (cond\n+                   (:key input-map) (assoc fmap :name (:key input-map))\n+                   key-fn           (update-in fmap [:name] key-fn)\n+                   :else            fmap)]\n+    (events/listen xhr goog.net.EventType.SUCCESS\n+      (fn [_]\n+        (put! ch {:f file\n+                  :signature (edn-ize (.getResponseText xhr))\n+                  :identifier identifier})\n+        (close! ch)))\n+    (events/listen xhr goog.net.EventType.ERROR\n+      (fn [_]\n+        (let [error-code      (.getLastErrorCode xhr)\n+              error-message   (.getDebugMessage goog.net.ErrorCode error-code)\n+              http-error-code (.getStatus xhr)]\n+          (put! ch {:identifier      identifier\n+                    :error-code      error-code\n+                    :error-message   (str \"While trying to sign file: \"\n+                                           error-message)\n+                    :http-error-code http-error-code})\n+          (close! ch))))\n+    (. xhr (send (signing-url server-url (:name fmap) (:type fmap)) \"GET\" nil nil))))","path":"src/cljs/s3_beam/client.cljs","position":64,"original_position":64,"commit_id":"3c38c59c385e92faf437fc7e01bba3a4875ed118","original_commit_id":"3c38c59c385e92faf437fc7e01bba3a4875ed118","user":{"login":"GetContented","id":5661934,"avatar_url":"https://avatars.githubusercontent.com/u/5661934?v=3","gravatar_id":"","url":"https://api.github.com/users/GetContented","html_url":"https://github.com/GetContented","followers_url":"https://api.github.com/users/GetContented/followers","following_url":"https://api.github.com/users/GetContented/following{/other_user}","gists_url":"https://api.github.com/users/GetContented/gists{/gist_id}","starred_url":"https://api.github.com/users/GetContented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GetContented/subscriptions","organizations_url":"https://api.github.com/users/GetContented/orgs","repos_url":"https://api.github.com/users/GetContented/repos","events_url":"https://api.github.com/users/GetContented/events{/privacy}","received_events_url":"https://api.github.com/users/GetContented/received_events","type":"User","site_admin":false},"body":"Ok. I wasn't sure if the nils were optinoal. I'll remove the parens.","created_at":"2015-09-03T10:29:08Z","updated_at":"2015-09-03T10:29:08Z","html_url":"https://github.com/martinklepsch/s3-beam/pull/21#discussion_r38631833","pull_request_url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/comments/38631833"},"html":{"href":"https://github.com/martinklepsch/s3-beam/pull/21#discussion_r38631833"},"pull_request":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21","id":44064060,"html_url":"https://github.com/martinklepsch/s3-beam/pull/21","diff_url":"https://github.com/martinklepsch/s3-beam/pull/21.diff","patch_url":"https://github.com/martinklepsch/s3-beam/pull/21.patch","issue_url":"https://api.github.com/repos/martinklepsch/s3-beam/issues/21","number":21,"state":"open","locked":false,"title":"Handle Errors & Object Key Naming","user":{"login":"GetContented","id":5661934,"avatar_url":"https://avatars.githubusercontent.com/u/5661934?v=3","gravatar_id":"","url":"https://api.github.com/users/GetContented","html_url":"https://github.com/GetContented","followers_url":"https://api.github.com/users/GetContented/followers","following_url":"https://api.github.com/users/GetContented/following{/other_user}","gists_url":"https://api.github.com/users/GetContented/gists{/gist_id}","starred_url":"https://api.github.com/users/GetContented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GetContented/subscriptions","organizations_url":"https://api.github.com/users/GetContented/orgs","repos_url":"https://api.github.com/users/GetContented/repos","events_url":"https://api.github.com/users/GetContented/events{/privacy}","received_events_url":"https://api.github.com/users/GetContented/received_events","type":"User","site_admin":false},"body":"- Makes the s3-pipe put a response map of interpreted data from S3 onto its report-chan, instead of just the file object or location. \r\n- Makes so that the s3-pipe can have either a map or a file put onto its upload-file chan: in the case of the map, it will have a :file key that contains the file, and will later be adjusted to allow an \"object key\" key to be passed through as well. Add an identifier key to this map for later passing back on the response channel - for identification by the user code that handles the response - also pass the identifier back thru the upload-file function, too.\r\n- Make so that the sign-file handles errors and reports the errors back, and so that the upload-file function passes these errors through\r\n- Make so that upload-file function handles errors of its own - such as http errors, and response codes from AWS, and reports these back on the response map\r\n- Make so that s3-pipe can have a key-fn passed to it which will be used to generate file keys before signing\r\n- Make it so that the upload-file chan’s map can have an object key which will be used for the file key before signing which is preferred to the key-fn","created_at":"2015-09-03T02:34:39Z","updated_at":"2015-09-03T10:29:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca8a48ad2ed9ffb0550fbce12fb3bf7940efe90e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21/commits","review_comments_url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21/comments","review_comment_url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/martinklepsch/s3-beam/issues/21/comments","statuses_url":"https://api.github.com/repos/martinklepsch/s3-beam/statuses/3c38c59c385e92faf437fc7e01bba3a4875ed118","head":{"label":"GetContented:patch-5","ref":"patch-5","sha":"3c38c59c385e92faf437fc7e01bba3a4875ed118","user":{"login":"GetContented","id":5661934,"avatar_url":"https://avatars.githubusercontent.com/u/5661934?v=3","gravatar_id":"","url":"https://api.github.com/users/GetContented","html_url":"https://github.com/GetContented","followers_url":"https://api.github.com/users/GetContented/followers","following_url":"https://api.github.com/users/GetContented/following{/other_user}","gists_url":"https://api.github.com/users/GetContented/gists{/gist_id}","starred_url":"https://api.github.com/users/GetContented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GetContented/subscriptions","organizations_url":"https://api.github.com/users/GetContented/orgs","repos_url":"https://api.github.com/users/GetContented/repos","events_url":"https://api.github.com/users/GetContented/events{/privacy}","received_events_url":"https://api.github.com/users/GetContented/received_events","type":"User","site_admin":false},"repo":{"id":39669117,"name":"s3-beam","full_name":"GetContented/s3-beam","owner":{"login":"GetContented","id":5661934,"avatar_url":"https://avatars.githubusercontent.com/u/5661934?v=3","gravatar_id":"","url":"https://api.github.com/users/GetContented","html_url":"https://github.com/GetContented","followers_url":"https://api.github.com/users/GetContented/followers","following_url":"https://api.github.com/users/GetContented/following{/other_user}","gists_url":"https://api.github.com/users/GetContented/gists{/gist_id}","starred_url":"https://api.github.com/users/GetContented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GetContented/subscriptions","organizations_url":"https://api.github.com/users/GetContented/orgs","repos_url":"https://api.github.com/users/GetContented/repos","events_url":"https://api.github.com/users/GetContented/events{/privacy}","received_events_url":"https://api.github.com/users/GetContented/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/GetContented/s3-beam","description":"direct-to-S3 uploading using Clojure(script)","fork":true,"url":"https://api.github.com/repos/GetContented/s3-beam","forks_url":"https://api.github.com/repos/GetContented/s3-beam/forks","keys_url":"https://api.github.com/repos/GetContented/s3-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GetContented/s3-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GetContented/s3-beam/teams","hooks_url":"https://api.github.com/repos/GetContented/s3-beam/hooks","issue_events_url":"https://api.github.com/repos/GetContented/s3-beam/issues/events{/number}","events_url":"https://api.github.com/repos/GetContented/s3-beam/events","assignees_url":"https://api.github.com/repos/GetContented/s3-beam/assignees{/user}","branches_url":"https://api.github.com/repos/GetContented/s3-beam/branches{/branch}","tags_url":"https://api.github.com/repos/GetContented/s3-beam/tags","blobs_url":"https://api.github.com/repos/GetContented/s3-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GetContented/s3-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GetContented/s3-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/GetContented/s3-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GetContented/s3-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/GetContented/s3-beam/languages","stargazers_url":"https://api.github.com/repos/GetContented/s3-beam/stargazers","contributors_url":"https://api.github.com/repos/GetContented/s3-beam/contributors","subscribers_url":"https://api.github.com/repos/GetContented/s3-beam/subscribers","subscription_url":"https://api.github.com/repos/GetContented/s3-beam/subscription","commits_url":"https://api.github.com/repos/GetContented/s3-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/GetContented/s3-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/GetContented/s3-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/GetContented/s3-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/GetContented/s3-beam/contents/{+path}","compare_url":"https://api.github.com/repos/GetContented/s3-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GetContented/s3-beam/merges","archive_url":"https://api.github.com/repos/GetContented/s3-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GetContented/s3-beam/downloads","issues_url":"https://api.github.com/repos/GetContented/s3-beam/issues{/number}","pulls_url":"https://api.github.com/repos/GetContented/s3-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/GetContented/s3-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/GetContented/s3-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GetContented/s3-beam/labels{/name}","releases_url":"https://api.github.com/repos/GetContented/s3-beam/releases{/id}","created_at":"2015-07-25T02:09:56Z","updated_at":"2015-07-25T02:09:57Z","pushed_at":"2015-09-03T02:34:28Z","git_url":"git://github.com/GetContented/s3-beam.git","ssh_url":"git@github.com:GetContented/s3-beam.git","clone_url":"https://github.com/GetContented/s3-beam.git","svn_url":"https://github.com/GetContented/s3-beam","homepage":"","size":157,"stargazers_count":0,"watchers_count":0,"language":"Clojure","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":"martinklepsch:master","ref":"master","sha":"ae6f353142f657464a15fdfe556a8a720ee9969d","user":{"login":"martinklepsch","id":97496,"avatar_url":"https://avatars.githubusercontent.com/u/97496?v=3","gravatar_id":"","url":"https://api.github.com/users/martinklepsch","html_url":"https://github.com/martinklepsch","followers_url":"https://api.github.com/users/martinklepsch/followers","following_url":"https://api.github.com/users/martinklepsch/following{/other_user}","gists_url":"https://api.github.com/users/martinklepsch/gists{/gist_id}","starred_url":"https://api.github.com/users/martinklepsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinklepsch/subscriptions","organizations_url":"https://api.github.com/users/martinklepsch/orgs","repos_url":"https://api.github.com/users/martinklepsch/repos","events_url":"https://api.github.com/users/martinklepsch/events{/privacy}","received_events_url":"https://api.github.com/users/martinklepsch/received_events","type":"User","site_admin":false},"repo":{"id":25460377,"name":"s3-beam","full_name":"martinklepsch/s3-beam","owner":{"login":"martinklepsch","id":97496,"avatar_url":"https://avatars.githubusercontent.com/u/97496?v=3","gravatar_id":"","url":"https://api.github.com/users/martinklepsch","html_url":"https://github.com/martinklepsch","followers_url":"https://api.github.com/users/martinklepsch/followers","following_url":"https://api.github.com/users/martinklepsch/following{/other_user}","gists_url":"https://api.github.com/users/martinklepsch/gists{/gist_id}","starred_url":"https://api.github.com/users/martinklepsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinklepsch/subscriptions","organizations_url":"https://api.github.com/users/martinklepsch/orgs","repos_url":"https://api.github.com/users/martinklepsch/repos","events_url":"https://api.github.com/users/martinklepsch/events{/privacy}","received_events_url":"https://api.github.com/users/martinklepsch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/martinklepsch/s3-beam","description":"direct-to-S3 uploading using ClojureScript","fork":false,"url":"https://api.github.com/repos/martinklepsch/s3-beam","forks_url":"https://api.github.com/repos/martinklepsch/s3-beam/forks","keys_url":"https://api.github.com/repos/martinklepsch/s3-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/martinklepsch/s3-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/martinklepsch/s3-beam/teams","hooks_url":"https://api.github.com/repos/martinklepsch/s3-beam/hooks","issue_events_url":"https://api.github.com/repos/martinklepsch/s3-beam/issues/events{/number}","events_url":"https://api.github.com/repos/martinklepsch/s3-beam/events","assignees_url":"https://api.github.com/repos/martinklepsch/s3-beam/assignees{/user}","branches_url":"https://api.github.com/repos/martinklepsch/s3-beam/branches{/branch}","tags_url":"https://api.github.com/repos/martinklepsch/s3-beam/tags","blobs_url":"https://api.github.com/repos/martinklepsch/s3-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/martinklepsch/s3-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/martinklepsch/s3-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/martinklepsch/s3-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/martinklepsch/s3-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/martinklepsch/s3-beam/languages","stargazers_url":"https://api.github.com/repos/martinklepsch/s3-beam/stargazers","contributors_url":"https://api.github.com/repos/martinklepsch/s3-beam/contributors","subscribers_url":"https://api.github.com/repos/martinklepsch/s3-beam/subscribers","subscription_url":"https://api.github.com/repos/martinklepsch/s3-beam/subscription","commits_url":"https://api.github.com/repos/martinklepsch/s3-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/martinklepsch/s3-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/martinklepsch/s3-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/martinklepsch/s3-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/martinklepsch/s3-beam/contents/{+path}","compare_url":"https://api.github.com/repos/martinklepsch/s3-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/martinklepsch/s3-beam/merges","archive_url":"https://api.github.com/repos/martinklepsch/s3-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/martinklepsch/s3-beam/downloads","issues_url":"https://api.github.com/repos/martinklepsch/s3-beam/issues{/number}","pulls_url":"https://api.github.com/repos/martinklepsch/s3-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/martinklepsch/s3-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/martinklepsch/s3-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/martinklepsch/s3-beam/labels{/name}","releases_url":"https://api.github.com/repos/martinklepsch/s3-beam/releases{/id}","created_at":"2014-10-20T09:53:44Z","updated_at":"2015-08-13T04:22:36Z","pushed_at":"2015-09-03T02:34:40Z","git_url":"git://github.com/martinklepsch/s3-beam.git","ssh_url":"git@github.com:martinklepsch/s3-beam.git","clone_url":"https://github.com/martinklepsch/s3-beam.git","svn_url":"https://github.com/martinklepsch/s3-beam","homepage":"","size":297,"stargazers_count":34,"watchers_count":34,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":6,"forks":6,"open_issues":6,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21"},"html":{"href":"https://github.com/martinklepsch/s3-beam/pull/21"},"issue":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/issues/21"},"comments":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/martinklepsch/s3-beam/statuses/3c38c59c385e92faf437fc7e01bba3a4875ed118"}}}}