add .env.template for configuration and update token file path handling
This commit is contained in:
7
.env.template
Normal file
7
.env.template
Normal file
@@ -0,0 +1,7 @@
|
||||
CLIENT_ID=<discord application client id>
|
||||
CLIENT_SECRET=<discord application client OAuth secret>
|
||||
REDIRECT_URI=<your OAuth2 redirect URI, must match the one set in your Discord application>
|
||||
ESP_IP=<IP address of your ESP device>
|
||||
ESP_PORT=<port number your ESP device listens on>
|
||||
LISTEN_PORT=<port number your application listens on>
|
||||
TOKEN_FILE_PATH=<path to store OAuth2 tokens, relative to project root, or absolute>
|
||||
@@ -1,5 +1,5 @@
|
||||
import { writeFileSync, existsSync, readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { isAbsolute, join } from 'path';
|
||||
|
||||
export interface TokenData {
|
||||
accessToken: string;
|
||||
@@ -8,7 +8,10 @@ export interface TokenData {
|
||||
}
|
||||
|
||||
export class TokenService {
|
||||
private TOKEN_FILE = join(__dirname, '../', '.discord-token.json');
|
||||
private TOKEN_FILE =
|
||||
process.env.TOKEN_FILE_PATH && isAbsolute(process.env.TOKEN_FILE_PATH)
|
||||
? process.env.TOKEN_FILE_PATH
|
||||
: join(__dirname, '../', process.env.TOKEN_FILE_PATH ?? '.discord-token.json');
|
||||
|
||||
public saveTokens(data: TokenData): void {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user