@jrmc/adonis-attachment
Version:
Turn any field on your Lucid model to an attachment data type
37 lines (36 loc) • 1.13 kB
JavaScript
/**
* @jrmc/adonis-attachment
*
* @license MIT
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
*/
import { bufferToTempFile } from '../utils/helpers.js';
import Converter from './converter.js';
import ImageConverter from './image_converter.js';
import Soffice from '../adapters/soffice.js';
export default class DocumentThumbnailConverter extends Converter {
async handle({ input, options }) {
const filePath = await this.documentToImage(input);
if (options && filePath) {
const converter = new ImageConverter();
return await converter.handle({
input: filePath,
options,
});
}
return filePath;
}
async documentToImage(input) {
let file = input;
if (Buffer.isBuffer(input)) {
file = await bufferToTempFile(input);
}
const soffice = new Soffice(file);
if (this.binPaths) {
if (this.binPaths.sofficePath) {
soffice.setSofficePath(this.binPaths.sofficePath);
}
}
return soffice.convert();
}
}