mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 20:19:26 +01:00
Lint and update
This commit is contained in:
@@ -1,49 +1,46 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
import File from "App/Models/File";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Application from '@ioc:Adonis/Core/Application'
|
||||
import File from 'App/Models/File'
|
||||
|
||||
export default class FilesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
files: await File.all()
|
||||
files: await File.all(),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const file = await request.file('file', {
|
||||
extnames: ['jpg', 'png', 'jpeg']
|
||||
extnames: ['jpg', 'png', 'jpeg'],
|
||||
})
|
||||
const label = request.input('label')
|
||||
|
||||
if (!file) {
|
||||
if (!file)
|
||||
return 'Please upload file!'
|
||||
}
|
||||
if (file.hasErrors) {
|
||||
|
||||
if (file.hasErrors)
|
||||
return file.errors
|
||||
}
|
||||
|
||||
await file.move(Application.makePath('storage'), {
|
||||
name: `${label}.${file.extname}`,
|
||||
overwrite: true
|
||||
overwrite: true,
|
||||
})
|
||||
|
||||
return response.status(200).send({
|
||||
file: await File.firstOrCreate({
|
||||
label: label
|
||||
label,
|
||||
}, {
|
||||
fileName: `${label}.${file.extname}`,
|
||||
label: label
|
||||
})
|
||||
label,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
public async destroy({ params, response }: HttpContextContract) {
|
||||
const file = await File.findOrFail(params.id)
|
||||
await file.delete()
|
||||
return response.status(200).send({
|
||||
message: 'File successfully deleted!'
|
||||
message: 'File successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user