initial work
commit
fe1b8be519
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"deno.enable": true,
|
||||||
|
"deno.unstable": true
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import { IAxiodResponse } from "https://deno.land/x/axiod@0.26.2/interfaces.ts";
|
||||||
|
import axiod from "https://deno.land/x/axiod@0.26.2/mod.ts";
|
||||||
|
import Work from "./Work.ts";
|
||||||
|
|
||||||
|
export default class AO3 {
|
||||||
|
session: typeof axiod
|
||||||
|
|
||||||
|
constructor(opts?: Record<string, any>) {
|
||||||
|
this.session = axiod.create({
|
||||||
|
baseURL: opts?.url ?? "https://archiveofourown.org/"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getWork(id: ID) {
|
||||||
|
const res = await this.session.get(`/works/${id}?view_adult=true&view_full_work=true`)
|
||||||
|
return new Work(id, res.data, this.session)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
export default class Chapter {
|
||||||
|
constructor(workId: ID, id: ID) {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import axiod from "https://deno.land/x/axiod@0.26.2/mod.ts"
|
||||||
|
import Chapter from "./Chapter.ts"
|
||||||
|
import { DOMParser, Element, HTMLDocument } from "https://deno.land/x/deno_dom@v0.1.35-alpha/deno-dom-wasm.ts";
|
||||||
|
|
||||||
|
export default class Work {
|
||||||
|
session: typeof axiod
|
||||||
|
id: ID
|
||||||
|
document: HTMLDocument
|
||||||
|
chapters: Chapter[] = []
|
||||||
|
tags: string[] = []
|
||||||
|
published?: Date
|
||||||
|
updated?: Date
|
||||||
|
|
||||||
|
constructor(id: ID, body: string, session: typeof axiod) {
|
||||||
|
this.session = session
|
||||||
|
this.id = id
|
||||||
|
this.document = new DOMParser().parseFromString(body, "text/html") as HTMLDocument
|
||||||
|
this.populateTags()
|
||||||
|
this.populateDates()
|
||||||
|
}
|
||||||
|
|
||||||
|
populateTags() {
|
||||||
|
Array.from((this.document.querySelector("dd.fandom > ul.commas") as Element).children).map(
|
||||||
|
t => this.tags.push(t.children[0].innerText)
|
||||||
|
)
|
||||||
|
Array.from((this.document.querySelector("dd.relationship > ul.commas") as Element).children).map(
|
||||||
|
t => this.tags.push(t.children[0].innerText)
|
||||||
|
)
|
||||||
|
Array.from((this.document.querySelector("dd.character > ul.commas") as Element).children).map(
|
||||||
|
t => this.tags.push(t.children[0].innerText)
|
||||||
|
)
|
||||||
|
Array.from((this.document.querySelector("dd.freeform > ul.commas") as Element).children).map(
|
||||||
|
t => this.tags.push(t.children[0].innerText)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
populateDates() {
|
||||||
|
this.published = new Date(this.document.querySelector("dd.published")?.innerText as string)
|
||||||
|
this.updated = new Date(this.document.querySelector("dd.status")?.innerText as string)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
type ID = BigInt | number | string
|
@ -0,0 +1,14 @@
|
|||||||
|
import AO3 from "./src/classes/AO3.ts";
|
||||||
|
import { assert } from "https://deno.land/std@0.161.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
const ao3 = new AO3();
|
||||||
|
|
||||||
|
const work = await ao3.getWork(37522864)
|
||||||
|
|
||||||
|
assert(work.tags.length > 0)
|
||||||
|
assert(work.tags.includes("Attempted Murder"))
|
||||||
|
console.log(`TAGS: ${work.tags}`)
|
||||||
|
assert(work.published instanceof Date)
|
||||||
|
console.log(`PUBLISHED: ${work.published}`)
|
||||||
|
assert(work.updated instanceof Date)
|
||||||
|
console.log(`UPDATED: ${work.updated}`)
|
Loading…
Reference in new issue