ente/src/services/exportService.ts

24 lines
760 B
TypeScript
Raw Normal View History

2021-03-29 05:15:08 +00:00
import { runningInBrowser } from 'utils/common/utilFunctions';
import downloadManager from './downloadManager';
import { file } from './fileService';
class ExportService {
ElectronAPIs: any = runningInBrowser() && window['ElectronAPIs'];
2021-03-29 11:29:19 +00:00
async exportFiles(files: file[]) {
2021-03-29 05:15:08 +00:00
const dir = await this.ElectronAPIs.selectDirectory();
2021-03-29 11:29:19 +00:00
console.log(files);
2021-03-29 05:15:08 +00:00
for (let file of files) {
2021-03-29 11:29:19 +00:00
await this.downloadAndSave(file, `${dir}/${file.metadata.title}`);
2021-03-29 05:15:08 +00:00
}
}
2021-03-29 11:29:19 +00:00
async downloadAndSave(file: file, path) {
console.log(this.ElectronAPIs);
const fileStream = await downloadManager.downloadFile(file);
this.ElectronAPIs.saveToDisk(path, fileStream);
}
2021-03-29 05:15:08 +00:00
}
export default new ExportService();