add auth
ci/woodpecker/push/woodpecker Pipeline failed Details

okay so apparently you can't just access mature works by setting `&mature=1` like i thought
cue literally hours of me banging my head against what i thought was api issues, only to discover that:
THE URL WAS BROKEN WHEN I PASSED IN ONLY A PATH
??????
i just gave up and made you pass in an entire URL, considering it's an internal only API i don't really give that much of a shit for now
pull/1/head
Drake 1 year ago
parent 0129c9fda1
commit cd53fa4257

3
.gitignore vendored

@ -1 +1,2 @@
wattpad-app*
wattpad-app*
test.ts

@ -102,6 +102,10 @@
"https://deno.land/x/another_cookiejar@v5.0.1/cookie_jar.ts": "e47d7b2c608bcd9600fd26825b600946f16ae167216cea71935049188d2fc6d1",
"https://deno.land/x/another_cookiejar@v5.0.1/fetch_wrapper.ts": "4fbca1e77383cf7da4703798e06a1129b21120f4d01c3a4c0801674dd7b6d53b",
"https://deno.land/x/another_cookiejar@v5.0.1/mod.ts": "eff949014965771f2cd447fe78625a1ad28b59333afa40640f02c0922534d89a",
"https://deno.land/x/another_cookiejar@v5.0.2/cookie.ts": "2be7548d01a3a9df97deb187761a843a77fd824057478919abf1e1e89ae1eb2e",
"https://deno.land/x/another_cookiejar@v5.0.2/cookie_jar.ts": "e47d7b2c608bcd9600fd26825b600946f16ae167216cea71935049188d2fc6d1",
"https://deno.land/x/another_cookiejar@v5.0.2/fetch_wrapper.ts": "4fbca1e77383cf7da4703798e06a1129b21120f4d01c3a4c0801674dd7b6d53b",
"https://deno.land/x/another_cookiejar@v5.0.2/mod.ts": "eff949014965771f2cd447fe78625a1ad28b59333afa40640f02c0922534d89a",
"https://deno.land/x/axiod@0.26.2/helpers.ts": "467f2ca75608f368c8092e800eab0d6d79b3fa42346372be62a5b93acf50fe7e",
"https://deno.land/x/axiod@0.26.2/interfaces.ts": "1b5a7b70b1e7faecd2f251ad080bd87188fba585e2de667af472c4d72abf636e",
"https://deno.land/x/axiod@0.26.2/mod.ts": "1175ec90a040d764b9940753f8d8e3f37a2328a0536eed48e411a8f1a3e9e5cb",

@ -20,6 +20,24 @@ export default class Wattpad {
this.session = newSession(opts ?? {});
}
async authenticate(username: string, password: string) {
await this.session.post("https://www.wattpad.com/login", {
"credentials": "include",
"headers": {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; rv:108.0) Gecko/20100101 Firefox/108.0",
"Content-Type": "application/x-www-form-urlencoded",
},
"referrer": "https://www.wattpad.com/login",
"body": new URLSearchParams({
username,
password,
}),
"method": "POST",
"mode": "cors",
});
}
/**
* gets a Story from an ID
* @returns {Promise<Story>} a Story class for the story

@ -1,3 +1,11 @@
import {
CookieJar,
wrapFetch,
} from "https://deno.land/x/another_cookiejar@v5.0.2/mod.ts";
const cookieJar = new CookieJar();
const cookieFetch = wrapFetch({ cookieJar });
export interface Options {
url?: string;
apiUrl?: string;
@ -20,7 +28,7 @@ const newSession = (opts: Options) => {
get: async (path: string, useAPI = false, opts2?: {
params?: URLSearchParams;
}) => {
const res = await fetch(
const res = await cookieFetch(
(useAPI ? opts.apiUrl : opts.url) + path + "?" +
opts2?.params ?? "",
{
@ -33,6 +41,17 @@ const newSession = (opts: Options) => {
}
return res;
},
post: async (url: string, opts2: RequestInit) => {
const res = await cookieFetch(
url,
opts2,
);
if (res.status > 300) {
console.log(res);
throw new Error("Failed request, probably rate-limited");
}
return res;
},
};
};

Loading…
Cancel
Save