diff --git a/buildNode.ts b/buildNode.ts index 19c83df..4e6379e 100644 --- a/buildNode.ts +++ b/buildNode.ts @@ -28,6 +28,8 @@ await build({ }, { name: "RequestInfo", typeOnly: true, + }, { + name: "Response", }], }], }, diff --git a/src/classes/Wattpad.ts b/src/classes/Wattpad.ts index 1c24d59..b739d90 100644 --- a/src/classes/Wattpad.ts +++ b/src/classes/Wattpad.ts @@ -33,6 +33,7 @@ export default class Wattpad { password, }), "method": "POST", + redirect: "manual", }); } diff --git a/src/utils/http.ts b/src/utils/http.ts index 8b0761b..95ddc4e 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -12,11 +12,10 @@ export interface Options { const cookies: Cookie[] = []; -function isRedirect(status: number) { - return [301, 302, 303, 307, 308].includes(status); -} - -async function cookieFetch(input: RequestInfo, init?: RequestInit) { +async function cookieFetch( + input: RequestInfo, + init?: RequestInit, +): Promise { const headers = new Headers((input as Request).headers || {}); if (init?.headers) { @@ -41,7 +40,7 @@ async function cookieFetch(input: RequestInfo, init?: RequestInit) { if (setCookies) { for (let i = 0; i < setCookies.length; i++) { const setCookie = setCookies[i]; - // FIXME: this dupe protection is bad out of 10 + if (!cookies.find((cookie) => cookie.name === setCookie.name)) { cookies.push(setCookie); } @@ -79,7 +78,7 @@ const newSession = (opts: Options) => { headers: opts.headers, }); - if (res.status > 300) { + if (res.status > 302) { console.log(url); console.log(await res.json()); throw new Error("Failed request, probably rate-limited"); @@ -93,7 +92,7 @@ const newSession = (opts: Options) => { url, opts2, ); - if (res.status > 300) { + if (res.status > 302) { console.log(res); throw new Error("Failed request, probably rate-limited"); }