refactor: implement sheetImgType
in abstract class
This commit is contained in:
parent
120d57b0e0
commit
aafb71fc4b
1 changed files with 8 additions and 16 deletions
|
@ -9,7 +9,6 @@ export abstract class ScoreInfo {
|
||||||
|
|
||||||
abstract pageCount: number;
|
abstract pageCount: number;
|
||||||
abstract thumbnailUrl: string;
|
abstract thumbnailUrl: string;
|
||||||
abstract sheetImgType: 'svg' | 'png'
|
|
||||||
|
|
||||||
get idLastDigit (): number {
|
get idLastDigit (): number {
|
||||||
return (+this.id) % RADIX
|
return (+this.id) % RADIX
|
||||||
|
@ -26,6 +25,12 @@ export abstract class ScoreInfo {
|
||||||
get msczCidUrl (): string {
|
get msczCidUrl (): string {
|
||||||
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.msczIpfsRef}`
|
return `https://ipfs.infura.io:5001/api/v0/block/stat?arg=${this.msczIpfsRef}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sheetImgType (): 'svg' | 'png' {
|
||||||
|
const thumbnail = this.thumbnailUrl
|
||||||
|
const imgtype = thumbnail.match(/\.(\w+)$/)![1]
|
||||||
|
return imgtype as 'svg' | 'png'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ScoreInfoInPage extends ScoreInfo {
|
export class ScoreInfoInPage extends ScoreInfo {
|
||||||
|
@ -48,23 +53,10 @@ export class ScoreInfoInPage extends ScoreInfo {
|
||||||
|
|
||||||
get thumbnailUrl (): string {
|
get thumbnailUrl (): string {
|
||||||
// url to the image of the first page
|
// url to the image of the first page
|
||||||
const el = this.document.querySelector("meta[property='og:image']") as HTMLMetaElement
|
const el = this.document.querySelector('link[as=image]') as HTMLLinkElement
|
||||||
const url = el.content
|
const url = el.href
|
||||||
return url.split('@')[0]
|
return url.split('@')[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
get sheetImgType (): 'svg' | 'png' {
|
|
||||||
try {
|
|
||||||
const imgE = this.document.querySelector('img[src*=score_]') as HTMLImageElement
|
|
||||||
const { pathname } = new URL(imgE.src)
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const imgtype = pathname.match(/\.(\w+)$/)![1]
|
|
||||||
return imgtype as 'svg' | 'png'
|
|
||||||
} catch (_) {
|
|
||||||
// return null
|
|
||||||
return 'svg'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const scoreinfo = new ScoreInfoInPage(document)
|
export const scoreinfo = new ScoreInfoInPage(document)
|
||||||
|
|
Loading…
Reference in a new issue