load ytmusic stuffs from cache and add dev logging #7
37
index.js
37
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();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user