All files / Rindu/utils getGeneratedImageUrl.ts

55.55% Statements 5/9
100% Branches 0/0
0% Functions 0/1
50% Lines 4/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2144x 44x   46x           44x                      
import { getSiteUrl } from "./environment";
import { generateHMACSHA256Token } from "./hmacToken";
 
export enum GeneratedImageAPI {
  TopTracksCover = "/api/top-tracks-cover",
  ConcertCover = "/api/concert-cover",
  RadioCover = "/api/radio-cover",
}
 
export const getGeneratedImageUrl = async (
  api: GeneratedImageAPI,
  params: Record<string, string>
): Promise<string> => {
  const url = new URL(`${getSiteUrl()}${api}`);
  const token = await generateHMACSHA256Token(params);
 
  url.search = new URLSearchParams({ ...params, token }).toString();
 
  return url.toString();
};