aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/data/songs.ts1
-rw-r--r--server/index.ts28
2 files changed, 25 insertions, 4 deletions
diff --git a/server/data/songs.ts b/server/data/songs.ts
index 08e9230..7a1ebf8 100644
--- a/server/data/songs.ts
+++ b/server/data/songs.ts
@@ -422,7 +422,6 @@ export const songs = [
{ artist: "aespa", name: "Flights, Not Feelings", youtubeId: "Qe7FP1abS5s" },
{ artist: "LE SSERAFIM", name: "HOT", youtubeId: "cCkAcVOS3ig" },
{ artist: "i-dle", name: "Allergy", youtubeId: "Gcp87-ZegRA" },
- { artist: "NewJeans", name: "Get Up", youtubeId: "SXM1q0CTfew" },
{ artist: "9MUSES", name: "Dolls", youtubeId: "QM58UGunHKY" },
{ artist: "Red Velvet", name: "Cosmic", youtubeId: "46FxItq18h0" },
{ artist: "ILLIT", name: "Midnight Fiction", youtubeId: "Sr7dWdf4Z3U" },
diff --git a/server/index.ts b/server/index.ts
index c78352a..54b3c18 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -25,10 +25,32 @@ function xorBuffer(data: Buffer, key: Buffer): Buffer {
return output;
}
+function getUtcDate(): string {
+ return new Date().toISOString().slice(0, 10);
+}
+function hashString(str: string): number {
+ let hash = 0;
+ for (let i = 0; i < str.length; i++) {
+ hash = (hash * 31 + str.charCodeAt(i)) >>> 0;
+ }
+ return hash;
+}
+
app.get('/today', (_req, res) => {
- const msInDay = 86_400_000;
- const index = Math.floor((Date.now() - startDate.getTime()) / msInDay);
- const song = songs[index % songs.length];
+ const date = getUtcDate();
+ const seed = hashString(date);
+ const index = seed % songs.length;
+ const song = songs[index];
+ const obfuscationKey = getObfuscationKey();
+ const songJson = JSON.stringify(song);
+ const obfuscatedData = xorBuffer(Buffer.from(songJson, 'utf8'), obfuscationKey);
+ res.json({
+ data: obfuscatedData.toString('hex'),
+ });
+});
+
+app.get('/select', (_req, res) => {
+ const song = songs[Math.floor(Math.random() * songs.length)];
const obfuscationKey = getObfuscationKey();
const songJson = JSON.stringify(song);
const obfuscatedData = xorBuffer(Buffer.from(songJson, 'utf8'), obfuscationKey);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage