feat: abstract storage for scoreinfo instance
This commit is contained in:
parent
64b0e4d441
commit
9e9f25ff80
|
@ -2,9 +2,11 @@
|
||||||
import { saveAs, assertRes } from './utils'
|
import { saveAs, assertRes } from './utils'
|
||||||
import { ScoreInfo } from './scoreinfo'
|
import { ScoreInfo } from './scoreinfo'
|
||||||
|
|
||||||
let msczBufferP: Promise<ArrayBuffer> | undefined
|
const MSCZ_BUF_SYM = Symbol('msczBufferP')
|
||||||
|
|
||||||
export const fetchMscz = async (scoreinfo: ScoreInfo): Promise<ArrayBuffer> => {
|
export const fetchMscz = async (scoreinfo: ScoreInfo): Promise<ArrayBuffer> => {
|
||||||
|
let msczBufferP = scoreinfo.store.get(MSCZ_BUF_SYM) as Promise<ArrayBuffer> | undefined
|
||||||
|
|
||||||
if (!msczBufferP) {
|
if (!msczBufferP) {
|
||||||
const url = scoreinfo.msczCidUrl
|
const url = scoreinfo.msczCidUrl
|
||||||
msczBufferP = (async (): Promise<ArrayBuffer> => {
|
msczBufferP = (async (): Promise<ArrayBuffer> => {
|
||||||
|
@ -16,6 +18,7 @@ export const fetchMscz = async (scoreinfo: ScoreInfo): Promise<ArrayBuffer> => {
|
||||||
const data = await r.arrayBuffer()
|
const data = await r.arrayBuffer()
|
||||||
return data
|
return data
|
||||||
})()
|
})()
|
||||||
|
scoreinfo.store.set(MSCZ_BUF_SYM, msczBufferP)
|
||||||
}
|
}
|
||||||
|
|
||||||
return msczBufferP
|
return msczBufferP
|
||||||
|
|
|
@ -10,6 +10,8 @@ export abstract class ScoreInfo {
|
||||||
abstract pageCount: number;
|
abstract pageCount: number;
|
||||||
abstract thumbnailUrl: string;
|
abstract thumbnailUrl: string;
|
||||||
|
|
||||||
|
public store = new Map<symbol, any>();
|
||||||
|
|
||||||
get idLastDigit (): number {
|
get idLastDigit (): number {
|
||||||
return (+this.id) % RADIX
|
return (+this.id) % RADIX
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue