UNPKG

@jrmc/adonis-attachment

Version:

Turn any field on your Lucid model to an attachment data type

41 lines (40 loc) 948 B
/** * @jrmc/adonis-attachment * * @license MIT * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr> */ import { AttachmentBase } from './attachment_base.js'; import { imageToBlurhash } from '../utils/helpers.js'; export class Variant extends AttachmentBase { key; #folder; blurhash; constructor(drive, attributes, input) { super(drive, attributes, input); this.key = attributes.key; this.#folder = attributes.folder; this.blurhash = attributes.blurhash; } async generateBlurhash(options) { this.blurhash = await imageToBlurhash(this.input, options); } /** * Getters */ get folder() { return this.#folder; } /** * */ toObject() { return { key: this.key, folder: this.folder, name: this.name, blurhash: this.blurhash, ...super.toObject(), }; } }