diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:22:48 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:22:48 -0700 |
| commit | 14172f9dd64ce91ba5cf51f82c53deb6a81d68a6 (patch) | |
| tree | 5e12ce4e30ecaed9a2aac48d2959d99a4d8b4ef7 /server | |
| parent | 818db3ef4aadf489dba5ba8ba4f3bb4e150f0b22 (diff) | |
create daily/unlimited mode, CDN audio file for daily mode
Diffstat (limited to 'server')
| -rw-r--r-- | server/data/songs.ts | 1 | ||||
| -rw-r--r-- | server/index.ts | 28 |
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); |
