@jrmc/adonis-attachment
Version:
Turn any field on your Lucid model to an attachment data type
122 lines (121 loc) • 4 kB
JavaScript
/**
* @jrmc/adonis-attachment
*
* @license MIT
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
*/
import { defaultStateAttributeMixin } from '../../utils/default_values.js';
import { AttachmentTransactionService } from './attachment_transaction_service.js';
import { AttachmentPersisterService } from './attachment_persister_service.js';
import { AttachmentVariantService } from './attachment_variant_service.js';
import { AttachmentDetachmentService } from './attachment_detachment_service.js';
import { AttachmentUtils } from './attachment_utils.js';
export default class AttachmentRecorderService {
constructor(row) {
this.
this.
}
/**
* Initialize attachments state if not exists
*/
if (!this.
this.
}
}
/**
* During commit, we should cleanup the old detached files
*/
async commit() {
await this.
}
/**
* During rollback we should remove the attached files.
*/
async rollback() {
await this.
}
/**
* Persist attachments before saving the row to the database
*/
async persist() {
await this.
}
/**
* Handle transaction lifecycle
*/
async transaction(options = { enabledRollback: true }) {
await this.
}
/**
* Pre-compute URLs for all attachments
*/
async preComputeUrl() {
await this.
}
/**
* Set key IDs for all attachments
*/
async setKeyId() {
await this.
}
/**
* Generate variants for all dirty attachment attributes
*/
async generateVariants() {
await this.
}
/**
* Regenerate variants with specific options
*/
async regenerateVariants(options = {}) {
await this.
}
/**
* Detach dirty attachments (mark for deletion)
*/
async detach() {
await this.
}
/**
* Detach all attachments (mark all for deletion)
*/
async detachAll() {
await this.
}
/**
* Get row instance
*/
get row() {
return this.
}
/**
* Get attachments with specific options
*/
async getAttachments(options) {
let attachments;
if (options.requiredOriginal) {
attachments = AttachmentUtils.getOriginalAttachmentsByAttributeName(this.
}
else if (options.requiredDirty) {
attachments = AttachmentUtils.getDirtyAttachmentsByAttributeName(this.
}
else {
attachments = AttachmentUtils.getAttachmentsByAttributeName(this.
}
const opts = AttachmentUtils.getOptionsByAttributeName(this.
attachments.forEach(async (attachment) => {
if (attachment) {
attachment.setOptions(opts);
await attachment.makeFolder(this.
// await attachment.makeName(this.#row, options.attributeName, attachment.originalName)
}
});
return attachments;
}
}