optimize some code

This commit is contained in:
killer069 2021-09-14 22:11:02 +05:30
parent 9ed0048792
commit 9a777e30ff
2 changed files with 3 additions and 4 deletions

View File

@ -11,10 +11,9 @@ enum SearchType {
Channel = 'EgIQAg%253D%253D',
}
export async function search(search :string, options? : ParseSearchInterface): Promise<(Video | Channel | PlayList)[]> {
export async function search(search :string, options : ParseSearchInterface = {}): Promise<(Video | Channel | PlayList)[]> {
let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+')
if(!options) options = { type : "video"}
if(!options.type) options.type = "video"
options.type ??= "video"
if(!url.match('&sp=')){
url += '&sp='
switch(options?.type){

View File

@ -7,7 +7,7 @@ interface RequestOpts extends RequestOptions{
method? : "GET" | "POST"
}
async function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
return new Promise((resolve, reject) => {
let s = new URL(req_url)
options.method ??= "GET"