Skip to content

Commit 2ed209a

Browse files
committed
extract constants
1 parent 3f05cae commit 2ed209a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

music-rpc.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { iTunes } from "https://raw.githubusercontent.com/NextFire/jxa/64b6
1010

1111
class Cache {
1212
static VERSION = 1;
13+
static CACHE_FILE = "cache.json";
1314
static #data: Map<string, iTunesInfos> = new Map();
1415

1516
static get(key: string) {
@@ -23,19 +24,22 @@ class Cache {
2324

2425
static async loadCache() {
2526
try {
26-
const text = await Deno.readTextFile("cache.json");
27+
const text = await Deno.readTextFile(this.CACHE_FILE);
2728
const data = JSON.parse(text);
2829
if (data.version !== this.VERSION) throw new Error("Old cache");
2930
this.#data = new Map(data.data);
3031
} 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+
);
3236
}
3337
}
3438

3539
static async saveCache() {
3640
try {
3741
await Deno.writeTextFile(
38-
"cache.json",
42+
this.CACHE_FILE,
3943
JSON.stringify({
4044
version: this.VERSION,
4145
data: Array.from(this.#data.entries()),
@@ -49,6 +53,7 @@ class Cache {
4953

5054
// Main part
5155

56+
const CLIENT_ID = "773825528921849856";
5257
start();
5358

5459
async function start() {
@@ -58,7 +63,7 @@ async function start() {
5863

5964
async function main() {
6065
try {
61-
const rpc = new Client({ id: "773825528921849856" });
66+
const rpc = new Client({ id: CLIENT_ID });
6267
await rpc.connect();
6368
console.log(rpc);
6469
const timer = setInterval(async () => {

0 commit comments

Comments
 (0)