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
|
* 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
|
// 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
|
// Begin the server-ing things
|
||||||
const app = express();
|
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
|
var server; // Set at app.listen (bottom), used to kill server on ctrl-c
|
||||||
|
|
||||||
// YT Music stuff
|
// YT Music stuff
|
||||||
@@ -263,6 +269,7 @@ async function customConsole() {
|
|||||||
const cmd_raw_args = cmd_raw.split(" ");
|
const cmd_raw_args = cmd_raw.split(" ");
|
||||||
const cmd_args = cmd_raw_args.slice(1);
|
const cmd_args = cmd_raw_args.slice(1);
|
||||||
const cmd = cmd_raw_args[0];
|
const cmd = cmd_raw_args[0];
|
||||||
|
const cmd_body = cmd_raw.substring(cmd.length).trim();
|
||||||
|
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case "?":
|
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
|
// ...... 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 .-.
|
// whatever black magic made it work keeps working .-.
|
||||||
try {
|
try {
|
||||||
rl.write(eval(cmd_args.toString()) + "\n");
|
rl.write(eval(cmd_body) + "\n");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
@@ -299,7 +306,13 @@ async function customConsole() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
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
|
// Load from cache
|
||||||
await (async () => {
|
await (async () => {
|
||||||
let cachefile;
|
let cachefile;
|
||||||
@@ -307,31 +320,35 @@ async function main() {
|
|||||||
let parsed_cachefile = JSON.parse(cachefile);
|
let parsed_cachefile = JSON.parse(cachefile);
|
||||||
playlistSongs = parsed_cachefile.playlistSongs;
|
playlistSongs = parsed_cachefile.playlistSongs;
|
||||||
thumbnails = parsed_cachefile.thumbnails;
|
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
|
// 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 () => {
|
(async () => {
|
||||||
|
if (dev == "true") console.log("ytmusic init begining");
|
||||||
// Init the moosics stuff
|
// Init the moosics stuff
|
||||||
await ytmusic.initialize();
|
await ytmusic.initialize();
|
||||||
|
if (dev == "true") console.log("ytmusic initialized");
|
||||||
|
|
||||||
// Populate playlistSongs and thumbnails
|
// Populate playlistSongs and thumbnails
|
||||||
await updateSongs();
|
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
|
// Populate the blog index
|
||||||
await generateBlogIndex();
|
await generateBlogIndex();
|
||||||
|
if (dev == "true") console.log("populated blog index");
|
||||||
|
|
||||||
server = http.createServer(app);
|
server = http.createServer(app);
|
||||||
|
|
||||||
|
if (dev == "true") console.log("Starting server");
|
||||||
await (async () => {
|
await (async () => {
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Listening to ${port}`);
|
console.log(`Listening to ${port}\n`);
|
||||||
|
|
||||||
// Start hourly loop to update playlist
|
// Start hourly loop to update playlist
|
||||||
loopHourly(async () => await updateSongs());
|
loopHourly(async () => await updateSongs());
|
||||||
|
|
||||||
// Start console
|
|
||||||
customConsole();
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user