feat: abstract storage for scoreinfo instance

This commit is contained in:
Xmader 2020-11-24 02:59:19 -05:00
parent 64b0e4d441
commit 9e9f25ff80
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 6 additions and 1 deletions

View File

@ -2,9 +2,11 @@
import { saveAs, assertRes } from './utils'
import { ScoreInfo } from './scoreinfo'
let msczBufferP: Promise<ArrayBuffer> | undefined
const MSCZ_BUF_SYM = Symbol('msczBufferP')
export const fetchMscz = async (scoreinfo: ScoreInfo): Promise<ArrayBuffer> => {
let msczBufferP = scoreinfo.store.get(MSCZ_BUF_SYM) as Promise<ArrayBuffer> | undefined
if (!msczBufferP) {
const url = scoreinfo.msczCidUrl
msczBufferP = (async (): Promise<ArrayBuffer> => {
@ -16,6 +18,7 @@ export const fetchMscz = async (scoreinfo: ScoreInfo): Promise<ArrayBuffer> => {
const data = await r.arrayBuffer()
return data
})()
scoreinfo.store.set(MSCZ_BUF_SYM, msczBufferP)
}
return msczBufferP

View File

@ -10,6 +10,8 @@ export abstract class ScoreInfo {
abstract pageCount: number;
abstract thumbnailUrl: string;
public store = new Map<symbol, any>();
get idLastDigit (): number {
return (+this.id) % RADIX
}