enhancement(lint): Fix lint errors for hackclub-spotify-bot/src/index.js

Co-authored-by: NeonGamerBot-QK <saahilattud@gmail.com>
Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
Signed-off-by: Saahil <neon@saahild.com>
This commit is contained in:
zeon-neon[bot] 2024-10-13 04:16:44 +00:00 committed by Saahil
parent 7b42e7d8a7
commit 7f7d824439
Signed by: neon
GPG key ID: 8A8B64515254CFC6

View file

@ -19,13 +19,16 @@ const db = new QuickDB({
}); });
function arrayToCsv(data) { function arrayToCsv(data) {
return data.map(row => return data
.map(
(row) =>
row row
.map(String) // convert every value to String .map(String) // convert every value to String
.map(v => v.replaceAll('"', '""')) // escape double quotes .map((v) => v.replaceAll('"', '""')) // escape double quotes
.map(v => `"${v}"`) // quote it .map((v) => `"${v}"`) // quote it
.join(',') // comma-separated .join(","), // comma-separated
).join('\r\n'); // rows starting on new lines )
.join("\r\n"); // rows starting on new lines
} }
let cacheDb = {}; let cacheDb = {};
@ -168,18 +171,19 @@ app.get("/home", async (req, res) => {
s: req.query.s, s: req.query.s,
}); });
}); });
app.get('/download/db', async (req,res) => { app.get("/download/db", async (req, res) => {
if(!req.session.info) return res.redirect("/login") if (!req.session.info) return res.redirect("/login");
const allSongs = await db.all(); const allSongs = await db.all();
const csvData = arrayToCsv([["slack_id", "url","song_id", "added_at"], const csvData = arrayToCsv([
...allSongs.map(d => { ["slack_id", "url", "song_id", "added_at"],
return [d.value.added_by, d.value.song_url, d.id, d.value.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.setHeader("Content-Type", "text/csv");
res.setHeader("Content-Disposition", 'attachment; filename="songs.csv"');
res.send(csvData); 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`);
@ -254,9 +258,9 @@ app.listen(process.env.PORT || 3000, async () => {
if (getCredentials() !== null) refreshToken(getCredentials().refresh_token); if (getCredentials() !== null) refreshToken(getCredentials().refresh_token);
}); });
process.on('uncaughtException', function(err) { process.on("uncaughtException", function (err) {
console.log(err); console.log(err);
}); });
process.on('unhandledRejection', function(err) { process.on("unhandledRejection", function (err) {
console.log(err); console.log(err);
}); });