actually load from cache
This commit is contained in:
30
index.js
30
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
|
||||
|
||||
Reference in New Issue
Block a user