refactor debug logging, add debug info for YT authorized tokens

This commit is contained in:
2025-07-04 15:58:00 +02:00
parent 6874804703
commit c57f9ec3ea
7 changed files with 262 additions and 300 deletions

View File

@ -7,6 +7,7 @@ import fs from 'fs/promises';
const logger = new Logger('App');
logger.log('App startup');
logger.log('Debug log enabled', Logger.isDebugEnabled());
TimelineReader.init();
export const handleError = (({ error }) => {

View File

@ -1,3 +1,4 @@
import { DEBUG_LOG } from '$env/static/private';
import { env } from '$env/dynamic/private';
import { isTruthy } from '$lib/truthyString';
const { DEV } = import.meta.env;
@ -41,7 +42,7 @@ export class Logger {
public constructor(private name: string) {}
public static isDebugEnabled(): boolean {
return DEV || enableVerboseLog;
return !!DEBUG_LOG || DEV || enableVerboseLog;
}
public verbose(...params: any[]) {
if (!enableVerboseLog) {
@ -50,7 +51,7 @@ export class Logger {
console.debug(new Date().toISOString(), `- ${this.name} -`, ...params);
}
public debug(...params: any[]) {
if (false && !Logger.isDebugEnabled()) {
if (!Logger.isDebugEnabled()) {
return;
}
console.debug(new Date().toISOString(), `- ${this.name} -`, ...params);

View File

@ -41,6 +41,20 @@ export class YoutubePlaylistAdder extends OauthPlaylistAdder implements Playlist
url,
YOUTUBE_CLIENT_SECRET
);
const token = await this.refreshToken();
if (token == null) {
return;
}
try {
this.logger.debug('Checking authorized token');
const res = await fetch(this.apiBase + '/channels?part=id&mine=true', {
method: 'GET',
headers: { Authorization: `${token.token_type} ${token.access_token}` }
}).then((r) => r.json());
this.logger.debug('Checked authorized token', res);
} catch (e) {
this.logger.debug('Error checking authorized token', e);
}
}
private async refreshToken(): Promise<OauthResponse | null> {