mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-03 07:59:29 +00:00
28 lines
869 B
TypeScript
28 lines
869 B
TypeScript
import { invokeCommand as invoke } from '../ipc';
|
|
import type { MediaMetadata } from '../bindings/MediaMetadata';
|
|
|
|
type FetchMediaMetadataArgs = {
|
|
url: string;
|
|
cookieBrowser: string | null;
|
|
username: string | null;
|
|
password: string | null;
|
|
};
|
|
|
|
const inFlightMediaMetadata = new Map<string, Promise<MediaMetadata>>();
|
|
|
|
const metadataKey = (args: FetchMediaMetadataArgs) =>
|
|
JSON.stringify([args.url, args.cookieBrowser, args.username, args.password]);
|
|
|
|
export const fetchMediaMetadataDeduped = (args: FetchMediaMetadataArgs): Promise<MediaMetadata> => {
|
|
const key = metadataKey(args);
|
|
const existing = inFlightMediaMetadata.get(key);
|
|
if (existing) return existing;
|
|
|
|
const request = invoke('fetch_media_metadata', args)
|
|
.finally(() => {
|
|
inFlightMediaMetadata.delete(key);
|
|
});
|
|
inFlightMediaMetadata.set(key, request);
|
|
return request;
|
|
};
|