Some stuff
ci/woodpecker/push/woodpecker Pipeline failed Details

Co-authored-by: Tymon <nomyTx@users.noreply.github.com>
master
Drake 1 year ago
parent b41a734cd3
commit f97020d326

@ -118,15 +118,15 @@ export default class Chapter {
async populateText() { async populateText() {
this.#text = ""; this.#text = "";
Array.from( const elements = this.#document.querySelectorAll(
this.#document.querySelectorAll( "div.userstuff[role='article'] > p",
"div.userstuff[role='article'] > p",
),
).forEach(
(t) => {
this.#text += (t as Element).innerText + "\n";
},
); );
for (let i = 0; i < elements.length; i++) {
const element = elements[i] as Element;
this.#text += element.innerText + "\n";
}
try { try {
this.#text = this.#text.trim(); this.#text = this.#text.trim();
@ -147,16 +147,16 @@ export default class Chapter {
"[role='article'] > div.userstuff", "[role='article'] > div.userstuff",
) as Element).innerHTML; ) as Element).innerHTML;
Array.from( const elements = this.#document.querySelectorAll(
this.#document.querySelectorAll( "[role='article'] > div.userstuff > p",
"[role='article'] > div.userstuff > p",
),
).forEach(
(t) => {
this.#text += (t as Element).innerText + "\n";
this.#html += (t as Element).innerHTML;
},
); );
for (let i = 0; i < elements.length; i++) {
const element = elements[i] as Element;
this.#text += element.innerText + "\n";
this.#html += element.innerHTML;
}
} }
} }
} }

@ -1,7 +1,6 @@
//NOTE: AO3's searching "api" is an absolute clusterfuck. i'm sorry. //NOTE: AO3's searching "api" is an absolute clusterfuck. i'm sorry.
import Work from "./Work.ts"; import Work from "./Work.ts";
import asyncForEach from "../utils/asyncForeach.ts";
import { DOMParser, Element, HTMLDocument } from "../types.d.ts"; import { DOMParser, Element, HTMLDocument } from "../types.d.ts";
export const Ratings = { export const Ratings = {
@ -102,29 +101,29 @@ export default class Search {
"text/html", "text/html",
) as HTMLDocument; ) as HTMLDocument;
let i = 0;
const limit = this.#opts.limit ?? 20; const limit = this.#opts.limit ?? 20;
await asyncForEach( const elements = this.#document.querySelectorAll("[role='article']");
Array.from(this.#document.querySelectorAll("[role='article']")),
async (e: Element) => { for (let i = 0; i < elements.length; i++) {
if (i >= limit) { const element: Element = elements[i] as Element;
return;
} if (i >= limit) {
const workId = e.id.replace("work_", ""); return;
//console.log(workId); }
const res = await this.#session.get(
`/works/${workId}?view_adult=true&view_full_work=true`, const workId = element.id.replace("work_", "");
); const res = await this.#session.get(
const work = new Work( `/works/${workId}?view_adult=true&view_full_work=true`,
workId, );
await res.text(), const work = new Work(
this.#session, workId,
this.#DOMParser, await res.text(),
); this.#session,
await work.init(); this.#DOMParser,
this.results.push(work); );
i++;
}, await work.init();
); this.results.push(work);
}
} }
} }

@ -75,34 +75,24 @@ export default class Work {
} }
populateTags() { populateTags() {
Array.from( /* this.#document.querySelectorAll("dd.fandom > ul.commas > li").map(
(this.#document.querySelector("dd.fandom > ul.commas") as Element) (t) => this.tags.push(t.text),
?.children ?? [],
).map(
(t) => this.tags.push(t.children[0].innerText),
); );
Array.from( this.#document.querySelectorAll("dd.relationship > ul.commas > li").map(
(this.#document.querySelector( (t) => this.tags.push(t.text),
"dd.relationship > ul.commas",
) as Element)
?.children ?? [],
).map(
(t) => this.tags.push(t.children[0].innerText),
); );
Array.from( this.#document.querySelectorAll("dd.character > ul.commas > li").map(
(this.#document.querySelector( (t) => this.tags.push(t.text),
"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 ?? [], //does that make me insane
).map(
(t) => this.tags.push(t.children[0].innerText),
); );
this.#document.querySelectorAll("dd.freeform > ul.commas > li").map(
(t) => this.tags.push(t.text),
); */
const elements = this.#document.querySelectorAll("dd > ul.commas > li");
for (let i = 0; i < elements.length; i++) {
this.tags.push((elements[i] as Element)?.innerText);
}
} }
populateDates() { populateDates() {
@ -143,23 +133,29 @@ export default class Work {
"text/html", "text/html",
) as HTMLDocument; ) as HTMLDocument;
Array.from((document.getElementById("selected_id") as Element).children) const elements = (Array.from(
document.querySelectorAll("#selected_id > option"),
) as Element[])
.sort( .sort(
(a, b) => { (a: Element, b: Element) => {
return Number(a.getAttribute("value")) - return Number(a.getAttribute("value")) -
Number(b.getAttribute("value")); Number(b.getAttribute("value"));
}, },
).forEach((c) => { );
const newChapter = new Chapter(
this.id, for (let i = 0; i < elements.length; i++) {
c.getAttribute("value") as string, const element = elements[i];
this.#session,
this.#DOMParser, const newChapter = new Chapter(
{ name: c.innerText }, this.id,
); element.getAttribute("value") as string,
this.chapters.push( this.#session,
newChapter, this.#DOMParser,
); { name: element.innerText },
}); );
this.chapters.push(
newChapter,
);
}
} }
} }

@ -1,9 +0,0 @@
// deno-lint-ignore-file no-explicit-any
export default async function asyncForEach(
array: any[],
callback: (val: any, index: number, array: any[]) => Promise<void>,
) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}

@ -1,8 +1,10 @@
import AO3 from "../src/classes/AO3.ts"; import AO3 from "../src/classes/AO3.ts";
import workTest from "./work.ts"; import workTest from "./work.ts";
import chaptersTest from "./chapter.ts"; import chaptersTest from "./chapter.ts";
import searchTest from "./search.ts";
const ao3 = new AO3(); const ao3 = new AO3();
await workTest(ao3); await workTest(ao3);
await chaptersTest(ao3); await chaptersTest(ao3);
await searchTest(ao3);

@ -0,0 +1,35 @@
import AO3 from "../mod.ts";
import type { Search } from "../mod.ts";
import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts";
export default function test(ao3: AO3) {
Deno.test("searches", async (test) => {
await test.step("specific search", async () => {
const search = ao3.search({
freeform: [
"no beta we die like sammy",
"not at all your honor",
],
fandoms: ["Bendy and the Ink Machine"],
});
await search.update(0);
assert(search.results[0].id === "43251729", "incorrect work found");
});
await test.step("broad search", async () => {
const search = ao3.search({
freeform: [
"Smut",
],
});
await search.update(0);
assert(search.results.length > 10, "not enough search results");
await search.update(1);
assert(
search.results.length > 10,
"could not find second page of results",
);
});
});
}
Loading…
Cancel
Save