(fileName, targetDirectory)
| 1704 | } |
| 1705 | |
| 1706 | async downloadFile(fileName, targetDirectory) { |
| 1707 | const caps = await this.getCapabilities() |
| 1708 | if (!caps['map_'].get('se:downloadsEnabled')) { |
| 1709 | throw new Error('Downloads must be enabled in options') |
| 1710 | } |
| 1711 | |
| 1712 | const response = await this.execute(new command.Command(command.Name.DOWNLOAD_FILE).setParameter('name', fileName)) |
| 1713 | |
| 1714 | const base64Content = response.contents |
| 1715 | |
| 1716 | if (!targetDirectory.endsWith('/')) { |
| 1717 | targetDirectory += '/' |
| 1718 | } |
| 1719 | |
| 1720 | fs.mkdirSync(targetDirectory, { recursive: true }) |
| 1721 | const zipFilePath = path.join(targetDirectory, `${fileName}.zip`) |
| 1722 | fs.writeFileSync(zipFilePath, Buffer.from(base64Content, 'base64')) |
| 1723 | |
| 1724 | const zipData = fs.readFileSync(zipFilePath) |
| 1725 | await JSZip.loadAsync(zipData) |
| 1726 | .then((zip) => { |
| 1727 | // Iterate through each file in the zip archive |
| 1728 | Object.keys(zip.files).forEach(async (fileName) => { |
| 1729 | const fileData = await zip.files[fileName].async('nodebuffer') |
| 1730 | fs.writeFileSync(`${targetDirectory}/${fileName}`, fileData) |
| 1731 | console.log(`File extracted: ${fileName}`) |
| 1732 | }) |
| 1733 | }) |
| 1734 | .catch((error) => { |
| 1735 | console.error('Error unzipping file:', error) |
| 1736 | }) |
| 1737 | } |
| 1738 | |
| 1739 | async deleteDownloadableFiles() { |
| 1740 | const caps = await this.getCapabilities() |
nothing calls this directly
no test coverage detected