pull/1/head
Drake 1 year ago
parent d0bc34275d
commit 4aac4e9be8

@ -0,0 +1,17 @@
import Wattpad from "../mod.ts";
const wp = new Wattpad();
const search = wp.search({
query: "bendy x reader",
});
await search.update(0);
await search.results[0].init();
console.log(search.results[0].name);
/*await search.results[0].chapters[0].init();
console.log(search.results[0].chapters[0].text);*/

@ -1,8 +1,7 @@
import { Part as PartType } from "../types.d.ts";
import { newSession } from "../utils/http.ts";
import { Part as PartType, Session } from "../types.d.ts";
export default class Chapter {
#session: ReturnType<typeof newSession>;
#session: Session;
id: string;
workID: string;
/**
@ -25,7 +24,7 @@ export default class Chapter {
constructor(
workId: string,
part: PartType,
session: ReturnType<typeof newSession>,
session: Session,
) {
this.#session = session;
this.workID = workId;

@ -1,5 +1,4 @@
import { SearchResults } from "../types.d.ts";
import { newSession } from "../utils/http.ts";
import { SearchResults, Session } from "../types.d.ts";
import Work from "./Story.ts";
export interface SearchParameters {
@ -20,12 +19,12 @@ export default class Search {
isTitle: false,
limit: 30,
};
#session: ReturnType<typeof newSession>;
#session: Session;
results: Work[] = [];
constructor(
opts: SearchParameters,
session: ReturnType<typeof newSession>,
session: Session,
) {
this.#session = session;
Object.assign(this.#opts, opts);

@ -1,9 +1,8 @@
import Chapter from "./Chapter.ts";
import { ID, StoryJSON } from "../types.d.ts";
import { newSession } from "../utils/http.ts";
import { Session, StoryJSON } from "../types.d.ts";
export default class Story {
#session: ReturnType<typeof newSession>;
#session: Session;
/**
* ID of the work
*/
@ -40,11 +39,11 @@ export default class Story {
* @param session an axiod session (used for fetching additional details)
*/
constructor(
id: ID,
session: ReturnType<typeof newSession>,
id: string,
session: Session,
) {
this.#session = session;
this.id = id.toString();
this.id = id;
}
async init() {

@ -1,5 +1,4 @@
import { SearchResults } from "../types.d.ts";
import { newSession } from "../utils/http.ts";
import { SearchResults, Session } from "../types.d.ts";
import Work from "./Story.ts";
export interface SearchParameters {
@ -17,12 +16,12 @@ export default class Search {
tags: [],
limit: 20,
};
#session: ReturnType<typeof newSession>;
#session: Session;
results: Work[] = [];
constructor(
opts: SearchParameters,
session: ReturnType<typeof newSession>,
session: Session,
) {
this.#session = session;
Object.assign(this.#opts, opts);

@ -1,13 +1,11 @@
import Work from "./Story.ts";
import { ID } from "../types.d.ts";
import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.36-alpha/deno-dom-wasm.ts";
import Search, { SearchParameters as QuerySearchParams } from "./Search.ts";
import TagSearch, { SearchParameters as TagSearchParams } from "./TagSearch.ts";
import { newSession, Options } from "../utils/http.ts";
import { Session } from "../types.d.ts";
export default class Wattpad {
session: ReturnType<typeof newSession>;
DOMParser = new DOMParser();
session: Session;
/**
* a representation of Wattpad in class form
@ -26,7 +24,7 @@ export default class Wattpad {
* gets a Story from an ID
* @returns {Promise<Work>} a Work class for the work
*/
async getWork(id: ID): Promise<Work> {
async getWork(id: string): Promise<Work> {
return new Work(id, this.session);
}

13
src/types.d.ts vendored

@ -1,13 +1,6 @@
export type ID = BigInt | number | string;
export type {
DOMParser,
} from "https://deno.land/x/deno_dom@v0.1.36-alpha/src/dom/dom-parser.ts";
export type {
Element,
} from "https://deno.land/x/deno_dom@v0.1.36-alpha/src/dom/element.ts";
export type {
HTMLDocument,
} from "https://deno.land/x/deno_dom@v0.1.36-alpha/src/dom/document.ts";
import { newSession } from "./utils/http.ts";
export type Session = ReturnType<typeof newSession>;
export interface StoryJSON {
id: string;

@ -1,15 +1,3 @@
// custom fetch wrappers.. for reasons
import {
CookieJar,
wrapFetch,
} from "https://deno.land/x/another_cookiejar@v5.0.1/mod.ts";
const cookieJar = new CookieJar();
const wrappedFetch = wrapFetch({
cookieJar,
});
export interface Options {
url?: string;
apiUrl?: string;
@ -32,7 +20,7 @@ const newSession = (opts: Options) => {
get: async (path: string, useAPI = false, opts2?: {
params?: URLSearchParams;
}) => {
const res = await wrappedFetch(
const res = await fetch(
(useAPI ? opts.apiUrl : opts.url) + path + "?" +
opts2?.params ?? "",
{

Loading…
Cancel
Save