@@ -10,6 +10,7 @@ import type { iTunes } from "https://raw.githubusercontent.com/NextFire/jxa/64b6
10
10
11
11
class Cache {
12
12
static VERSION = 1 ;
13
+ static CACHE_FILE = "cache.json" ;
13
14
static #data: Map < string , iTunesInfos > = new Map ( ) ;
14
15
15
16
static get ( key : string ) {
@@ -23,19 +24,22 @@ class Cache {
23
24
24
25
static async loadCache ( ) {
25
26
try {
26
- const text = await Deno . readTextFile ( "cache.json" ) ;
27
+ const text = await Deno . readTextFile ( this . CACHE_FILE ) ;
27
28
const data = JSON . parse ( text ) ;
28
29
if ( data . version !== this . VERSION ) throw new Error ( "Old cache" ) ;
29
30
this . #data = new Map ( data . data ) ;
30
31
} catch ( err ) {
31
- console . error ( err , "No valid cache.json found, generating a new cache" ) ;
32
+ console . error (
33
+ err ,
34
+ `No valid ${ this . CACHE_FILE } found, generating a new cache...`
35
+ ) ;
32
36
}
33
37
}
34
38
35
39
static async saveCache ( ) {
36
40
try {
37
41
await Deno . writeTextFile (
38
- "cache.json" ,
42
+ this . CACHE_FILE ,
39
43
JSON . stringify ( {
40
44
version : this . VERSION ,
41
45
data : Array . from ( this . #data. entries ( ) ) ,
@@ -49,6 +53,7 @@ class Cache {
49
53
50
54
// Main part
51
55
56
+ const CLIENT_ID = "773825528921849856" ;
52
57
start ( ) ;
53
58
54
59
async function start ( ) {
@@ -58,7 +63,7 @@ async function start() {
58
63
59
64
async function main ( ) {
60
65
try {
61
- const rpc = new Client ( { id : "773825528921849856" } ) ;
66
+ const rpc = new Client ( { id : CLIENT_ID } ) ;
62
67
await rpc . connect ( ) ;
63
68
console . log ( rpc ) ;
64
69
const timer = setInterval ( async ( ) => {
0 commit comments