feat: abstract storage for scoreinfo instance
This commit is contained in:
parent
64b0e4d441
commit
9e9f25ff80
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue