等待HTTP请求完成,然后继续在Node.js中循环

时间:2020-02-22 14:37:45

标签: node.js

我不知道该怎么做。我开始学习javascript。 有谁能够帮助我?这是我的代码:

let url = "https://drive.google.com/uc?export=download&id=driveid";
   while(true) {
      let check = false;
      console.log(url);
      const request = https.get(url, (response) => {
         if(typeof response.headers['Content-Disposition'] !== "undefined") {
            const file = fs.createWriteStream("a3.mp4");
            response.on('data', (chunk) => {
               file.write(chunk);
            }).on('end', async () => {
               file.end();
               check = true;
            })
         } else {
            let str = "";
            response.on('data', (chunk) => {
               str += chunk;
            }).on('end', () => {
               url = get_confirm_download_url(str);
               if(!url) {
                  console.log("Can\"t find download link");
                  check = true;
               }
            })
         }
      });
      if(check) break;
   }

我真的需要你的帮助

1 个答案:

答案 0 :(得分:0)

我不确定我在这里是否正确,但是我已经对您的代码进行了一些假设。试试这个:

playerList