ente/src/services/exportService.ts

30 lines
970 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();
const exportedFiles: Set<number> = await this.ElectronAPIs.getExportedFiles();
2021-03-29 11:29:19 +00:00
console.log(files);
2021-03-29 05:15:08 +00:00
for (let file of files) {
if (!exportedFiles.has(file.id)) {
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();