2020-10-09 19:35:46 +02:00
|
|
|
import { _ } from 'lib/locale';
|
|
|
|
const InteropService_Exporter_Base = require('lib/services/interop/InteropService_Exporter_Base').default;
|
|
|
|
const InteropService_Exporter_Raw = require('lib/services/interop/InteropService_Exporter_Raw').default;
|
2018-02-26 21:25:54 +02:00
|
|
|
const fs = require('fs-extra');
|
2020-10-09 19:35:46 +02:00
|
|
|
const shim = require('lib/shim').default;
|
2018-02-26 21:25:54 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
export default class InteropService_Exporter_Jex extends InteropService_Exporter_Base {
|
|
|
|
async init(destPath:string) {
|
2019-09-19 23:51:18 +02:00
|
|
|
if (await shim.fsDriver().isDirectory(destPath)) throw new Error(`Path is a directory: ${destPath}`);
|
2018-02-26 21:25:54 +02:00
|
|
|
|
|
|
|
this.tempDir_ = await this.temporaryDirectory_(false);
|
|
|
|
this.destPath_ = destPath;
|
|
|
|
this.rawExporter_ = new InteropService_Exporter_Raw();
|
|
|
|
await this.rawExporter_.init(this.tempDir_);
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
async processItem(itemType:number, item:any) {
|
|
|
|
return this.rawExporter_.processItem(itemType, item);
|
2018-02-26 21:25:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
async processResource(resource:any, filePath:string) {
|
2018-02-26 21:25:54 +02:00
|
|
|
return this.rawExporter_.processResource(resource, filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
async close() {
|
|
|
|
const stats = await shim.fsDriver().readDirStats(this.tempDir_, { recursive: true });
|
2020-10-09 19:35:46 +02:00
|
|
|
const filePaths = stats.filter((a:any) => !a.isDirectory()).map((a:any) => a.path);
|
2018-02-26 21:25:54 +02:00
|
|
|
|
|
|
|
if (!filePaths.length) throw new Error(_('There is no data to export.'));
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
await require('tar').create(
|
|
|
|
{
|
|
|
|
strict: true,
|
|
|
|
portable: true,
|
|
|
|
file: this.destPath_,
|
|
|
|
cwd: this.tempDir_,
|
|
|
|
},
|
|
|
|
filePaths
|
|
|
|
);
|
2018-02-26 21:25:54 +02:00
|
|
|
|
|
|
|
await fs.remove(this.tempDir_);
|
|
|
|
}
|
|
|
|
}
|