2018-02-26 21:25:54 +02:00
|
|
|
const InteropService_Importer_Base = require('lib/services/InteropService_Importer_Base');
|
|
|
|
const InteropService_Importer_Raw = require('lib/services/InteropService_Importer_Raw');
|
2019-07-29 15:58:33 +02:00
|
|
|
const { filename } = require('lib/path-utils.js');
|
2018-02-26 21:25:54 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
class InteropService_Importer_Jex extends InteropService_Importer_Base {
|
|
|
|
async exec(result) {
|
|
|
|
const tempDir = await this.temporaryDirectory_(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await require('tar').extract({
|
|
|
|
strict: true,
|
|
|
|
portable: true,
|
|
|
|
file: this.sourcePath_,
|
|
|
|
cwd: tempDir,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const msg = [`Cannot untar file ${this.sourcePath_}`, error.message];
|
2018-02-26 21:25:54 +02:00
|
|
|
if (error.data) msg.push(JSON.stringify(error.data));
|
2020-03-14 01:46:14 +02:00
|
|
|
const e = new Error(msg.join(': '));
|
2018-02-26 21:25:54 +02:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2018-03-01 20:35:17 +02:00
|
|
|
if (!('defaultFolderTitle' in this.options_)) this.options_.defaultFolderTitle = filename(this.sourcePath_);
|
|
|
|
|
2018-02-26 21:25:54 +02:00
|
|
|
const importer = new InteropService_Importer_Raw();
|
|
|
|
await importer.init(tempDir, this.options_);
|
|
|
|
result = await importer.exec(result);
|
|
|
|
|
|
|
|
await fs.remove(tempDir);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = InteropService_Importer_Jex;
|