fetchMetadata.ts 563 B

123456789101112131415161718192021222324252627
  1. import pLimit from "p-limit";
  2. import { Root } from "../types";
  3. const limit = pLimit(1);
  4. export let metadata: {
  5. url: string;
  6. data?: Root;
  7. } | null = null;
  8. export async function fetchMetadata(id: string): Promise<void> {
  9. await limit(async () => {
  10. if (metadata?.url === document.location.href) return;
  11. metadata = { url: document.location.href };
  12. metadata.data = await (
  13. await fetch(
  14. `https://www.netflix.com/nq/website/memberapi/release/metadata?movieid=${id}`
  15. )
  16. ).json();
  17. });
  18. }
  19. export function clearMetadata(): void {
  20. metadata = null;
  21. }