WOOOOOOOO YEAH BABYYYYYYYYYYYYYY
ci/woodpecker/pr/woodpecker Pipeline was successful Details

pull/1/head
Tymon 1 year ago
parent f6ef83f4c3
commit c08205cf7a

@ -28,6 +28,8 @@ await build({
}, { }, {
name: "RequestInfo", name: "RequestInfo",
typeOnly: true, typeOnly: true,
}, {
name: "Response",
}], }],
}], }],
}, },

@ -33,6 +33,7 @@ export default class Wattpad {
password, password,
}), }),
"method": "POST", "method": "POST",
redirect: "manual",
}); });
} }

@ -12,11 +12,10 @@ export interface Options {
const cookies: Cookie[] = []; const cookies: Cookie[] = [];
function isRedirect(status: number) { async function cookieFetch(
return [301, 302, 303, 307, 308].includes(status); input: RequestInfo,
} init?: RequestInit,
): Promise<Response> {
async function cookieFetch(input: RequestInfo, init?: RequestInit) {
const headers = new Headers((input as Request).headers || {}); const headers = new Headers((input as Request).headers || {});
if (init?.headers) { if (init?.headers) {
@ -41,7 +40,7 @@ async function cookieFetch(input: RequestInfo, init?: RequestInit) {
if (setCookies) { if (setCookies) {
for (let i = 0; i < setCookies.length; i++) { for (let i = 0; i < setCookies.length; i++) {
const setCookie = setCookies[i]; const setCookie = setCookies[i];
// FIXME: this dupe protection is bad out of 10
if (!cookies.find((cookie) => cookie.name === setCookie.name)) { if (!cookies.find((cookie) => cookie.name === setCookie.name)) {
cookies.push(setCookie); cookies.push(setCookie);
} }
@ -79,7 +78,7 @@ const newSession = (opts: Options) => {
headers: opts.headers, headers: opts.headers,
}); });
if (res.status > 300) { if (res.status > 302) {
console.log(url); console.log(url);
console.log(await res.json()); console.log(await res.json());
throw new Error("Failed request, probably rate-limited"); throw new Error("Failed request, probably rate-limited");
@ -93,7 +92,7 @@ const newSession = (opts: Options) => {
url, url,
opts2, opts2,
); );
if (res.status > 300) { if (res.status > 302) {
console.log(res); console.log(res);
throw new Error("Failed request, probably rate-limited"); throw new Error("Failed request, probably rate-limited");
} }

Loading…
Cancel
Save