|
|
@ -2,6 +2,7 @@ import { readFile } from "fs/promises"; |
|
|
|
import Application from "@server/Application"; |
|
|
|
import TVDB from "tvdb-v4"; |
|
|
|
import Service from "./Service"; |
|
|
|
import { env, secret } from "@server/util"; |
|
|
|
|
|
|
|
/** |
|
|
|
* The token refresh period in milliseconds |
|
|
@ -32,7 +33,7 @@ export default class TvDb extends Service |
|
|
|
* Boot the service |
|
|
|
*/ |
|
|
|
public async boot() { |
|
|
|
let apiKey = (await readFile(<string>process.env["TVDB_KEY_FILE"])).toString().trim(); |
|
|
|
let apiKey = await secret(env("TVDB_KEY_FILE")); |
|
|
|
this.tvdb = new TVDB(apiKey); |
|
|
|
await this.refreshLogin(); |
|
|
|
} |
|
|
@ -52,9 +53,10 @@ export default class TvDb extends Service |
|
|
|
return; |
|
|
|
} |
|
|
|
this.log("Refreshing login token..."); |
|
|
|
let pin = await secret(env("TVDB_PIN_FILE")); |
|
|
|
let timestamp = Date.now() + TOKEN_REFRESH_PERIOD; // Save the time before the request
|
|
|
|
await this.tvdb.login(<string>process.env["TVDB_PIN"]); |
|
|
|
this.nextTokenRefreshTimestamp = timestamp // if succeeds, update the timestamp
|
|
|
|
await this.tvdb.login(pin); |
|
|
|
this.nextTokenRefreshTimestamp = timestamp |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|