mirror of
https://github.com/neongamerbot-qk/hackclub-nest
synced 2024-11-28 19:13:40 +00:00
Compare commits
20 commits
4df82e3d81
...
2120076218
Author | SHA1 | Date | |
---|---|---|---|
|
2120076218 | ||
|
c25f853dbb | ||
|
c26d26f27c | ||
|
4d8971ef81 | ||
9bf5d89464 | |||
|
8848d40b68 | ||
|
fdd184a8eb | ||
|
1fa86c2807 | ||
a93103d996 | |||
|
1282743295 | ||
|
8c24a2760f | ||
|
7ef5256e63 | ||
|
4969b4941d | ||
|
98b3cf258b | ||
|
a8409d6bf4 | ||
|
1cf2d561a4 | ||
|
38c3ed1967 | ||
|
aa73856b49 | ||
7d50117f95 | |||
70d44be463 |
13 changed files with 136 additions and 43 deletions
|
@ -1,20 +0,0 @@
|
||||||
cat .config/systemd/user/caddy.service
|
|
||||||
screen
|
|
||||||
htop
|
|
||||||
free -m -h
|
|
||||||
quota
|
|
||||||
quota -h
|
|
||||||
ls
|
|
||||||
du -h
|
|
||||||
neofetch
|
|
||||||
ls -a
|
|
||||||
htop
|
|
||||||
free -m -h
|
|
||||||
ls
|
|
||||||
nest resources
|
|
||||||
ls
|
|
||||||
mutt
|
|
||||||
ls Mail/
|
|
||||||
mutt
|
|
||||||
ls -a
|
|
||||||
exit
|
|
|
@ -1 +1,60 @@
|
||||||
{"admin":{"listen":"unix//home/neon/caddy-admin.sock"},"apps":{"http":{"servers":{"srv0":{"automatic_https":{"skip":["neon.hackclub.app"]},"listen":["unix/.webserver.sock|777"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"vars","root":"/home/neon/pub"},{"handler":"file_server","hide":[".git",".env","/home/neon/Caddyfile"]}]}]}],"match":[{"host":["neon.hackclub.app"]}],"terminal":true}]}}}}}
|
{
|
||||||
|
"admin": { "listen": "unix//home/neon/caddy-admin.sock" },
|
||||||
|
"apps": {
|
||||||
|
"http": {
|
||||||
|
"servers": {
|
||||||
|
"srv0": {
|
||||||
|
"automatic_https": { "skip": ["spotify.hackclub.app"] },
|
||||||
|
"listen": ["unix/.spotify.neon.hackclub.app.webserver.sock|777"],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "subroute",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "reverse_proxy",
|
||||||
|
"upstreams": [{ "dial": "localhost:38275" }]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"match": [{ "host": ["spotify.hackclub.app"] }],
|
||||||
|
"terminal": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"srv1": {
|
||||||
|
"automatic_https": { "skip": ["neon.hackclub.app"] },
|
||||||
|
"listen": ["unix/.webserver.sock|777"],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "subroute",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{ "handler": "vars", "root": "/home/neon/pub" },
|
||||||
|
{
|
||||||
|
"handler": "file_server",
|
||||||
|
"hide": [".git", ".env", "/home/neon/Caddyfile"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"match": [{ "host": ["neon.hackclub.app"] }],
|
||||||
|
"terminal": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,8 +1,12 @@
|
||||||
*.sock
|
*.sock
|
||||||
|
.npm
|
||||||
.config/git
|
.config/git
|
||||||
.config/pulse # tokens
|
.config/pulse # tokens
|
||||||
Mail # mail sent to neon@hackclub.app is here
|
.config/caddy
|
||||||
sent # all sent mail is there
|
Mail
|
||||||
|
sent
|
||||||
|
Mail/* # mail sent to neon@hackclub.app is here
|
||||||
|
sent/* # all sent mail is there
|
||||||
.bun
|
.bun
|
||||||
.local
|
.local
|
||||||
.nix-profile
|
.nix-profile
|
||||||
|
|
1
.lesshst
Normal file
1
.lesshst
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.less-history-file:
|
|
@ -9,3 +9,7 @@ http://neon.hackclub.app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http://spotify.hackclub.app {
|
||||||
|
bind unix/.spotify.sock|777
|
||||||
|
reverse_proxy localhost:378625
|
||||||
|
}
|
||||||
|
|
1
Mail/.gitignore
vendored
Normal file
1
Mail/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*
|
|
@ -4,12 +4,12 @@
|
||||||
- - [x] oauth [docs](https://tools.slack.dev/node-slack-sdk/oauth)
|
- - [x] oauth [docs](https://tools.slack.dev/node-slack-sdk/oauth)
|
||||||
- - [ ] fix the [channel](https://app.slack.com/client/T0266FRGM/C07RE4N7S4B)
|
- - [ ] fix the [channel](https://app.slack.com/client/T0266FRGM/C07RE4N7S4B)
|
||||||
- - - [x] Add ping for new-song event & send message ovs
|
- - - [x] Add ping for new-song event & send message ovs
|
||||||
- [ ] Spotify
|
- [x] Spotify
|
||||||
- - [x] web api [docs](https://developer.spotify.com/documentation/web-api/)
|
- - [x] web api [docs](https://developer.spotify.com/documentation/web-api/)
|
||||||
- - [x] oauth [docs](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
|
- - [x] oauth [docs](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
|
||||||
- - [x] refresh token [docs](https://developer.spotify.com/documentation/general/guides/authorization-guide/#refresh-an-access-token)
|
- - [x] refresh token [docs](https://developer.spotify.com/documentation/general/guides/authorization-guide/#refresh-an-access-token)
|
||||||
- - [x] playlist tools (creation,modifcation,deletion)
|
- - [x] playlist tools (creation,modifcation,deletion)
|
||||||
- [x] keydb (quick db or smthing)
|
- [x] keydb (quick db or smthing)
|
||||||
- [x] express
|
- [x] express
|
||||||
- [ ] transparency of added songs
|
- [x] transparency of added songs
|
||||||
- - [ ] export db -> into csv with properties (slack_id, url, added_at)
|
- - [x] export db -> into csv with properties (slack_id, url, added_at)
|
||||||
|
|
|
@ -17,6 +17,20 @@ const { QuickDB } = require("quick.db");
|
||||||
const db = new QuickDB({
|
const db = new QuickDB({
|
||||||
filePath: "./data/songs.sqlite",
|
filePath: "./data/songs.sqlite",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function arrayToCsv(data) {
|
||||||
|
return data
|
||||||
|
.map(
|
||||||
|
(row) =>
|
||||||
|
row
|
||||||
|
.map(String) // convert every value to String
|
||||||
|
.map((v) => v.replaceAll('"', '""')) // escape double quotes
|
||||||
|
.map((v) => `"${v}"`) // quote it
|
||||||
|
.join(","), // comma-separated
|
||||||
|
)
|
||||||
|
.join("\r\n"); // rows starting on new lines
|
||||||
|
}
|
||||||
|
|
||||||
let cacheDb = {};
|
let cacheDb = {};
|
||||||
const app = express();
|
const app = express();
|
||||||
const userScopes = ["identity.avatar", "identity.basic", "identity.team"];
|
const userScopes = ["identity.avatar", "identity.basic", "identity.team"];
|
||||||
|
@ -69,7 +83,7 @@ app.use(
|
||||||
path: path.join(__dirname, "../data/sessions"),
|
path: path.join(__dirname, "../data/sessions"),
|
||||||
}),
|
}),
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
cookie: { secure: "auto", maxAge: 1000 * 60 * 60 * 24 * 365 },
|
cookie: { secure: "auto", maxAge: 1000 * 60 * 60 * 24 * 7 },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -157,6 +171,19 @@ app.get("/home", async (req, res) => {
|
||||||
s: req.query.s,
|
s: req.query.s,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
app.get("/download/db", async (req, res) => {
|
||||||
|
if (!req.session.info) return res.redirect("/login");
|
||||||
|
const allSongs = await db.all();
|
||||||
|
const csvData = arrayToCsv([
|
||||||
|
["slack_id", "url", "song_id", "added_at"],
|
||||||
|
...allSongs.map((d) => {
|
||||||
|
return [d.value.added_by, d.value.song_url, d.id, d.value.added_at];
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
res.setHeader("Content-Type", "text/csv");
|
||||||
|
res.setHeader("Content-Disposition", 'attachment; filename="songs.csv"');
|
||||||
|
res.send(csvData);
|
||||||
|
});
|
||||||
app.post("/spotify/submitsong", async (req, res) => {
|
app.post("/spotify/submitsong", async (req, res) => {
|
||||||
if (!req.session.token) return res.redirect("/login");
|
if (!req.session.token) return res.redirect("/login");
|
||||||
if (!cacheDb[req.query.token]) return res.redirect(`/home?error=0`);
|
if (!cacheDb[req.query.token]) return res.redirect(`/home?error=0`);
|
||||||
|
@ -230,3 +257,10 @@ app.listen(process.env.PORT || 3000, async () => {
|
||||||
// if(!await db.has())
|
// if(!await db.has())
|
||||||
if (getCredentials() !== null) refreshToken(getCredentials().refresh_token);
|
if (getCredentials() !== null) refreshToken(getCredentials().refresh_token);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
process.on("uncaughtException", function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
process.on("unhandledRejection", function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
|
@ -633,3 +633,12 @@ td {
|
||||||
max-width: var(--size-narrow-plus);
|
max-width: var(--size-narrow-plus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* custom additions */
|
||||||
|
.error {
|
||||||
|
color: var(--red);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.success {
|
||||||
|
color: var(--green);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
|
@ -23,18 +23,21 @@
|
||||||
<div class="card container" style="max-width: 550px;">
|
<div class="card container" style="max-width: 550px;">
|
||||||
<h2 class="headline">Submit Song</h2>
|
<h2 class="headline">Submit Song</h2>
|
||||||
<!-- <p> -->
|
<!-- <p> -->
|
||||||
<form action="/spotify/submitsong?token=<%=onetimetoken%>" method="POST">
|
<form action="/spotify/submitsong?token=<%=onetimetoken%>" method="POST" disabled="<%=s%>">
|
||||||
|
|
||||||
<div class="interactive">
|
<div class="interactive">
|
||||||
<label>Song URL</label>
|
<label>Song URL</label>
|
||||||
<input type="url" name="songurl" placeholder="https://open.spotify.com/track/6aWOvqmjb3343D5sq7zMgl?si=b72b81a97e564dc3" />
|
<input type="url" name="songurl" disabled="<%=s%>" placeholder="https://open.spotify.com/track/6aWOvqmjb3343D5sq7zMgl?si=b72b81a97e564dc3" />
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<!-- </p> -->
|
<!-- </p> -->
|
||||||
<% if (s) { %>
|
<% if (s) { %>
|
||||||
|
<!-- <meta property="hhtp-equiv" content="refresh"> -->
|
||||||
|
<meta http-equiv="refresh" content="5; url='/home'" />
|
||||||
<div class="success">
|
<div class="success">
|
||||||
<h2>Success!</h2>
|
<h2>Success!</h2>
|
||||||
<p>Your song has been added to the playlist!</p>
|
<p class="success">Your song has been added to the playlist!</p>
|
||||||
|
<p>refreshing page in 5s</p>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
@ -46,16 +49,22 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<button type="submit">Submit</button>
|
<button type="submit" disabled="<%=s%>">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer style="display: inline-flex;padding-left: 2px;padding-right: 2px;">
|
||||||
<a href="/logout" class="button">Logout</a>
|
<a href="/logout" class="button" style="padding-left: 2px;padding-right: 2px;">Logout</a>
|
||||||
|
<div>
|
||||||
|
<a href="/download/db" download class="button" style="margin-left: 8px;margin-right: 2px;">Download all song entries</a>
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
<p style="max-width: 250px; inline-size: max-content; word-break: break-all;color: gray;"> The "Download all song entries" button includes all songs submited thru the form (even if removed from the playlist)</p>
|
||||||
|
<a href="https://open.spotify.com/playlist/3gRv97fvllFFLVdCH6XzsE?si=eUQm8275QdyMquBbNdPVHA">Check out the playlist</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<a href="/login">Login Page</a>
|
<a href="/login">Login Page</a>
|
||||||
|
<a href="https://open.spotify.com/playlist/3gRv97fvllFFLVdCH6XzsE?si=eUQm8275QdyMquBbNdPVHA">Check out the playlist</a>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
|
|
1
sent/.gitignore
vendored
Normal file
1
sent/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*
|
|
@ -1,10 +0,0 @@
|
||||||
Date: Fri, 13 Sep 2024 01:41:52 +0000
|
|
||||||
From: neon <neon@hackclub.app>
|
|
||||||
To: neon@saahild.com
|
|
||||||
Subject: Hi
|
|
||||||
Message-ID: <ZuOYYH41PzEkqYrv@hackclub.app>
|
|
||||||
MIME-Version: 1.0
|
|
||||||
Content-Type: text/plain; charset=us-ascii
|
|
||||||
Content-Disposition: inline
|
|
||||||
|
|
||||||
Hello World!
|
|
Loading…
Reference in a new issue