Update login

This commit is contained in:
TPN 2024-07-16 07:55:31 +00:00
parent 1bc744d48d
commit 34b2fb74ae
3 changed files with 20 additions and 15 deletions

View file

@ -2,6 +2,6 @@ export const useAltEndpoint: boolean = false;
export const baseUrl = useAltEndpoint ? 'https://rips.cc' : 'https://ee3.me'; export const baseUrl = useAltEndpoint ? 'https://rips.cc' : 'https://ee3.me';
export const username = ''; export const username = '_sf_';
export const password = ''; export const password = 'defonotscraping';

View file

@ -24,3 +24,8 @@ export interface renewResponse {
msg?: string | null; msg?: string | null;
status: number | string | null; status: number | string | null;
} }
export interface loginResponse {
status: number;
message: string;
}

View file

@ -4,28 +4,28 @@ import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
import { parseSetCookie } from '@/utils/cookie'; import { parseSetCookie } from '@/utils/cookie';
import { baseUrl } from './common'; import { baseUrl } from './common';
import { loginResponse } from './types';
export async function login( export async function login(
user: string, user: string,
pass: string, pass: string,
ctx: ShowScrapeContext | MovieScrapeContext, ctx: ShowScrapeContext | MovieScrapeContext,
): Promise<string | null> { ): Promise<string | null> {
let req; const req = await ctx.proxiedFetcher.full<string>('/login', {
if (user && pass) baseUrl,
req = await ctx.proxiedFetcher.full<string>('/login', { method: 'POST',
baseUrl, body: new URLSearchParams({ user, pass, action: 'login' }),
method: 'POST', readHeaders: ['Set-Cookie'],
body: new URLSearchParams({ user, pass, action: 'login' }), });
readHeaders: ['Set-Cookie'], const res: loginResponse = JSON.parse(req.body);
});
const cookies = parseSetCookie( const cookie = parseSetCookie(
req?.headers.get('Set-Cookie') || // It retruns a cookie even when the login failed
// we don't wan't our creds to be in the code // I have the backup cookie here just in case
'PHPSESSID=phmje3cqeft42rckf8mj7illhc;', res.status === 1 ? (req.headers.get('Set-Cookie') ?? '') : 'PHPSESSID=mk2p73c77qc28o5i5120843ruu;',
); );
return cookies.PHPSESSID.value; return cookie.PHPSESSID.value;
} }
export function parseSearch(body: string): { title: string; year: number; id: string }[] { export function parseSearch(body: string): { title: string; year: number; id: string }[] {