@adonis-agora/media
Version:
Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a
46 lines • 2.62 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { BaseCommand, flags } from '@adonisjs/core/ace';
import { backfillMediaTenants } from '../src/commands/tenancy_backfill.js';
/**
* `node ace media:tenancy:backfill --owner-type=Organization` — stamp `tenant_id` on stored files
* that have none and whose owner is the tenant itself (`tenant_id = owner_id`). Lucid store only.
*/
export default class MediaTenancyBackfill extends BaseCommand {
static commandName = 'media:tenancy:backfill';
static description = 'Stamp tenant_id on media whose owner is the tenant (e.g. --owner-type=Organization)';
static options = { startApp: true };
async run() {
if (!this.ownerType) {
this.logger.error('Pass --owner-type, the owner type that is the tenant (e.g. Organization).');
this.exitCode = 1;
return;
}
const db = (await this.app.container.make('lucid.db'));
const count = await backfillMediaTenants(db.connection(this.connection), {
ownerType: this.ownerType,
...(this.table !== undefined ? { table: this.table } : {}),
...(this.dryRun ? { dryRun: true } : {}),
});
this.logger.success(this.dryRun
? `${count} file(s) owned by ${this.ownerType} have no tenant and would be stamped.`
: `Stamped ${count} file(s) owned by ${this.ownerType} with their owner as tenant.`);
}
}
__decorate([
flags.string({ description: 'Owner type that is the tenant itself (e.g. Organization)' })
], MediaTenancyBackfill.prototype, "ownerType", void 0);
__decorate([
flags.string({ description: 'The media table (default: media)' })
], MediaTenancyBackfill.prototype, "table", void 0);
__decorate([
flags.string({ description: 'The Lucid connection (default: the default connection)' })
], MediaTenancyBackfill.prototype, "connection", void 0);
__decorate([
flags.boolean({ description: 'Only count the files that would be stamped' })
], MediaTenancyBackfill.prototype, "dryRun", void 0);
//# sourceMappingURL=tenancy_backfill.js.map