噩梦不用等待下载

时间:2019-08-02 00:53:49

标签: javascript typescript nightmare

我正在尝试使用噩梦下载一些代码 但是代码不会等待,也不会下载文件

async function ProblemDownload(Name, Categ, Lang, ProblemLink){
    //console.log(ProblemLink);
    await nightmare.on('download', async (state, downloadItem) => {
        if(state == 'started'){
            await nightmare
            .emit('download', '.\\CODES\\'+CATEG_WHERE[Categ]+'\\'+Name+LANGUAGES_EXTEND[Lang], downloadItem)
            .then((data) =>{
                console.log(data)
            })
            .catch( () => {})
            //'+CATEG_WHERE[Categ]+'\\'+Name+LANGUAGES_EXTEND[Lang]
        }
        else if(state == 'completed'){
            console.log(downloadItem);
        }
    })
    .catch()
    return await nightmare
    .downloadManager()
    .goto(ProblemLink)
    .waitDownloadsComplete()
    .then(() =>{
        console.log('nome: ', Name)
    })
    .catch(() => {});
}


这是我在运行代码时得到的反馈,该代码始终在下载代码,而不下载预期的其他两个代码。

1001 - Extremely Basic
undefined
1002 - Area of a Circle
{ filename: 'UOJ_1001 - (4983634) Accepted.cpp',
  mimetype: 'text/html',
  receivedBytes: 155,
  totalBytes: 0,
  url:
   'https://www.urionlinejudge.com.br/judge/en/runs/dropbox/4983634/5b86f9ac95f5eba26cd433661534e739',
  path: '.\\CODES\\BEGINNER\\1001 - Extremely Basic.cpp' }
{ filename: 'UOJ_1001 - (4983634) Accepted.cpp',
  mimetype: 'text/html',
  receivedBytes: 155,
  totalBytes: 0,
  url:
   'https://www.urionlinejudge.com.br/judge/en/runs/dropbox/4983634/5b86f9ac95f5eba26cd433661534e739',
  path: '.\\CODES\\BEGINNER\\1001 - Extremely Basic.cpp',
  state: 'completed' }
undefined
undefined
1003 - Simple Sum
{ filename: 'UOJ_1002 - (5032554) Accepted.cpp',
  mimetype: 'text/html',
  receivedBytes: 198,
  totalBytes: 0,
  url:
   'https://www.urionlinejudge.com.br/judge/en/runs/dropbox/5032554/cfcb72e4ff1a8c0f7ca02758e3141514',
  path: '.\\CODES\\BEGINNER\\1001 - Extremely Basic.cpp' }
{ filename: 'UOJ_1002 - (5032554) Accepted.cpp',
  mimetype: 'text/html',
  receivedBytes: 198,
  totalBytes: 0,
  url:
   'https://www.urionlinejudge.com.br/judge/en/runs/dropbox/5032554/cfcb72e4ff1a8c0f7ca02758e3141514',
  path: '.\\CODES\\BEGINNER\\1001 - Extremely Basic.cpp',
  state: 'completed' }
{ filename: 'UOJ_1002 - (5032554) Accepted.cpp',
  mimetype: 'text/html',
  receivedBytes: 198,
  totalBytes: 0,
  url:
   'https://www.urionlinejudge.com.br/judge/en/runs/dropbox/5032554/cfcb72e4ff1a8c0f7ca02758e3141514',
  path: '.\\CODES\\BEGINNER\\1001 - Extremely Basic.cpp',
  state: 'completed' }
undefined
undefined
undefined

有人可以帮我解释一下我如何让《噩梦》在每次下载前都等待下载。

0 个答案:

没有答案