mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Merge branch 'main' into misc-improvements
This commit is contained in:
@@ -8,7 +8,7 @@ export type ProxyOptions = ProxyOpts | string;
|
||||
|
||||
interface RequestOpts extends RequestOptions {
|
||||
body?: string;
|
||||
method?: 'GET' | 'POST';
|
||||
method?: 'GET' | 'POST' | 'HEAD';
|
||||
proxies?: ProxyOptions[];
|
||||
cookies?: boolean;
|
||||
}
|
||||
@@ -119,6 +119,23 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
|
||||
});
|
||||
}
|
||||
|
||||
export function request_resolve_redirect(url: string): Promise<string> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let res = await https_getter(url, { method: 'HEAD' }).catch((err: Error) => err);
|
||||
if (res instanceof Error) {
|
||||
reject(res);
|
||||
return;
|
||||
}
|
||||
const statusCode = Number(res.statusCode);
|
||||
if (statusCode >= 300 && statusCode < 400) {
|
||||
const resolved = await request_resolve_redirect(res.headers.location as string);
|
||||
resolve(resolved);
|
||||
} else {
|
||||
resolve(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses one random number between max and min number.
|
||||
* @param min Minimum number
|
||||
|
||||
Reference in New Issue
Block a user