From 17cf0599707090bcb2f3992e6b65f3f7809073f0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 14 May 2018 23:56:27 -0400 Subject: [PATCH] node fetch api --- package-lock.json | 5 +++++ package.json | 1 + src/services/api.service.ts | 4 +--- src/services/nodeApi.service.ts | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/services/nodeApi.service.ts diff --git a/package-lock.json b/package-lock.json index 9e5eb8f861..e4490a13ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5786,6 +5786,11 @@ "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=", "dev": true }, + "node-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" + }, "node-forge": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.1.tgz", diff --git a/package.json b/package.json index 10e66ab3bc..e3984ee5c4 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "electron-updater": "2.21.4", "keytar": "4.1.0", "lunr": "2.1.6", + "node-fetch": "2.1.2", "node-forge": "0.7.1", "rxjs": "5.5.6", "zone.js": "0.8.19" diff --git a/src/services/api.service.ts b/src/services/api.service.ts index b4274465a6..cda9888685 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -439,12 +439,10 @@ export class ApiService implements ApiServiceAbstraction { } private async handleTokenState(): Promise { - let accessToken: string; + let accessToken = await this.tokenService.getToken(); if (this.tokenService.tokenNeedsRefresh()) { const tokenResponse = await this.doRefreshToken(); accessToken = tokenResponse.accessToken; - } else { - accessToken = await this.tokenService.getToken(); } return 'Bearer ' + accessToken; diff --git a/src/services/nodeApi.service.ts b/src/services/nodeApi.service.ts new file mode 100644 index 0000000000..d75ff1fdac --- /dev/null +++ b/src/services/nodeApi.service.ts @@ -0,0 +1,15 @@ +import { Utils } from '../misc/utils'; + +import { ApiService } from './api.service'; + +import { PlatformUtilsService } from '../abstractions/platformUtils.service'; +import { TokenService } from '../abstractions/token.service'; + +import * as fetch from 'node-fetch'; + +export class NodeApiService extends ApiService { + constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, + logoutCallback: Function) { + super(tokenService, platformUtilsService, logoutCallback); + } +}