mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Cookies update
This commit is contained in:
53
play-dl/Request/index.ts
Normal file
53
play-dl/Request/index.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Response } from "./classes";
|
||||
|
||||
|
||||
export type Proxy = ProxyOpts | string;
|
||||
|
||||
interface ProxyOpts {
|
||||
host: string;
|
||||
port: number;
|
||||
authentication?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
body?: string;
|
||||
method: 'GET' | 'POST';
|
||||
proxies?: Proxy[];
|
||||
cookies? : boolean
|
||||
headers? : Object;
|
||||
timeout? : number
|
||||
}
|
||||
|
||||
interface StreamGetterOptions{
|
||||
method: 'GET' | 'POST';
|
||||
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()
|
||||
if (res.statusCode >= 300 && res.statusCode < 400) {
|
||||
res = await request_stream((res.headers as any).location, options);
|
||||
await res.stream()
|
||||
}
|
||||
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()
|
||||
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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user