(fileName, targetDirectory)
| 1749 | } |
| 1750 | |
| 1751 | async downloadFile(fileName, targetDirectory) { |
| 1752 | const caps = await this.getCapabilities() |
| 1753 | if (!caps['map_'].get('se:downloadsEnabled')) { |
| 1754 | throw new Error('Downloads must be enabled in options') |
| 1755 | } |
| 1756 | |
| 1757 | const response = await this.execute(new command.Command(command.Name.DOWNLOAD_FILE).setParameter('name', fileName)) |
| 1758 | |
| 1759 | const base64Content = response.contents |
| 1760 | |
| 1761 | if (!targetDirectory.endsWith('/')) { |
| 1762 | targetDirectory += '/' |
| 1763 | } |
| 1764 | |
| 1765 | fs.mkdirSync(targetDirectory, { recursive: true }) |
| 1766 | const zipFilePath = path.join(targetDirectory, `${fileName}.zip`) |
| 1767 | fs.writeFileSync(zipFilePath, Buffer.from(base64Content, 'base64')) |
| 1768 | |
| 1769 | const zipData = fs.readFileSync(zipFilePath) |
| 1770 | await JSZip.loadAsync(zipData) |
| 1771 | .then((zip) => { |
| 1772 | // Iterate through each file in the zip archive |
| 1773 | Object.keys(zip.files).forEach(async (fileName) => { |
| 1774 | const fileData = await zip.files[fileName].async('nodebuffer') |
| 1775 | fs.writeFileSync(`${targetDirectory}/${fileName}`, fileData) |
| 1776 | console.log(`File extracted: ${fileName}`) |
| 1777 | }) |
| 1778 | }) |
| 1779 | .catch((error) => { |
| 1780 | console.error('Error unzipping file:', error) |
| 1781 | }) |
| 1782 | } |
| 1783 | |
| 1784 | async deleteDownloadableFiles() { |
| 1785 | const caps = await this.getCapabilities() |
nothing calls this directly
no test coverage detected