Skip to content

Commit 20faab4

Browse files
committed
Replace console logging with logger for improved error handling in server and yt-dlp
1 parent 687908f commit 20faab4

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ app.post("/login", (req, res) => {
364364
app.get("/logout", (req, res) => {
365365
req.session.destroy((err) => {
366366
if (err) {
367-
console.error("Error destroying session:", err);
367+
logger.error("Error destroying session:", err);
368368
}
369369
res.redirect("/login");
370370
});
@@ -374,7 +374,7 @@ app.get("/logout", (req, res) => {
374374
app.get("/", (req, res) => {
375375
fs.readdir(config.videosDir, (err, files) => {
376376
if (err) {
377-
console.error(err);
377+
logger.error(err);
378378
res.status(500).send("Internal Server Error");
379379
return;
380380
}
@@ -524,11 +524,11 @@ app.post("/api/remote_upload", upload.single("link"), async (req, res) => {
524524
});
525525

526526
writer.on("error", (err) => {
527-
console.error(err);
527+
logger.error(err);
528528
res.status(500).send("Error uploading file");
529529
});
530530
} catch (err) {
531-
console.error(err);
531+
logger.error(err);
532532
res.status(500).send("Error uploading file");
533533
}
534534
});
@@ -649,7 +649,7 @@ app.get("/delete/:file", (req, res) => {
649649
if (fs.existsSync(filePath)) {
650650
fs.unlink(filePath, (err) => {
651651
if (err) {
652-
console.error(err);
652+
logger.error(err);
653653
res.status(500).send("Internal Server Error");
654654
} else {
655655
res.redirect("/");

src/utils/yt-dlp.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ if (platform === "win32") {
2929
} else if (arch === "x64") {
3030
determinedFilename = "yt-dlp";
3131
} else {
32-
console.warn(`[WARN] Unsupported Linux architecture '${arch}' for yt-dlp. Falling back to generic 'yt-dlp'. Download might fail.`);
32+
logger.warn(`Unsupported Linux architecture '${arch}' for yt-dlp. Falling back to generic 'yt-dlp'. Download might fail.`);
3333
determinedFilename = "yt-dlp";
3434
}
3535
} else {
36-
console.warn(`[WARN] Unsupported OS '${platform}' for yt-dlp. Attempting to use generic 'yt-dlp'. Download might fail.`);
36+
logger.warn(`Unsupported OS '${platform}' for yt-dlp. Attempting to use generic 'yt-dlp'. Download might fail.`);
3737
determinedFilename = "yt-dlp";
3838
}
3939

@@ -74,7 +74,7 @@ function json(str: string) {
7474

7575
export async function downloadExecutable() {
7676
if (!existsSync(exePath)) {
77-
console.info("[INFO] Yt-dlp couldn't be found, trying to download...");
77+
logger.info("Yt-dlp couldn't be found, trying to download...");
7878
const releases = await got.get("https://api.github.com/repos/yt-dlp/yt-dlp/releases?per_page=1").json();
7979
const release = releases[0];
8080
const asset = release.assets.find(ast => ast.name === filename);
@@ -85,7 +85,7 @@ export async function downloadExecutable() {
8585
return 0;
8686
}).then(resolve).catch(reject);
8787
});
88-
console.info("[INFO] Yt-dlp has been downloaded.");
88+
logger.info("Yt-dlp has been downloaded.");
8989
}
9090
}
9191

@@ -128,7 +128,7 @@ export default async function ytdl(url: string, options: Partial<YTFlags> = {},
128128
const exitCode = await proc.exited;
129129

130130
if (exitCode !== 0) {
131-
console.error(`yt-dlp process exited with code ${exitCode}. Stderr: ${errorData}`);
131+
logger.error(`yt-dlp process exited with code ${exitCode}. Stderr: ${errorData}`);
132132
throw new Error(`yt-dlp failed with exit code ${exitCode}: ${errorData || data}`);
133133
}
134134

@@ -173,17 +173,17 @@ export async function downloadToTempFile(url: string, options: Partial<YTFlags>
173173
try {
174174
unlinkSync(tempFilePath);
175175
} catch (cleanupError) {
176-
console.warn(`[WARN] Failed to cleanup temp file ${tempFilePath} after yt-dlp error:`, cleanupError);
176+
logger.warn(`Failed to cleanup temp file ${tempFilePath} after yt-dlp error:`, cleanupError);
177177
}
178178
}
179179
const errorMessage = `yt-dlp failed to download to temp file. Exit code: ${exitCode}. Stderr: ${errorData.trim()}`;
180-
console.error(`[ERROR] ${errorMessage}`);
180+
logger.error(errorMessage);
181181
throw new Error(errorMessage);
182182
}
183183

184184
if (!existsSync(tempFilePath)) {
185185
const errorMessage = `yt-dlp exited successfully but temp file ${tempFilePath} was not created. Stderr: ${errorData.trim()}`;
186-
console.error(`[ERROR] ${errorMessage}`);
186+
logger.error(errorMessage);
187187
throw new Error(errorMessage);
188188
}
189189

0 commit comments

Comments
 (0)