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/index.ts | |
| parent | 818db3ef4aadf489dba5ba8ba4f3bb4e150f0b22 (diff) | |
create daily/unlimited mode, CDN audio file for daily mode
Diffstat (limited to 'server/index.ts')
| -rw-r--r-- | server/index.ts | 28 |
1 files changed, 25 insertions, 3 deletions
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); |
