mirror of
https://github.com/snobu/destreamer.git
synced 2026-01-17 05:22:18 +00:00
Fix error messages from TokenCache
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { Session } from './Types';
|
import { Session } from './Types';
|
||||||
|
import { terminal as term } from 'terminal-kit';
|
||||||
const jwtDecode = require('jwt-decode');
|
const jwtDecode = require('jwt-decode');
|
||||||
|
const tokenCacheFile = '.token_cache';
|
||||||
|
|
||||||
export class TokenCache {
|
export class TokenCache {
|
||||||
|
|
||||||
public Read(): Session | null {
|
public Read(): Session | null {
|
||||||
let j = null;
|
let j = null;
|
||||||
try {
|
if(!fs.existsSync(tokenCacheFile)) {
|
||||||
let f = fs.readFileSync(".token_cache", "utf8");
|
term.yellow(`${tokenCacheFile} not found.\n`);
|
||||||
j = JSON.parse(f);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
let f = fs.readFileSync(tokenCacheFile, "utf8");
|
||||||
|
j = JSON.parse(f);
|
||||||
|
|
||||||
interface Jwt {
|
interface Jwt {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
@@ -26,6 +26,10 @@ export class TokenCache {
|
|||||||
let exp = decodedJwt["exp"];
|
let exp = decodedJwt["exp"];
|
||||||
let timeLeft = exp - now;
|
let timeLeft = exp - now;
|
||||||
|
|
||||||
|
let timeLeftInMinutes = Math.floor(timeLeft / 60);
|
||||||
|
console.log("\n");
|
||||||
|
term.bgBrightGreen.black(`Access token still good for ${timeLeftInMinutes} minutes.`);
|
||||||
|
console.log("\n");
|
||||||
if (timeLeft < 120) {
|
if (timeLeft < 120) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user