tattle-made / whatsapp-scraper

2 stars 2 forks source link

getZipFileNames returns undefined #4

Closed surajsharma closed 4 years ago

surajsharma commented 4 years ago

in the following code, getZipFileNames returns undefined even though the preceding line logs a value:


function getZipFileNames(drive) {
  drive.files.list(
    {
      pageSize: 10,
      fields: "nextPageToken, files(id, name)",
    },
    (err, res) => {
      if (err) return console.log("The API returned an error: " + err);

      const files = res.data.files;
      const pageToken = null,
        folderId = null;

      if (files.length) {
        console.log("Files:");
        let zipFileNames = [];
        files.map((file) => {
          if (file.name.includes(".zip")) {
            console.log(file.name);
            zipFileNames = zipFileNames.concat(file.name);
          }
        });

        console.log(">>>", zipFileNames);
        return zipFileNames;
      }
    }
  );
}

function listFiles(auth) {
  const drive = google.drive({ version: "v3", auth });
  const fileId = "1_tCKjPYcjIfnloGiF318bbwUl7yI7u6U";
  var dest = fs.createWriteStream("/tmp/whatsapp_dump.zip");

  let zipFileNames = getZipFileNames(drive);

  drive.files
    .get({
      fileId: fileId,
      alt: "media",
    })
    .then((res) => {
      console.log(">", zipFileNames);
    });
}

to reproduce, clone my fork of the repo, npm i in src/scraper and then node .

dennyabrain commented 4 years ago

Fixed here - https://github.com/surajsharma/whatsapp-scraper/commit/46be6273ef1fbb40b0d1620c665429f70a90f376