|
@@ -1,7 +1,8 @@
|
|
-import { ConfigManager, clamp, fetchAdvanced, insertAfter } from "@sv443-network/userutils";
|
|
|
|
|
|
+import { ConfigManager, clamp, compress, decompress, fetchAdvanced, insertAfter } from "@sv443-network/userutils";
|
|
import { constructUrlString, error, getResourceUrl, info, log, onSelectorOld, warn, t, tp } from "../utils";
|
|
import { constructUrlString, error, getResourceUrl, info, log, onSelectorOld, warn, t, tp } from "../utils";
|
|
import { emitInterface } from "../interface";
|
|
import { emitInterface } from "../interface";
|
|
-import { scriptInfo } from "../constants";
|
|
|
|
|
|
+import { compressionFormat, scriptInfo } from "../constants";
|
|
|
|
+import type { LyricsCacheEntry } from "../types";
|
|
|
|
|
|
/** Base URL of geniURL */
|
|
/** Base URL of geniURL */
|
|
export const geniUrlBase = "https://api.sv443.net/geniurl";
|
|
export const geniUrlBase = "https://api.sv443.net/geniurl";
|
|
@@ -24,13 +25,6 @@ void thresholdParam; // TODO: re-add once geniURL 1.4 is released
|
|
/** How many cache entries can exist at a time - this is used to cap memory usage */
|
|
/** How many cache entries can exist at a time - this is used to cap memory usage */
|
|
const maxLyricsCacheSize = 300;
|
|
const maxLyricsCacheSize = 300;
|
|
|
|
|
|
-export type LyricsCacheEntry = {
|
|
|
|
- artist: string;
|
|
|
|
- song: string;
|
|
|
|
- url: string;
|
|
|
|
- added: number;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
export type LyricsCache = {
|
|
export type LyricsCache = {
|
|
cache: LyricsCacheEntry[];
|
|
cache: LyricsCacheEntry[];
|
|
};
|
|
};
|
|
@@ -41,17 +35,19 @@ const lyricsCache = new ConfigManager<LyricsCache>({
|
|
cache: [],
|
|
cache: [],
|
|
},
|
|
},
|
|
formatVersion: 1,
|
|
formatVersion: 1,
|
|
|
|
+ encodeData: (data) => compress(data, compressionFormat, "base64"),
|
|
|
|
+ decodeData: (data) => decompress(data, compressionFormat, "base64"),
|
|
// migrations: {
|
|
// migrations: {
|
|
// // 1 -> 2
|
|
// // 1 -> 2
|
|
// 2: (oldData: Record<string, unknown>) => {
|
|
// 2: (oldData: Record<string, unknown>) => {
|
|
// return {
|
|
// return {
|
|
- // ...oldData,
|
|
|
|
|
|
+ // cache: oldData.cache,
|
|
// };
|
|
// };
|
|
// },
|
|
// },
|
|
// }
|
|
// }
|
|
});
|
|
});
|
|
|
|
|
|
-export async function initLyricsCacheNew() {
|
|
|
|
|
|
+export async function initLyricsCache() {
|
|
const data = await lyricsCache.loadData();
|
|
const data = await lyricsCache.loadData();
|
|
log(`Loaded lyrics cache (${data.cache.length} entries):`, data);
|
|
log(`Loaded lyrics cache (${data.cache.length} entries):`, data);
|
|
return data;
|
|
return data;
|
|
@@ -66,6 +62,11 @@ export function getLyricsCacheEntry(artist: string, song: string) {
|
|
return cache.find(e => e.artist === artist && e.song === song);
|
|
return cache.find(e => e.artist === artist && e.song === song);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/** Returns the full lyrics cache array */
|
|
|
|
+export function getLyricsCache() {
|
|
|
|
+ return lyricsCache.getData().cache;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Adds the provided entry into the lyrics URL cache, synchronously to RAM and asynchronously to GM storage
|
|
* Adds the provided entry into the lyrics URL cache, synchronously to RAM and asynchronously to GM storage
|
|
* {@linkcode artist} and {@linkcode song} need to be sanitized first!
|
|
* {@linkcode artist} and {@linkcode song} need to be sanitized first!
|