Compare commits
14 Commits
732d221e11
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f8a9d37221 | |||
| de24f5488e | |||
| 3d0c93fbef | |||
| 85279ecc47 | |||
| c9d7afd353 | |||
| 669231e8a6 | |||
| 227cde48d9 | |||
| 9ff2252227 | |||
| 372620e2c9 | |||
| 4b27236ae3 | |||
| 092109b48d | |||
| f5189af0c9 | |||
| e458d8972e | |||
| b57c92a999 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ private/
|
|||||||
*/private/
|
*/private/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
.env
|
.env
|
||||||
|
ytmusic_cache
|
||||||
|
.vscode
|
||||||
|
|||||||
57
index.js
57
index.js
@@ -29,12 +29,12 @@ const playlistId = 'PLnlTMS4cxfx3-et_L8APzpEgy_eCf18-U';
|
|||||||
/**
|
/**
|
||||||
* Port that nginx proxies to public
|
* Port that nginx proxies to public
|
||||||
*/
|
*/
|
||||||
const port = process.env.PORT || 48915;
|
const port = process.env.PORT || 48916;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are we prod or dev
|
* Are we prod or dev
|
||||||
*/
|
*/
|
||||||
const dev = process.env.DEV || false;
|
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
|
||||||
|
|
||||||
@@ -88,6 +88,8 @@ async function updateSongs() {
|
|||||||
if (typeof playlistSongs == 'object') {
|
if (typeof playlistSongs == 'object') {
|
||||||
// For each song that youtube moosic has yelled back at us, give them individually to populateThumbnails()
|
// 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)));
|
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 {
|
else {
|
||||||
// like legit this shouldnt even be possible
|
// like legit this shouldnt even be possible
|
||||||
@@ -124,6 +126,14 @@ 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(`got a req to ${req.path}?${req.query} with a body of ${req.body}`);
|
||||||
|
}
|
||||||
|
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
|
||||||
@@ -261,6 +271,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 "?":
|
||||||
@@ -277,7 +288,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);
|
||||||
}
|
}
|
||||||
@@ -296,32 +307,52 @@ 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() {
|
async function main() {
|
||||||
|
|
||||||
// Init the moosics stuff (black magic)
|
if (dev == "true") console.log("Starting custom console");
|
||||||
await ytmusic.initialize();
|
// Start console
|
||||||
|
customConsole(); // DO NOT CALL `await` ON THIS!! THIS WILL CAUSE IT TO NEVER RETURN!!
|
||||||
|
if (dev == "true") console.log("Console started");
|
||||||
|
|
||||||
// Populate playlistSongs and thumbnails
|
if (dev == "true") console.log("Loading ytmusic stuffs from cache file");
|
||||||
await updateSongs();
|
// 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;
|
||||||
|
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();
|
||||||
|
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
|
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a few signals
|
// Handle a few signals
|
||||||
|
|||||||
2
start.sh
2
start.sh
@@ -8,5 +8,5 @@ sudo -iu prod fuser $(sudo -iu prod which node) -k
|
|||||||
echo '==== Restarting Nginx ===='
|
echo '==== Restarting Nginx ===='
|
||||||
rc-service nginx restart
|
rc-service nginx restart
|
||||||
echo '===== Starting server ===='
|
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'
|
echo 'boosh'
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ screen -wipe portfolio_devel
|
|||||||
echo '==== Restarting Nginx ===='
|
echo '==== Restarting Nginx ===='
|
||||||
rc-service nginx restart
|
rc-service nginx restart
|
||||||
echo '===== Starting server ===='
|
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 .'
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
Hihi :D<br />
|
Hihi :D<br />
|
||||||
I am a nerd that happens to like hacking stuff.<br />
|
I am a nerd that happens to like hacking stuff.<br />
|
||||||
I mainly nerd about privacy, android, web development, cybersecurity, and sysadmin.<br />
|
I mainly nerd about privacy, android, web development, cybersecurity, and sysadmin.<br />
|
||||||
My goal is to become a CISO.
|
My goal is to become a CISO.<br />
|
||||||
|
I host my own git server at <a href="/git">/git</a> to gain sysadmin experience and to move off of microslop's github.
|
||||||
</p>
|
</p>
|
||||||
<div id="v-break"></div>
|
<div id="v-break"></div>
|
||||||
<h2 id="stats" class="selectDisable">Stats</h2>
|
<h2 id="stats" class="selectDisable">Stats</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user