UNPKG

@mieweb/wikigdrive

Version:

Google Drive to MarkDown synchronization

54 lines (53 loc) 1.84 kB
import { QueueTask } from './QueueTask.js'; import { BufferWritable } from '../../utils/BufferWritable.js'; export class TaskFetchDocument extends QueueTask { constructor(logger, googleDriveService, auth, fileService, file, forceDownload) { super(logger); Object.defineProperty(this, "logger", { enumerable: true, configurable: true, writable: true, value: logger }); Object.defineProperty(this, "googleDriveService", { enumerable: true, configurable: true, writable: true, value: googleDriveService }); Object.defineProperty(this, "auth", { enumerable: true, configurable: true, writable: true, value: auth }); Object.defineProperty(this, "fileService", { enumerable: true, configurable: true, writable: true, value: fileService }); Object.defineProperty(this, "file", { enumerable: true, configurable: true, writable: true, value: file }); Object.defineProperty(this, "forceDownload", { enumerable: true, configurable: true, writable: true, value: forceDownload }); } async run() { const odtPath = this.file.id + '.odt'; if (await this.fileService.exists(odtPath) && !this.forceDownload) { return []; } const destOdt = new BufferWritable(); await this.googleDriveService.exportDocument(this.auth, { ...this.file, mimeType: 'application/vnd.oasis.opendocument.text' }, destOdt); await this.fileService.writeBuffer(odtPath, destOdt.getBuffer()); return []; } }