added pleroma workaround on refresh token

This commit is contained in:
Nicolas Constant 2019-10-03 19:58:37 -04:00
parent e3b2ffcd58
commit 6cd3d7272a
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 10 additions and 6 deletions

View File

@ -18,7 +18,7 @@ export class MastodonWrapperService {
private readonly authService: AuthService, private readonly authService: AuthService,
private readonly mastodonService: MastodonService) { } private readonly mastodonService: MastodonService) { }
private refreshAccountIfNeeded(accountInfo: AccountInfo): Promise<AccountInfo> { refreshAccountIfNeeded(accountInfo: AccountInfo): Promise<AccountInfo> {
let isExpired = false; let isExpired = false;
let storedAccountInfo = this.getStoreAccountInfo(accountInfo.id); let storedAccountInfo = this.getStoreAccountInfo(accountInfo.id);
@ -28,13 +28,17 @@ export class MastodonWrapperService {
isExpired = true; isExpired = true;
} else { } else {
const nowEpoch = Date.now() / 1000 | 0; const nowEpoch = Date.now() / 1000 | 0;
let expire_on = storedAccountInfo.token.expires_in + storedAccountInfo.token.created_at;
//Pleroma workaround
let expire_in = storedAccountInfo.token.expires_in;
if(expire_in < 3600) {
expire_in = 3600;
}
let expire_on = expire_in + storedAccountInfo.token.created_at;
isExpired = expire_on - nowEpoch <= 60 * 2; isExpired = expire_on - nowEpoch <= 60 * 2;
// console.warn(`expire in ${storedAccountInfo.token.expires_in} ${storedAccountInfo.token.expires_in / 1000 / 60}`); //console.warn(`expiring in ${Math.round((expire_on - nowEpoch)/24/60/60)}days ${Math.round((expire_on - nowEpoch)/60/60)}h ${Math.round((expire_on - nowEpoch)/60)} mins`);
// console.warn(`epoch comparison: ${nowEpoch} / ${expire_on} : ${isExpired}`);
// console.warn(`expiring in ${storedAccountInfo.token.expires_in} ${storedAccountInfo.token.expires_in/24/60/60} days`);
console.warn(`expiring in ${Math.round((expire_on - nowEpoch)/24/60/60)}days ${Math.round((expire_on - nowEpoch)/60/60)}h ${Math.round((expire_on - nowEpoch)/60)} mins`);
} }
} }
} catch (err) { } catch (err) {