search validation added

This commit is contained in:
killer069
2021-10-09 16:18:05 +05:30
parent 1ba762d10c
commit 6698a87983
11 changed files with 199 additions and 187 deletions

View File

@@ -1,5 +1,4 @@
import { Response } from "./classes";
import { Response } from './classes';
export type Proxy = ProxyOpts | string;
@@ -16,38 +15,38 @@ interface RequestOptions {
body?: string;
method: 'GET' | 'POST';
proxies?: Proxy[];
cookies? : boolean
headers? : Object;
timeout? : number
cookies?: boolean;
headers?: Object;
timeout?: number;
}
interface StreamGetterOptions{
interface StreamGetterOptions {
method: 'GET' | 'POST';
cookies? : boolean
headers : Object;
cookies?: boolean;
headers: Object;
}
export function request_stream(req_url : string, options : RequestOptions = {method : "GET"}): Promise<Response>{
return new Promise(async(resolve, reject) => {
let res = new Response(req_url, options)
await res.stream()
export function request_stream(req_url: string, options: RequestOptions = { method: 'GET' }): Promise<Response> {
return new Promise(async (resolve, reject) => {
let res = new Response(req_url, options);
await res.stream();
if (res.statusCode >= 300 && res.statusCode < 400) {
res = await request_stream((res.headers as any).location, options);
await res.stream()
await res.stream();
}
resolve(res)
})
resolve(res);
});
}
export function request(req_url : string, options : RequestOptions = {method : "GET"}): Promise<Response>{
return new Promise(async(resolve, reject) => {
let res = new Response(req_url, options)
await res.fetch()
export function request(req_url: string, options: RequestOptions = { method: 'GET' }): Promise<Response> {
return new Promise(async (resolve, reject) => {
let res = new Response(req_url, options);
await res.fetch();
if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) {
res = await request((res.headers as any).location, options);
} else if (Number(res.statusCode) > 400) {
reject(new Error(`Got ${res.statusCode} from the request`));
}
resolve(res)
})
}
resolve(res);
});
}