{"action":"created","comment":{"url":"https://api.github.com/repos/prateekbh/Guess/pulls/comments/104591926","pull_request_review_id":25434780,"id":104591926,"diff_hunk":"@@ -84,6 +87,122 @@ router.post('/saveword', function(req, res) {\n   });\n });\n \n+/*\n+curl -H \"Content-Type: application/json\" -H \"Accept: application/json\" \\\n+-X POST \\\n+-H \"Cookie: userid=123\" \\\n+-d '{\"words\": [{\"word\":\"dfg1\",\"images\":[\"URL1\", \"URL2\"]}, {\"word\":\"ghj\",\"images\":[\"URL1\", \"URL2\"]}]}' http://localhost:8080/adminapi/saveword\n+*/\n+router.post('/bulksave', function(req, res) {\n+  if (!(config.COOKIE_NAME in req.cookies))\n+  return res.status(400).send('Cookie not provided.');\n+  const sessionId = req.cookies[config.COOKIE_NAME];\n+  db.getUser(sessionId, (user) => {\n+    if (user === false || user === 'No User.')\n+      return res.status(500).send('Error Occurred in user lookup');\n+    if (config.WHITELISTED_ADMINS.indexOf(user.email) < 0)\n+      return res.status(400).send('Invalid user');\n+\n+    let dbPromises = [];\n+    if (req.body.hasOwnProperty('word')) {\n+      dbPromises.push(saveWord(req.body, user.email));\n+    } else {\n+      res.status(400).send('Invalid request format');\n+    }\n+\n+    Promise.all(dbPromises).then((results) => {\n+      let response = {Saved: 0, Duplicate: 0, errors: 0};\n+      for (var i = 0; i < results.length; i++) {\n+        if (results[i] === 'Duplicate' || results[i] === 'Saved') {\n+          response[results[i]] += 1;\n+        } else response.errors += 1;\n+      }\n+      res.send(JSON.stringify(response));\n+    })\n+    .catch((err) => {\n+      res.status(500).send('Unknown Error Occurred, some words might have been saved');\n+    });\n+  });\n+});\n+\n+function saveWord(payload, email) {\n+  return new Promise((resolve, reject) => {\n+    console.log(payload.word);\n+    db.checkWordExists(payload.word, (err, message) => {\n+      if (err) return reject(err);\n+      if (message === true) {\n+        return resolve('Duplicate');\n+      }\n+      payload.author = email;\n+      db.insertWordInCollection(payload, (err, message) => {\n+        if (err) return reject(err);\n+        resolve(message);\n+      });\n+    });\n+  });\n+}\n+\n+// Endpoint to pick the words from ./routes/wordlist.txt and create game configs\n+// curl localhost:8080/adminapi/makegames?wordcount=2\n+router.get('/makegames', (req, res, next) => {\n+  let wordcount = req.query.wordcount;\n+  fs.readFile('./routes/wordlist.txt', 'utf8', function (err, data) {\n+    if (err) {\n+      res.status(500).send('Error Occurred');\n+      return console.log(err);\n+    }\n+    data = data.replace(/(?:\\r\\n|\\r|\\n)/g, '').replace(/( )/g, '');\n+    evalute(data, wordcount, res);\n+  });\n+});\n+\n+var wordsProcessed = 0;\n+function evalute(data, wordcount, res) {\n+  let words = data.split(',');\n+  let dbLookups = [];\n+  for (var i = wordsProcessed; i < words.length && dbLookups.length < wordcount; i++) {\n+    let word = words[i];\n+    // remove \\n which may have crept in the last word\n+    if (word.slice(-1) === '\\n') word = word.slice(0, word.length - 1);\n+    if (word.length < 4) continue;\n+\n+    dbLookups.push(new Promise((resolve, reject) => {\n+      db.checkWordExists(word, (err, found) => {\n+        if (err) return reject(err);\n+        resolve({'found': found, 'word': word});\n+      });\n+    }));\n+  }\n+\n+  Promise.all(dbLookups).then((results) => {\n+    let resData = {words: []};\n+    let pexelCalls = [];\n+    for (var i = 0; i < results.length; i++) {\n+      if (!results[i].found) {\n+        resData.words.push({word: results[i].word, images: []});\n+        // API calls to pexel\n+        pexelCalls.push(pexelReq(results[i].word));\n+        wordsProcessed += 1;\n+      }\n+    }\n+    Promise.all(pexelCalls).then((results) => {\n+      for (var j = 0; j < results.length; j++) {\n+        if (!results[j].body.hasOwnProperty('photos')) continue;\n+        results[j].body.photos.slice(0, 4).forEach((item) => {\n+          resData.words[j].images.push(item.src.medium);\n+        });\n+      }\n+      res.send(JSON.stringify(resData));\n+    });\n+  });\n+}\n+\n+function pexelReq(word) {\n+  return request","path":"routes/adminapi.js","position":135,"original_position":135,"commit_id":"124808006c77d582a20f05d194a70d4a73d79322","original_commit_id":"124808006c77d582a20f05d194a70d4a73d79322","user":{"login":"prateekbh","id":5960497,"avatar_url":"https://avatars1.githubusercontent.com/u/5960497?v=3","gravatar_id":"","url":"https://api.github.com/users/prateekbh","html_url":"https://github.com/prateekbh","followers_url":"https://api.github.com/users/prateekbh/followers","following_url":"https://api.github.com/users/prateekbh/following{/other_user}","gists_url":"https://api.github.com/users/prateekbh/gists{/gist_id}","starred_url":"https://api.github.com/users/prateekbh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prateekbh/subscriptions","organizations_url":"https://api.github.com/users/prateekbh/orgs","repos_url":"https://api.github.com/users/prateekbh/repos","events_url":"https://api.github.com/users/prateekbh/events{/privacy}","received_events_url":"https://api.github.com/users/prateekbh/received_events","type":"User","site_admin":false},"body":"use fetch instead, its a standard and is being used everywhere in the project...\r\ncheck /subscribe","created_at":"2017-03-07T05:32:27Z","updated_at":"2017-03-07T05:32:27Z","html_url":"https://github.com/prateekbh/Guess/pull/11#discussion_r104591926","pull_request_url":"https://api.github.com/repos/prateekbh/Guess/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/comments/104591926"},"html":{"href":"https://github.com/prateekbh/Guess/pull/11#discussion_r104591926"},"pull_request":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/prateekbh/Guess/pulls/11","id":109099598,"html_url":"https://github.com/prateekbh/Guess/pull/11","diff_url":"https://github.com/prateekbh/Guess/pull/11.diff","patch_url":"https://github.com/prateekbh/Guess/pull/11.patch","issue_url":"https://api.github.com/repos/prateekbh/Guess/issues/11","number":11,"state":"open","locked":false,"title":"makegames endpoint and saveword point supports batch","user":{"login":"atvanguard","id":3612498,"avatar_url":"https://avatars2.githubusercontent.com/u/3612498?v=3","gravatar_id":"","url":"https://api.github.com/users/atvanguard","html_url":"https://github.com/atvanguard","followers_url":"https://api.github.com/users/atvanguard/followers","following_url":"https://api.github.com/users/atvanguard/following{/other_user}","gists_url":"https://api.github.com/users/atvanguard/gists{/gist_id}","starred_url":"https://api.github.com/users/atvanguard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atvanguard/subscriptions","organizations_url":"https://api.github.com/users/atvanguard/orgs","repos_url":"https://api.github.com/users/atvanguard/repos","events_url":"https://api.github.com/users/atvanguard/events{/privacy}","received_events_url":"https://api.github.com/users/atvanguard/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-03-04T08:20:42Z","updated_at":"2017-03-07T05:32:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b80d113f7c084da592d32cedb2e1cefb49f342df","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/prateekbh/Guess/pulls/11/commits","review_comments_url":"https://api.github.com/repos/prateekbh/Guess/pulls/11/comments","review_comment_url":"https://api.github.com/repos/prateekbh/Guess/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prateekbh/Guess/issues/11/comments","statuses_url":"https://api.github.com/repos/prateekbh/Guess/statuses/124808006c77d582a20f05d194a70d4a73d79322","head":{"label":"atvanguard:master","ref":"master","sha":"124808006c77d582a20f05d194a70d4a73d79322","user":{"login":"atvanguard","id":3612498,"avatar_url":"https://avatars2.githubusercontent.com/u/3612498?v=3","gravatar_id":"","url":"https://api.github.com/users/atvanguard","html_url":"https://github.com/atvanguard","followers_url":"https://api.github.com/users/atvanguard/followers","following_url":"https://api.github.com/users/atvanguard/following{/other_user}","gists_url":"https://api.github.com/users/atvanguard/gists{/gist_id}","starred_url":"https://api.github.com/users/atvanguard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atvanguard/subscriptions","organizations_url":"https://api.github.com/users/atvanguard/orgs","repos_url":"https://api.github.com/users/atvanguard/repos","events_url":"https://api.github.com/users/atvanguard/events{/privacy}","received_events_url":"https://api.github.com/users/atvanguard/received_events","type":"User","site_admin":false},"repo":{"id":78725845,"name":"Guess","full_name":"atvanguard/Guess","owner":{"login":"atvanguard","id":3612498,"avatar_url":"https://avatars2.githubusercontent.com/u/3612498?v=3","gravatar_id":"","url":"https://api.github.com/users/atvanguard","html_url":"https://github.com/atvanguard","followers_url":"https://api.github.com/users/atvanguard/followers","following_url":"https://api.github.com/users/atvanguard/following{/other_user}","gists_url":"https://api.github.com/users/atvanguard/gists{/gist_id}","starred_url":"https://api.github.com/users/atvanguard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atvanguard/subscriptions","organizations_url":"https://api.github.com/users/atvanguard/orgs","repos_url":"https://api.github.com/users/atvanguard/repos","events_url":"https://api.github.com/users/atvanguard/events{/privacy}","received_events_url":"https://api.github.com/users/atvanguard/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atvanguard/Guess","description":"web clone for 4pics one word","fork":true,"url":"https://api.github.com/repos/atvanguard/Guess","forks_url":"https://api.github.com/repos/atvanguard/Guess/forks","keys_url":"https://api.github.com/repos/atvanguard/Guess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atvanguard/Guess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atvanguard/Guess/teams","hooks_url":"https://api.github.com/repos/atvanguard/Guess/hooks","issue_events_url":"https://api.github.com/repos/atvanguard/Guess/issues/events{/number}","events_url":"https://api.github.com/repos/atvanguard/Guess/events","assignees_url":"https://api.github.com/repos/atvanguard/Guess/assignees{/user}","branches_url":"https://api.github.com/repos/atvanguard/Guess/branches{/branch}","tags_url":"https://api.github.com/repos/atvanguard/Guess/tags","blobs_url":"https://api.github.com/repos/atvanguard/Guess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atvanguard/Guess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atvanguard/Guess/git/refs{/sha}","trees_url":"https://api.github.com/repos/atvanguard/Guess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atvanguard/Guess/statuses/{sha}","languages_url":"https://api.github.com/repos/atvanguard/Guess/languages","stargazers_url":"https://api.github.com/repos/atvanguard/Guess/stargazers","contributors_url":"https://api.github.com/repos/atvanguard/Guess/contributors","subscribers_url":"https://api.github.com/repos/atvanguard/Guess/subscribers","subscription_url":"https://api.github.com/repos/atvanguard/Guess/subscription","commits_url":"https://api.github.com/repos/atvanguard/Guess/commits{/sha}","git_commits_url":"https://api.github.com/repos/atvanguard/Guess/git/commits{/sha}","comments_url":"https://api.github.com/repos/atvanguard/Guess/comments{/number}","issue_comment_url":"https://api.github.com/repos/atvanguard/Guess/issues/comments{/number}","contents_url":"https://api.github.com/repos/atvanguard/Guess/contents/{+path}","compare_url":"https://api.github.com/repos/atvanguard/Guess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atvanguard/Guess/merges","archive_url":"https://api.github.com/repos/atvanguard/Guess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atvanguard/Guess/downloads","issues_url":"https://api.github.com/repos/atvanguard/Guess/issues{/number}","pulls_url":"https://api.github.com/repos/atvanguard/Guess/pulls{/number}","milestones_url":"https://api.github.com/repos/atvanguard/Guess/milestones{/number}","notifications_url":"https://api.github.com/repos/atvanguard/Guess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atvanguard/Guess/labels{/name}","releases_url":"https://api.github.com/repos/atvanguard/Guess/releases{/id}","deployments_url":"https://api.github.com/repos/atvanguard/Guess/deployments","created_at":"2017-01-12T08:53:33Z","updated_at":"2017-01-12T08:53:35Z","pushed_at":"2017-03-04T11:05:02Z","git_url":"git://github.com/atvanguard/Guess.git","ssh_url":"git@github.com:atvanguard/Guess.git","clone_url":"https://github.com/atvanguard/Guess.git","svn_url":"https://github.com/atvanguard/Guess","homepage":null,"size":470,"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":"prateekbh:master","ref":"master","sha":"9ac41d3424d04de9b57d4bd1902608fdca1f5087","user":{"login":"prateekbh","id":5960497,"avatar_url":"https://avatars1.githubusercontent.com/u/5960497?v=3","gravatar_id":"","url":"https://api.github.com/users/prateekbh","html_url":"https://github.com/prateekbh","followers_url":"https://api.github.com/users/prateekbh/followers","following_url":"https://api.github.com/users/prateekbh/following{/other_user}","gists_url":"https://api.github.com/users/prateekbh/gists{/gist_id}","starred_url":"https://api.github.com/users/prateekbh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prateekbh/subscriptions","organizations_url":"https://api.github.com/users/prateekbh/orgs","repos_url":"https://api.github.com/users/prateekbh/repos","events_url":"https://api.github.com/users/prateekbh/events{/privacy}","received_events_url":"https://api.github.com/users/prateekbh/received_events","type":"User","site_admin":false},"repo":{"id":78434529,"name":"Guess","full_name":"prateekbh/Guess","owner":{"login":"prateekbh","id":5960497,"avatar_url":"https://avatars1.githubusercontent.com/u/5960497?v=3","gravatar_id":"","url":"https://api.github.com/users/prateekbh","html_url":"https://github.com/prateekbh","followers_url":"https://api.github.com/users/prateekbh/followers","following_url":"https://api.github.com/users/prateekbh/following{/other_user}","gists_url":"https://api.github.com/users/prateekbh/gists{/gist_id}","starred_url":"https://api.github.com/users/prateekbh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prateekbh/subscriptions","organizations_url":"https://api.github.com/users/prateekbh/orgs","repos_url":"https://api.github.com/users/prateekbh/repos","events_url":"https://api.github.com/users/prateekbh/events{/privacy}","received_events_url":"https://api.github.com/users/prateekbh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/prateekbh/Guess","description":"web clone for 4pics one word","fork":false,"url":"https://api.github.com/repos/prateekbh/Guess","forks_url":"https://api.github.com/repos/prateekbh/Guess/forks","keys_url":"https://api.github.com/repos/prateekbh/Guess/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prateekbh/Guess/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prateekbh/Guess/teams","hooks_url":"https://api.github.com/repos/prateekbh/Guess/hooks","issue_events_url":"https://api.github.com/repos/prateekbh/Guess/issues/events{/number}","events_url":"https://api.github.com/repos/prateekbh/Guess/events","assignees_url":"https://api.github.com/repos/prateekbh/Guess/assignees{/user}","branches_url":"https://api.github.com/repos/prateekbh/Guess/branches{/branch}","tags_url":"https://api.github.com/repos/prateekbh/Guess/tags","blobs_url":"https://api.github.com/repos/prateekbh/Guess/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prateekbh/Guess/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prateekbh/Guess/git/refs{/sha}","trees_url":"https://api.github.com/repos/prateekbh/Guess/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prateekbh/Guess/statuses/{sha}","languages_url":"https://api.github.com/repos/prateekbh/Guess/languages","stargazers_url":"https://api.github.com/repos/prateekbh/Guess/stargazers","contributors_url":"https://api.github.com/repos/prateekbh/Guess/contributors","subscribers_url":"https://api.github.com/repos/prateekbh/Guess/subscribers","subscription_url":"https://api.github.com/repos/prateekbh/Guess/subscription","commits_url":"https://api.github.com/repos/prateekbh/Guess/commits{/sha}","git_commits_url":"https://api.github.com/repos/prateekbh/Guess/git/commits{/sha}","comments_url":"https://api.github.com/repos/prateekbh/Guess/comments{/number}","issue_comment_url":"https://api.github.com/repos/prateekbh/Guess/issues/comments{/number}","contents_url":"https://api.github.com/repos/prateekbh/Guess/contents/{+path}","compare_url":"https://api.github.com/repos/prateekbh/Guess/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prateekbh/Guess/merges","archive_url":"https://api.github.com/repos/prateekbh/Guess/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prateekbh/Guess/downloads","issues_url":"https://api.github.com/repos/prateekbh/Guess/issues{/number}","pulls_url":"https://api.github.com/repos/prateekbh/Guess/pulls{/number}","milestones_url":"https://api.github.com/repos/prateekbh/Guess/milestones{/number}","notifications_url":"https://api.github.com/repos/prateekbh/Guess/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prateekbh/Guess/labels{/name}","releases_url":"https://api.github.com/repos/prateekbh/Guess/releases{/id}","deployments_url":"https://api.github.com/repos/prateekbh/Guess/deployments","created_at":"2017-01-09T14:08:22Z","updated_at":"2017-03-03T18:46:38Z","pushed_at":"2017-03-07T03:47:02Z","git_url":"git://github.com/prateekbh/Guess.git","ssh_url":"git@github.com:prateekbh/Guess.git","clone_url":"https://github.com/prateekbh/Guess.git","svn_url":"https://github.com/prateekbh/Guess","homepage":null,"size":1190,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/11"},"html":{"href":"https://github.com/prateekbh/Guess/pull/11"},"issue":{"href":"https://api.github.com/repos/prateekbh/Guess/issues/11"},"comments":{"href":"https://api.github.com/repos/prateekbh/Guess/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prateekbh/Guess/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/prateekbh/Guess/statuses/124808006c77d582a20f05d194a70d4a73d79322"}}}}
{"actor":{"display_login":"prateekbh"}}