Added timeout for request
This commit is contained in:
		
							parent
							
								
									7b6644c646
								
							
						
					
					
						commit
						9c05502c83
					
				
							
								
								
									
										12
									
								
								src/utils.js
								
								
								
								
							
							
						
						
									
										12
									
								
								src/utils.js
								
								
								
								
							| 
						 | 
					@ -40,6 +40,7 @@ utils.loadConfig = function (file) {
 | 
				
			||||||
      cookie: '',
 | 
					      cookie: '',
 | 
				
			||||||
      lang: 'en',
 | 
					      lang: 'en',
 | 
				
			||||||
      delay: 3000,
 | 
					      delay: 3000,
 | 
				
			||||||
 | 
					      timeout: 5000,
 | 
				
			||||||
      output: 'guide.xml'
 | 
					      output: 'guide.xml'
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    config
 | 
					    config
 | 
				
			||||||
| 
						 | 
					@ -155,21 +156,13 @@ utils.parsePrograms = function ({ response, item, config }) {
 | 
				
			||||||
    content: response.data
 | 
					    content: response.data
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const programs = config
 | 
					  return config
 | 
				
			||||||
    .parser(options)
 | 
					    .parser(options)
 | 
				
			||||||
    .filter(i => i)
 | 
					    .filter(i => i)
 | 
				
			||||||
    .map(p => {
 | 
					    .map(p => {
 | 
				
			||||||
      p.channel = item.channel.xmltv_id
 | 
					      p.channel = item.channel.xmltv_id
 | 
				
			||||||
      return p
 | 
					      return p
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					 | 
				
			||||||
  console.log(
 | 
					 | 
				
			||||||
    `  ${config.site} - ${item.channel.xmltv_id} - ${item.date.format('MMM D, YYYY')} (${
 | 
					 | 
				
			||||||
      programs.length
 | 
					 | 
				
			||||||
    } programs)`
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return programs
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
utils.writeToFile = function (filename, data) {
 | 
					utils.writeToFile = function (filename, data) {
 | 
				
			||||||
| 
						 | 
					@ -187,6 +180,7 @@ utils.createHttpClient = function (config) {
 | 
				
			||||||
      'User-Agent': config.userAgent,
 | 
					      'User-Agent': config.userAgent,
 | 
				
			||||||
      Cookie: config.cookie
 | 
					      Cookie: config.cookie
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    timeout: config.timeout,
 | 
				
			||||||
    withCredentials: true,
 | 
					    withCredentials: true,
 | 
				
			||||||
    jar: new tough.CookieJar()
 | 
					    jar: new tough.CookieJar()
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue