{"action":"created","comment":{"url":"https://api.github.com/repos/transloadit/uppy/pulls/comments/122453553","pull_request_review_id":44573137,"id":122453553,"diff_hunk":"@@ -147,9 +149,73 @@ function runPromiseSequence (functions, ...args) {\n //   return (!f && 'not a function') || (s && s[1] || 'anonymous')\n // }\n \n+function isPreviewSupported (fileTypeSpecific) {\n+  // list of images that browsers can preview\n+  if (/^(jpeg|gif|png|svg|svg\\+xml|bmp)$/.test(fileTypeSpecific)) {\n+    return true\n+  }\n+  return false\n+}\n+\n+function getArrayBuffer (file) {\n+  return new Promise(function (resolve, reject) {\n+    var reader = new FileReader()\n+    reader.addEventListener('load', function (e) {\n+      // e.target.result is an ArrayBuffer\n+      resolve(e.target.result)\n+    })\n+    reader.addEventListener('error', function (err) {\n+      console.error('FileReader error' + err)\n+      reject(err)\n+    })\n+    // file-type only needs the first 4100 bytes\n+    const chunk = file.data.slice(0, 4100)\n+    reader.readAsArrayBuffer(chunk)\n+  })\n+}\n+\n function getFileType (file) {\n-  return file.type ? file.type.split('/') : ['', '']\n-  // return mime.lookup(file.name)\n+  const emptyFileType = ['', '']\n+  const extensionsToMime = {\n+    'md': 'text/markdown',\n+    'markdown': 'text/markdown',\n+    'mp4': 'video/mp4',\n+    'mp3': 'audio/mp3'\n+  }\n+\n+  const fileExtension = getFileNameAndExtension(file.name)[1]\n+\n+  // 1. try to determine file type from magic bytes with file-type module\n+  // this should be the most trustworthy way\n+  return getArrayBuffer(file)\n+    .then((buffer) => {\n+      const type = fileType(buffer)\n+      if (type && type.mime) {\n+        return type.mime.split('/')\n+      }\n+\n+      // 2. if that’s no good, check if mime type is set in the file object\n+      if (file.type) {\n+        return Promise.resolve(file.type.split('/'))","path":"src/core/Utils.js","position":64,"original_position":64,"commit_id":"24816d2c5bd6ec0ffcb65cc8f3e89401ef6fa82a","original_commit_id":"24816d2c5bd6ec0ffcb65cc8f3e89401ef6fa82a","user":{"login":"goto-bus-stop","id":1006268,"avatar_url":"https://avatars2.githubusercontent.com/u/1006268?v=3","gravatar_id":"","url":"https://api.github.com/users/goto-bus-stop","html_url":"https://github.com/goto-bus-stop","followers_url":"https://api.github.com/users/goto-bus-stop/followers","following_url":"https://api.github.com/users/goto-bus-stop/following{/other_user}","gists_url":"https://api.github.com/users/goto-bus-stop/gists{/gist_id}","starred_url":"https://api.github.com/users/goto-bus-stop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goto-bus-stop/subscriptions","organizations_url":"https://api.github.com/users/goto-bus-stop/orgs","repos_url":"https://api.github.com/users/goto-bus-stop/repos","events_url":"https://api.github.com/users/goto-bus-stop/events{/privacy}","received_events_url":"https://api.github.com/users/goto-bus-stop/received_events","type":"User","site_admin":false},"body":"Tiniest of nits, but this `Promise.resolve` isn't strictly necessary","created_at":"2017-06-16T14:24:33Z","updated_at":"2017-06-16T14:43:50Z","html_url":"https://github.com/transloadit/uppy/pull/219#discussion_r122453553","pull_request_url":"https://api.github.com/repos/transloadit/uppy/pulls/219","_links":{"self":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/comments/122453553"},"html":{"href":"https://github.com/transloadit/uppy/pull/219#discussion_r122453553"},"pull_request":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/219"}}},"pull_request":{"url":"https://api.github.com/repos/transloadit/uppy/pulls/219","id":125278651,"html_url":"https://github.com/transloadit/uppy/pull/219","diff_url":"https://github.com/transloadit/uppy/pull/219.diff","patch_url":"https://github.com/transloadit/uppy/pull/219.patch","issue_url":"https://api.github.com/repos/transloadit/uppy/issues/219","number":219,"state":"open","locked":false,"title":"[WIP] Better file type detection","user":{"login":"arturi","id":1199054,"avatar_url":"https://avatars1.githubusercontent.com/u/1199054?v=3","gravatar_id":"","url":"https://api.github.com/users/arturi","html_url":"https://github.com/arturi","followers_url":"https://api.github.com/users/arturi/followers","following_url":"https://api.github.com/users/arturi/following{/other_user}","gists_url":"https://api.github.com/users/arturi/gists{/gist_id}","starred_url":"https://api.github.com/users/arturi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arturi/subscriptions","organizations_url":"https://api.github.com/users/arturi/orgs","repos_url":"https://api.github.com/users/arturi/repos","events_url":"https://api.github.com/users/arturi/events{/privacy}","received_events_url":"https://api.github.com/users/arturi/received_events","type":"User","site_admin":false},"body":"1. This PR adds [`file-type`](https://github.com/sindresorhus/file-type) module to help detect binary mime-type by looking at the first few magic bytes of that file. This fixes `.avi` detection for me, for example — recognized as a video now. But needs some thought, as currently it fails to detect markdown, for instance, or word/docx. Should we add those types based on file extension and maintain a relatively small list of commonly used ones, or is there a better way? And if we rely on said list, should we not use `file-type` at all then?\r\n\r\n2. `isPreviewReady` method is checking whether the file is previewable, to address this:\r\n    > uppy detects `.xcf` files (from gimp) as images, but they can't be previewed in browsers. maybe we can maintain an image/{png,jpg,...} whitelist for previews? there might be an npm module for that :laughing:\r\n","created_at":"2017-06-13T04:59:18Z","updated_at":"2017-06-16T14:43:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5be4c424ad2439c1ba1fa5b2af8064eaa84532fb","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/transloadit/uppy/pulls/219/commits","review_comments_url":"https://api.github.com/repos/transloadit/uppy/pulls/219/comments","review_comment_url":"https://api.github.com/repos/transloadit/uppy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/transloadit/uppy/issues/219/comments","statuses_url":"https://api.github.com/repos/transloadit/uppy/statuses/24816d2c5bd6ec0ffcb65cc8f3e89401ef6fa82a","head":{"label":"transloadit:feature/file-types","ref":"feature/file-types","sha":"24816d2c5bd6ec0ffcb65cc8f3e89401ef6fa82a","user":{"login":"transloadit","id":125754,"avatar_url":"https://avatars1.githubusercontent.com/u/125754?v=3","gravatar_id":"","url":"https://api.github.com/users/transloadit","html_url":"https://github.com/transloadit","followers_url":"https://api.github.com/users/transloadit/followers","following_url":"https://api.github.com/users/transloadit/following{/other_user}","gists_url":"https://api.github.com/users/transloadit/gists{/gist_id}","starred_url":"https://api.github.com/users/transloadit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transloadit/subscriptions","organizations_url":"https://api.github.com/users/transloadit/orgs","repos_url":"https://api.github.com/users/transloadit/repos","events_url":"https://api.github.com/users/transloadit/events{/privacy}","received_events_url":"https://api.github.com/users/transloadit/received_events","type":"Organization","site_admin":false},"repo":{"id":46273445,"name":"uppy","full_name":"transloadit/uppy","owner":{"login":"transloadit","id":125754,"avatar_url":"https://avatars1.githubusercontent.com/u/125754?v=3","gravatar_id":"","url":"https://api.github.com/users/transloadit","html_url":"https://github.com/transloadit","followers_url":"https://api.github.com/users/transloadit/followers","following_url":"https://api.github.com/users/transloadit/following{/other_user}","gists_url":"https://api.github.com/users/transloadit/gists{/gist_id}","starred_url":"https://api.github.com/users/transloadit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transloadit/subscriptions","organizations_url":"https://api.github.com/users/transloadit/orgs","repos_url":"https://api.github.com/users/transloadit/repos","events_url":"https://api.github.com/users/transloadit/events{/privacy}","received_events_url":"https://api.github.com/users/transloadit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/transloadit/uppy","description":"The next open source file uploader for web browsers :dog: ","fork":false,"url":"https://api.github.com/repos/transloadit/uppy","forks_url":"https://api.github.com/repos/transloadit/uppy/forks","keys_url":"https://api.github.com/repos/transloadit/uppy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/transloadit/uppy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/transloadit/uppy/teams","hooks_url":"https://api.github.com/repos/transloadit/uppy/hooks","issue_events_url":"https://api.github.com/repos/transloadit/uppy/issues/events{/number}","events_url":"https://api.github.com/repos/transloadit/uppy/events","assignees_url":"https://api.github.com/repos/transloadit/uppy/assignees{/user}","branches_url":"https://api.github.com/repos/transloadit/uppy/branches{/branch}","tags_url":"https://api.github.com/repos/transloadit/uppy/tags","blobs_url":"https://api.github.com/repos/transloadit/uppy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/transloadit/uppy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/transloadit/uppy/git/refs{/sha}","trees_url":"https://api.github.com/repos/transloadit/uppy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/transloadit/uppy/statuses/{sha}","languages_url":"https://api.github.com/repos/transloadit/uppy/languages","stargazers_url":"https://api.github.com/repos/transloadit/uppy/stargazers","contributors_url":"https://api.github.com/repos/transloadit/uppy/contributors","subscribers_url":"https://api.github.com/repos/transloadit/uppy/subscribers","subscription_url":"https://api.github.com/repos/transloadit/uppy/subscription","commits_url":"https://api.github.com/repos/transloadit/uppy/commits{/sha}","git_commits_url":"https://api.github.com/repos/transloadit/uppy/git/commits{/sha}","comments_url":"https://api.github.com/repos/transloadit/uppy/comments{/number}","issue_comment_url":"https://api.github.com/repos/transloadit/uppy/issues/comments{/number}","contents_url":"https://api.github.com/repos/transloadit/uppy/contents/{+path}","compare_url":"https://api.github.com/repos/transloadit/uppy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/transloadit/uppy/merges","archive_url":"https://api.github.com/repos/transloadit/uppy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/transloadit/uppy/downloads","issues_url":"https://api.github.com/repos/transloadit/uppy/issues{/number}","pulls_url":"https://api.github.com/repos/transloadit/uppy/pulls{/number}","milestones_url":"https://api.github.com/repos/transloadit/uppy/milestones{/number}","notifications_url":"https://api.github.com/repos/transloadit/uppy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/transloadit/uppy/labels{/name}","releases_url":"https://api.github.com/repos/transloadit/uppy/releases{/id}","deployments_url":"https://api.github.com/repos/transloadit/uppy/deployments","created_at":"2015-11-16T12:32:33Z","updated_at":"2017-06-16T02:24:21Z","pushed_at":"2017-06-15T23:50:09Z","git_url":"git://github.com/transloadit/uppy.git","ssh_url":"git@github.com:transloadit/uppy.git","clone_url":"https://github.com/transloadit/uppy.git","svn_url":"https://github.com/transloadit/uppy","homepage":"http://uppy.io","size":21069,"stargazers_count":2651,"watchers_count":2651,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":91,"mirror_url":null,"open_issues_count":41,"forks":91,"open_issues":41,"watchers":2651,"default_branch":"master"}},"base":{"label":"transloadit:master","ref":"master","sha":"a4973bf1ea5d9f296132cbfe07ed7bc50d101b5a","user":{"login":"transloadit","id":125754,"avatar_url":"https://avatars1.githubusercontent.com/u/125754?v=3","gravatar_id":"","url":"https://api.github.com/users/transloadit","html_url":"https://github.com/transloadit","followers_url":"https://api.github.com/users/transloadit/followers","following_url":"https://api.github.com/users/transloadit/following{/other_user}","gists_url":"https://api.github.com/users/transloadit/gists{/gist_id}","starred_url":"https://api.github.com/users/transloadit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transloadit/subscriptions","organizations_url":"https://api.github.com/users/transloadit/orgs","repos_url":"https://api.github.com/users/transloadit/repos","events_url":"https://api.github.com/users/transloadit/events{/privacy}","received_events_url":"https://api.github.com/users/transloadit/received_events","type":"Organization","site_admin":false},"repo":{"id":46273445,"name":"uppy","full_name":"transloadit/uppy","owner":{"login":"transloadit","id":125754,"avatar_url":"https://avatars1.githubusercontent.com/u/125754?v=3","gravatar_id":"","url":"https://api.github.com/users/transloadit","html_url":"https://github.com/transloadit","followers_url":"https://api.github.com/users/transloadit/followers","following_url":"https://api.github.com/users/transloadit/following{/other_user}","gists_url":"https://api.github.com/users/transloadit/gists{/gist_id}","starred_url":"https://api.github.com/users/transloadit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transloadit/subscriptions","organizations_url":"https://api.github.com/users/transloadit/orgs","repos_url":"https://api.github.com/users/transloadit/repos","events_url":"https://api.github.com/users/transloadit/events{/privacy}","received_events_url":"https://api.github.com/users/transloadit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/transloadit/uppy","description":"The next open source file uploader for web browsers :dog: ","fork":false,"url":"https://api.github.com/repos/transloadit/uppy","forks_url":"https://api.github.com/repos/transloadit/uppy/forks","keys_url":"https://api.github.com/repos/transloadit/uppy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/transloadit/uppy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/transloadit/uppy/teams","hooks_url":"https://api.github.com/repos/transloadit/uppy/hooks","issue_events_url":"https://api.github.com/repos/transloadit/uppy/issues/events{/number}","events_url":"https://api.github.com/repos/transloadit/uppy/events","assignees_url":"https://api.github.com/repos/transloadit/uppy/assignees{/user}","branches_url":"https://api.github.com/repos/transloadit/uppy/branches{/branch}","tags_url":"https://api.github.com/repos/transloadit/uppy/tags","blobs_url":"https://api.github.com/repos/transloadit/uppy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/transloadit/uppy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/transloadit/uppy/git/refs{/sha}","trees_url":"https://api.github.com/repos/transloadit/uppy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/transloadit/uppy/statuses/{sha}","languages_url":"https://api.github.com/repos/transloadit/uppy/languages","stargazers_url":"https://api.github.com/repos/transloadit/uppy/stargazers","contributors_url":"https://api.github.com/repos/transloadit/uppy/contributors","subscribers_url":"https://api.github.com/repos/transloadit/uppy/subscribers","subscription_url":"https://api.github.com/repos/transloadit/uppy/subscription","commits_url":"https://api.github.com/repos/transloadit/uppy/commits{/sha}","git_commits_url":"https://api.github.com/repos/transloadit/uppy/git/commits{/sha}","comments_url":"https://api.github.com/repos/transloadit/uppy/comments{/number}","issue_comment_url":"https://api.github.com/repos/transloadit/uppy/issues/comments{/number}","contents_url":"https://api.github.com/repos/transloadit/uppy/contents/{+path}","compare_url":"https://api.github.com/repos/transloadit/uppy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/transloadit/uppy/merges","archive_url":"https://api.github.com/repos/transloadit/uppy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/transloadit/uppy/downloads","issues_url":"https://api.github.com/repos/transloadit/uppy/issues{/number}","pulls_url":"https://api.github.com/repos/transloadit/uppy/pulls{/number}","milestones_url":"https://api.github.com/repos/transloadit/uppy/milestones{/number}","notifications_url":"https://api.github.com/repos/transloadit/uppy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/transloadit/uppy/labels{/name}","releases_url":"https://api.github.com/repos/transloadit/uppy/releases{/id}","deployments_url":"https://api.github.com/repos/transloadit/uppy/deployments","created_at":"2015-11-16T12:32:33Z","updated_at":"2017-06-16T02:24:21Z","pushed_at":"2017-06-15T23:50:09Z","git_url":"git://github.com/transloadit/uppy.git","ssh_url":"git@github.com:transloadit/uppy.git","clone_url":"https://github.com/transloadit/uppy.git","svn_url":"https://github.com/transloadit/uppy","homepage":"http://uppy.io","size":21069,"stargazers_count":2651,"watchers_count":2651,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":91,"mirror_url":null,"open_issues_count":41,"forks":91,"open_issues":41,"watchers":2651,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/219"},"html":{"href":"https://github.com/transloadit/uppy/pull/219"},"issue":{"href":"https://api.github.com/repos/transloadit/uppy/issues/219"},"comments":{"href":"https://api.github.com/repos/transloadit/uppy/issues/219/comments"},"review_comments":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/219/comments"},"review_comment":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/transloadit/uppy/pulls/219/commits"},"statuses":{"href":"https://api.github.com/repos/transloadit/uppy/statuses/24816d2c5bd6ec0ffcb65cc8f3e89401ef6fa82a"}}}}
{"actor":{"display_login":"goto-bus-stop"}}