mirror of
https://github.com/neongamerbot-qk/hackclub-nest
synced 2024-11-24 17:33:42 +00:00
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:
parent
7b42e7d8a7
commit
7f7d824439
1 changed files with 26 additions and 22 deletions
|
@ -18,14 +18,17 @@ const db = new QuickDB({
|
||||||
filePath: "./data/songs.sqlite",
|
filePath: "./data/songs.sqlite",
|
||||||
});
|
});
|
||||||
|
|
||||||
function arrayToCsv(data){
|
function arrayToCsv(data) {
|
||||||
return data.map(row =>
|
return data
|
||||||
row
|
.map(
|
||||||
.map(String) // convert every value to String
|
(row) =>
|
||||||
.map(v => v.replaceAll('"', '""')) // escape double quotes
|
row
|
||||||
.map(v => `"${v}"`) // quote it
|
.map(String) // convert every value to String
|
||||||
.join(',') // comma-separated
|
.map((v) => v.replaceAll('"', '""')) // escape double quotes
|
||||||
).join('\r\n'); // rows starting on new lines
|
.map((v) => `"${v}"`) // quote it
|
||||||
|
.join(","), // comma-separated
|
||||||
|
)
|
||||||
|
.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.send(csvData);
|
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`);
|
||||||
|
@ -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);
|
||||||
});
|
});
|
Loading…
Reference in a new issue