@mieweb/wikigdrive
Version:
Google Drive to MarkDown synchronization
61 lines (59 loc) • 2.41 kB
JavaScript
import { QueueTask } from './QueueTask.js';
export class TaskFetchDiagram 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 targetPathSvg = this.file.id + '.svg';
const targetPathPng = this.file.id + '.png';
if (await this.fileService.exists(targetPathPng) && await this.fileService.exists(targetPathSvg) && !this.forceDownload) {
return [];
}
this.logger.info('Downloading diagram: ' + this.file.name);
const writeStream = this.fileService.createWriteStream(targetPathSvg);
await this.googleDriveService.exportDocument(this.auth, Object.assign({}, this.file, { mimeType: 'image/svg+xml' }), writeStream);
const writeStreamPng = this.fileService.createWriteStream(targetPathPng);
await this.googleDriveService.exportDocument(this.auth, Object.assign({}, this.file, { mimeType: 'image/png' }), writeStreamPng);
/* const md5Checksum = await this.fileService.md5File(targetPathPng);
console.log('md5Checksum', md5Checksum);
const image = await getImageMeta(await this.fileService.readBuffer(targetPathPng));
console.log('image', image);*/
return [];
}
}