Browse Source

Move pin to secret file

master
David Ludwig 4 years ago
parent
commit
74ca83e242
2 changed files with 6 additions and 4 deletions
  1. +1
    -1
      .env.example
  2. +5
    -3
      src/server/services/TvDb.ts

+ 1
- 1
.env.example View File

@ -11,7 +11,7 @@ TMDB_KEY_FILE = /run/secrets/tmdb_key
# TVDB API key
TVDB_KEY_FILE = /run/secrets/tvdb_key
TVDB_PIN =
TVDB_PIN_FILE = /run/secrets/tvdb_pin
TVDB_REFRESH_PERIOD = 480 # (8 hours) How frequently to refresh the token (in minutes)
# Database -----------------------------------------------------------------------------------------


+ 5
- 3
src/server/services/TvDb.ts View File

@ -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
}
/**


Loading…
Cancel
Save