yusuketk пре 7 година
родитељ
комит
39f627a1d3
1 измењених фајлова са 10 додато и 10 уклоњено
  1. 10 10
      lib/util/restQiitaAPI.js

+ 10 - 10
lib/util/restQiitaAPI.js

@@ -20,11 +20,6 @@ module.exports = function(Team, Token) {
   function restAPI(path, options) {
     return new Promise((resolve, reject) => {
       options.url = `${options.url}/api/v2/${path}`;
-      // const req = https.request(options, (res) => {
-      //   const total = res.headers['total-count'];
-      //   res.on('data', (chunk) => {
-      //     resolve([chunk, total]);
-      //   });
       request(options, function(err, res, body) {
         if (err) {
           return console.error('upload failed:', err);
@@ -38,8 +33,8 @@ module.exports = function(Team, Token) {
   restQiitaAPI.getQiitaUser = function() {
     return new Promise((resolve, reject) => {
       restAPI('users', options)
-      .then(function(buf, link){
-        return JSON.parse(buf.toString());
+      .then(function(res){
+        return JSON.parse(res[0].toString());
       })
       .then(function(user) {
         if(user.length > 0) {
@@ -58,10 +53,15 @@ module.exports = function(Team, Token) {
   restQiitaAPI.getQiitaPages = function(pageNum) {
     return new Promise((resolve, reject) => {
       restAPI(`items?page=${pageNum}&per_page=100`, options)
-      .then(function(res){
-        const page = res[0];
+      .then(function(res) {
+        const pages = JSON.parse(res[0].toString());
         const total = res[1];
-        resolve([JSON.parse(page.toString()), total]);
+        if(pages.length > 0) {
+          resolve([pages, total]);
+        }
+        else {
+          reject('page not find.');
+        }
       })
       .catch(function(err){
         reject(err);