From 4b27236ae38630c311664b89097bebaad2954961 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 12:24:58 -0500 Subject: [PATCH 1/7] add cachefile to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8003b3e..221cf10 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ private/ */private/ package-lock.json .env +ytmusic_cache -- 2.52.0 From 372620e2c9b21638e496a9489f218b9ea7c26d53 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 12:27:24 -0500 Subject: [PATCH 2/7] allow nodejs to write to ytmusic_cache --- start_dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start_dev.sh b/start_dev.sh index 664c0b9..d487f0c 100755 --- a/start_dev.sh +++ b/start_dev.sh @@ -4,4 +4,4 @@ screen -wipe portfolio_devel echo '==== Restarting Nginx ====' rc-service nginx restart echo '===== Starting server ====' -sudo -iu prod bash -c 'cd /development/website && node --permission --allow-fs-read=/development/website/* .' +sudo -iu prod bash -c 'cd /development/website && node --permission --allow-fs-read=/development/website/* --allow-fs-write=/development/website/ytmusic_cache .' -- 2.52.0 From 9ff225222745a0df1c1ac116399408c8e260e8f4 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 12:27:26 -0500 Subject: [PATCH 3/7] allow nodejs to write to ytmusic_cache but for prod too --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index fcc8621..80526fc 100755 --- a/start.sh +++ b/start.sh @@ -8,5 +8,5 @@ sudo -iu prod fuser $(sudo -iu prod which node) -k echo '==== Restarting Nginx ====' rc-service nginx restart echo '===== Starting server ====' -screen -dmS portfolio bash -c "sudo -iu prod bash -c 'cd /prod/portfolio && node --permission --allow-fs-read=/prod/portfolio/* .'" +screen -dmS portfolio bash -c "sudo -iu prod bash -c 'cd /prod/portfolio && node --permission --allow-fs-read=/prod/portfolio/* --allow-fs-write/prod/portfolio/ytmusic_cache .'" echo 'boosh' -- 2.52.0 From 227cde48d9cfcaddae03e8df04a84c5cfee4a2c3 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 14:47:10 -0500 Subject: [PATCH 4/7] write ytmusic stuffs to cache --- .gitignore | 1 + index.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 221cf10..f3c3544 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ private/ package-lock.json .env ytmusic_cache +.vscode diff --git a/index.js b/index.js index 9dd8dc1..c9fa8eb 100755 --- a/index.js +++ b/index.js @@ -88,6 +88,8 @@ async function updateSongs() { if (typeof playlistSongs == 'object') { // For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails() await Promise.all(playlistSongs.map(async song => await populateThumbnails(song))); + // Write all of this to cache + fs.writeFileSync(path.join(baseDir + 'ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails})); } else { // like legit this shouldnt even be possible -- 2.52.0 From 669231e8a68df4337e4516cd9ed3ba2c9d068e71 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 14:57:08 -0500 Subject: [PATCH 5/7] actually load from cache --- index.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c9fa8eb..cbbf791 100755 --- a/index.js +++ b/index.js @@ -89,7 +89,7 @@ async function updateSongs() { // For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails() await Promise.all(playlistSongs.map(async song => await populateThumbnails(song))); // Write all of this to cache - fs.writeFileSync(path.join(baseDir + 'ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails})); + fs.writeFileSync(path.join(baseDir + '/ytmusic_cache'), JSON.stringify({playlistSongs, thumbnails})); } else { // like legit this shouldnt even be possible @@ -298,15 +298,25 @@ async function customConsole() { } } -// Wrap in a async function to wait for youtube music response before starting http server -// (to prevent a race condition where people can view the moosic page be4 it is ready) async function main() { - // Init the moosics stuff (black magic) - await ytmusic.initialize(); + // Load from cache + await (async () => { + let cachefile; + cachefile = fs.readFileSync(path.join(baseDir, '/ytmusic_cache')); + let parsed_cachefile = JSON.parse(cachefile); + playlistSongs = parsed_cachefile.playlistSongs; + thumbnails = parsed_cachefile.thumbnails; + }); - // Populate playlistSongs and thumbnails - await updateSongs(); + // Wrap in async but don't await as to not delay server boot, we can load from cache faster then we can load from yt music + (async () => { + // Init the moosics stuff + await ytmusic.initialize(); + + // Populate playlistSongs and thumbnails + await updateSongs(); + }); // Populate the blog index await generateBlogIndex(); @@ -319,11 +329,11 @@ async function main() { // Start hourly loop to update playlist loopHourly(async () => await updateSongs()); + + // Start console + customConsole(); }); })(); - - // Start console - customConsole(); } // Handle a few signals -- 2.52.0 From c9d7afd353dffafa5d3849b594a1f1f4b4e6db69 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 15:33:22 -0500 Subject: [PATCH 6/7] add verbose logging to dev server --- index.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index cbbf791..87eb06e 100755 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ const port = process.env.PORT || 48916; /** * Are we prod or dev */ -const dev = process.env.DEV || true; +const dev = process.env.DEV || "true"; // Helper functions I've made to do things and stuff :P @@ -126,6 +126,12 @@ async function send404(req, res) { // Begin the server-ing things const app = express(); + +app.use((req, res, next) => { + if (dev == "true") console.log(req); + next(); +}); + var server; // Set at app.listen (bottom), used to kill server on ctrl-c // YT Music stuff @@ -263,6 +269,7 @@ async function customConsole() { const cmd_raw_args = cmd_raw.split(" "); const cmd_args = cmd_raw_args.slice(1); const cmd = cmd_raw_args[0]; + const cmd_body = cmd_raw.substring(cmd.length).trim(); switch(cmd) { case "?": @@ -279,7 +286,7 @@ async function customConsole() { // ...... i dont know what or how or why but magically it is working now so i am just not gonna touch it and hope // whatever black magic made it work keeps working .-. try { - rl.write(eval(cmd_args.toString()) + "\n"); + rl.write(eval(cmd_body) + "\n"); } catch (err) { console.error(err); } @@ -299,7 +306,13 @@ async function customConsole() { } async function main() { + + if (dev == "true") console.log("Starting custom console"); + // Start console + customConsole(); // DO NOT CALL `await` ON THIS!! THIS WILL CAUSE IT TO NEVER RETURN!! + if (dev == "true") console.log("Console started"); + if (dev == "true") console.log("Loading ytmusic stuffs from cache file"); // Load from cache await (async () => { let cachefile; @@ -307,31 +320,35 @@ async function main() { let parsed_cachefile = JSON.parse(cachefile); playlistSongs = parsed_cachefile.playlistSongs; thumbnails = parsed_cachefile.thumbnails; - }); - + if (dev == "true") console.log("Finished loading from ytmusic stuffs from cache"); + })(); + // Wrap in async but don't await as to not delay server boot, we can load from cache faster then we can load from yt music (async () => { + if (dev == "true") console.log("ytmusic init begining"); // Init the moosics stuff - await ytmusic.initialize(); + await ytmusic.initialize(); + if (dev == "true") console.log("ytmusic initialized"); // Populate playlistSongs and thumbnails await updateSongs(); - }); + if (dev == "true") console.log("Loaded new data from YTMusic!\n"); + })(); + if (dev == "true") console.log("populating blog index") // Populate the blog index await generateBlogIndex(); + if (dev == "true") console.log("populated blog index"); server = http.createServer(app); + if (dev == "true") console.log("Starting server"); await (async () => { server.listen(port, () => { - console.log(`Listening to ${port}`); + console.log(`Listening to ${port}\n`); // Start hourly loop to update playlist loopHourly(async () => await updateSongs()); - - // Start console - customConsole(); }); })(); } -- 2.52.0 From 85279ecc475fba7f7a9c25e8538c42b42ca653c1 Mon Sep 17 00:00:00 2001 From: oddbyte Date: Mon, 19 Jan 2026 16:06:54 -0500 Subject: [PATCH 7/7] make req logging less verbose --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 87eb06e..897da24 100755 --- a/index.js +++ b/index.js @@ -128,7 +128,9 @@ async function send404(req, res) { const app = express(); app.use((req, res, next) => { - if (dev == "true") console.log(req); + if (dev == "true") { + console.log(`got a req to ${req.path}?${req.query} with a body of ${req.body}`); + } next(); }); -- 2.52.0