diff --git a/src/scoreinfo.ts b/src/scoreinfo.ts index 3356d6a..a0849fd 100644 --- a/src/scoreinfo.ts +++ b/src/scoreinfo.ts @@ -1,4 +1,6 @@ +import { getFetch } from './utils' + export abstract class ScoreInfo { private readonly IPNS_KEY = 'QmSdXtvzC8v8iTTZuj5cVmiugnzbR1QATYRcGix4bBsioP'; private readonly RADIX = 20; @@ -58,6 +60,33 @@ export class ScoreInfoInPage extends ScoreInfo { } } +export class ScoreInfoHtml extends ScoreInfo { + private readonly ID_REG = // + private readonly TITLE_REG = // + + constructor (private html: string) { super() } + + get id (): number { + const m = this.html.match(this.ID_REG) + if (!m) return 0 + return +m[1] + } + + get title (): string { + const m = this.html.match(this.TITLE_REG) + if (!m) return '' + return m[1] + } + + static async request (url: string, _fetch = getFetch()): Promise { + const r = await _fetch(url) + if (!r.ok) return new ScoreInfoHtml('') + + const html = await r.text() + return new ScoreInfoHtml(html) + } +} + export abstract class SheetInfo { abstract pageCount: number; abstract thumbnailUrl: string;