@mieweb/wikigdrive
Version:
Google Drive to MarkDown synchronization
57 lines (56 loc) • 2.5 kB
JavaScript
import { TransformContainer } from '../transform/TransformContainer.js';
import { UserConfigService } from '../google_folder/UserConfigService.js';
import { getContentFileService } from '../transform/utils.js';
import { MarkdownTreeProcessor } from '../transform/MarkdownTreeProcessor.js';
import { clearCachedChanges } from '../job/JobManagerContainer.js';
export class ActionTransform {
constructor(engine, googleFileSystem, transformedFileSystem) {
Object.defineProperty(this, "engine", {
enumerable: true,
configurable: true,
writable: true,
value: engine
});
Object.defineProperty(this, "googleFileSystem", {
enumerable: true,
configurable: true,
writable: true,
value: googleFileSystem
});
Object.defineProperty(this, "transformedFileSystem", {
enumerable: true,
configurable: true,
writable: true,
value: transformedFileSystem
});
}
async execute(folderId, jobId, filesIds = []) {
const transformContainer = new TransformContainer({
folderId,
name: jobId,
jobId
}, { filesIds });
await transformContainer.mount2(this.googleFileSystem, this.transformedFileSystem);
const userConfigService = new UserConfigService(this.googleFileSystem);
await userConfigService.load();
transformContainer.setUseGoogleMarkdowns(userConfigService.config.use_google_markdowns);
const jobManager = this.engine.getContainer('job_manager');
transformContainer.onProgressNotify(({ completed, total, warnings, failed }) => {
jobManager.progressJob(folderId, jobId, { completed, total, warnings, failed });
});
await this.engine.registerContainer(transformContainer);
try {
await transformContainer.run(folderId);
if (transformContainer.failed()) {
throw new Error('Transform failed');
}
const contentFileService = await getContentFileService(this.transformedFileSystem, userConfigService);
const markdownTreeProcessor = new MarkdownTreeProcessor(contentFileService);
await markdownTreeProcessor.load();
}
finally {
await this.engine.unregisterContainer(transformContainer.params.name);
}
await clearCachedChanges(this.googleFileSystem);
}
}