Update index.js
This commit is contained in:
		
							parent
							
								
									63b2e7dd2d
								
							
						
					
					
						commit
						42434c40cd
					
				
							
								
								
									
										14
									
								
								src/index.js
								
								
								
								
							
							
						
						
									
										14
									
								
								src/index.js
								
								
								
								
							| 
						 | 
					@ -1,19 +1,14 @@
 | 
				
			||||||
const utils = require('./utils')
 | 
					const utils = require('./utils')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  grab: async function (channel, config, cb) {
 | 
					  grab: async function (channel, date, config, cb) {
 | 
				
			||||||
 | 
					    date = typeof date === 'string' ? utils.getUTCDate(date) : date
 | 
				
			||||||
    config = utils.loadConfig(config)
 | 
					    config = utils.loadConfig(config)
 | 
				
			||||||
    channel.lang = channel.lang || config.lang || null
 | 
					    channel.lang = channel.lang || config.lang || null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const utcDate = utils.getUTCDate()
 | 
					 | 
				
			||||||
    const dates = Array.from({ length: config.days }, (_, i) => utcDate.add(i, 'd'))
 | 
					 | 
				
			||||||
    const queue = []
 | 
					 | 
				
			||||||
    dates.forEach(date => {
 | 
					 | 
				
			||||||
      queue.push({ date, channel })
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let programs = []
 | 
					    let programs = []
 | 
				
			||||||
    for (let item of queue) {
 | 
					
 | 
				
			||||||
 | 
					    const item = { date, channel }
 | 
				
			||||||
    await utils
 | 
					    await utils
 | 
				
			||||||
      .buildRequest(item, config)
 | 
					      .buildRequest(item, config)
 | 
				
			||||||
      .then(request => utils.fetchData(request))
 | 
					      .then(request => utils.fetchData(request))
 | 
				
			||||||
| 
						 | 
					@ -29,7 +24,6 @@ module.exports = {
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await utils.sleep(config.delay)
 | 
					    await utils.sleep(config.delay)
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return programs
 | 
					    return programs
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue