UNPKG

819 BJavaScriptView Raw
1const e=require("bluebird"),r=require("./../utils/credentials"),i=require("./../utils/api"),t=require("./../utils/files"),n=require("../utils/progress"),{EncryptDecrypt:o}=require("./../utils/encrypt"),u=require("path");module.exports=function(){return e.coroutine(function*(){let c,l,s;l=yield r.readCredentials();try{l=JSON.parse(l).key}catch(e){throw"User not logged in"}if((s=yield t.getIndex()).oauth_provider){var a={headers:{accesstoken:l},method:"GET"},{body:d}=yield i.makeApiCall("/oauth/"+s.oauth_provider,a);if(d.key){if(!(c=t.fileExist(u.join(global.config.APP_DIR,"oauth.enc"))))return e.reject("oauth.enc file missing");n.printMessage("Decrypting"),c=u.join(global.config.APP_DIR,"oauth.enc");yield new o(c,d.key).decryptAsync();n.printDone("Decrypting")}}return e.resolve(!0)})().catch(r=>e.reject(r))};
\No newline at end of file