aboutsummaryrefslogtreecommitdiffstats
path: root/server/shared.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/shared.ts')
-rw-r--r--server/shared.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/server/shared.ts b/server/shared.ts
index 3b5344c..9744de9 100644
--- a/server/shared.ts
+++ b/server/shared.ts
@@ -1,5 +1,7 @@
import { createHmac, timingSafeEqual } from "crypto";
import { songs } from "./data/songs";
+import { musicVideos } from "./data/mvs";
+
function getSalt(): string {
return process.env.VITE_HEARDLE_SALT ?? "changeme";
@@ -58,6 +60,7 @@ export function pickSong(date: string): Song {
return songs[index];
}
+
function getLastNDates(n: number): string[] {
const dates: string[] = [];
for (let i = 1; i <= n; i++) {
@@ -83,6 +86,17 @@ export function getDailySong(today: string): Song {
return candidate;
}
+export function pickMusicVideo(date: string): Song {
+ const seed = hashString(date);
+ const index = seed % musicVideos.length;
+ return musicVideos[index];
+}
+
+export function getDailyMusicVideo(today: string): Song {
+ // potentially use deterministic no-repeat here too, for now this is fine
+ return pickMusicVideo(today);
+}
+
function signValue(prefix: string, value: string): string {
return createHmac("sha256", getSigningSecret())
.update(`${prefix}:${value}`)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage