40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import type { HttpContext } from '@adonisjs/core/http'
|
|
import vpsConfig from '#config/vps'
|
|
import backupService from '#services/backup_service'
|
|
import { actor, audit } from '#services/audit'
|
|
|
|
export default class BackupsController {
|
|
async index() {
|
|
return {
|
|
dir: vpsConfig.backups.dir,
|
|
schedule: backupService.schedule,
|
|
files: await backupService.list(),
|
|
}
|
|
}
|
|
|
|
async store(ctx: HttpContext) {
|
|
const job = await backupService.run(actor(ctx))
|
|
return { jobId: job.id }
|
|
}
|
|
|
|
async download(ctx: HttpContext) {
|
|
const path = backupService.path(ctx.params.name)
|
|
await audit(ctx, {
|
|
action: 'Téléchargement de sauvegarde',
|
|
target: ctx.params.name,
|
|
status: 'success',
|
|
})
|
|
return ctx.response.attachment(path, ctx.params.name)
|
|
}
|
|
|
|
async destroy(ctx: HttpContext) {
|
|
await backupService.delete(ctx.params.name)
|
|
await audit(ctx, {
|
|
action: 'Suppression de sauvegarde',
|
|
target: ctx.params.name,
|
|
status: 'success',
|
|
})
|
|
return { ok: true }
|
|
}
|
|
}
|