diff --git a/src/batch.ts b/src/batch.ts index ad56148..9a9b40f 100644 --- a/src/batch.ts +++ b/src/batch.ts @@ -35,7 +35,8 @@ export default function(args: string[], done: (err?: Error) => void) config.pass = undefined; my_request.eatCookies(config); cfg.save(config); - log.info("Unlogged!"); + log.info('Unlogged!'); + process.exit(0); } diff --git a/src/config.ts b/src/config.ts index ebde062..063a035 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,7 @@ import os = require('os'); import fs = require('fs-extra'); import path = require('path'); -const configFile = path.join(process.cwd(), "config.json"); +const configFile = path.join(process.cwd(), 'config.json'); function fileExist(path: string) { @@ -24,7 +24,7 @@ export function load(): IConfigLine const data = fs.readFileSync(configFile, 'utf8'); return JSON.parse(data); } - + return {args: undefined}; } diff --git a/src/my_request.ts b/src/my_request.ts index 9420c86..6eca968 100644 --- a/src/my_request.ts +++ b/src/my_request.ts @@ -152,10 +152,12 @@ function checkIfUserIsAuth(config: IConfig, done: (err: Error) => void): void function loadCookies(config: IConfig) { const cookiePath = path.join(config.output || process.cwd(), '.cookies.json'); - if(!fs.existsSync(cookiePath)) + + if (!fs.existsSync(cookiePath)) { - fs.closeSync(fs.openSync(cookiePath, 'w')); + fs.closeSync(fs.openSync(cookiePath, 'w')); } + j = request.jar(new cookieStore(cookiePath)); } @@ -163,10 +165,11 @@ export function eatCookies(config: IConfig) { const cookiePath = path.join(config.output || process.cwd(), '.cookies.json'); - if(fs.existsSync(cookiePath)) + if (fs.existsSync(cookiePath)) { fs.removeSync(cookiePath); } + j = undefined; } @@ -190,6 +193,7 @@ export function get(config: IConfig, options: string|request.Options, done: (err cloudscraper.request(modify(options, 'GET'), (error: any, response: any, body: any) => { if (error) return done(error); + done(null, typeof body === 'string' ? body : String(body)); }); }); @@ -209,14 +213,14 @@ export function post(config: IConfig, options: request.Options, done: (err: Erro { if (err) { - return done(err); + return done(err); } cloudscraper.request(modify(options, 'POST'), (error: Error, response: any, body: any) => { if (error) { - return done(error); + return done(error); } done(null, typeof body === 'string' ? body : String(body)); });