import Store from "electron-store" ; import { EpisodeListEpisodes , Provider } from "@/graphql/generated/types" ; type EpisodeCacheSchema = { [ id ] : { nextEpisodeAiringAt : number ; episodes : EpisodeListEpisodes [ ] ; } ; } ; const episodeCache = new Store < any > ( { name : "episodeCache" , } ) ; const CURRENT_VERSION = 1 ; let schemaVersion = episodeCache . get ( "__version" , null ) ; if ( schemaVersion !== CURRENT_VERSION ) { if ( schemaVersion == null ) { episodeCache . clear ( ) ; schemaVersion = 1 ; } episodeCache . set ( "__version" , schemaVersion ) ; } export class EpisodeCache { public static get ( animeId , provider ) { return episodeCache . get ( `${ provider }:${ animeId }` , null ) ; } public static getNextEpisodeAiringAt ( animeId , provider ) { return episodeCache . get ( `${ provider }:${ animeId }.nextEpisodeAiringAt` , null ) ; } public static set ( animeId , provider , episodes , nextEpisodeAiringAt ) { episodeCache . set ( `${ provider }:${ animeId }` , { nextEpisodeAiringAt , episodes , } ) ; } public static clear ( ) { const version = episodeCache . get ( "__version" ) ; episodeCache . clear ( ) ; episodeCache . set ( "__version" , version ) ; } }