OcrRecordController.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
  2. import PaginationService from 'App/Services/PaginationService'
  3. import { schema } from '@ioc:Adonis/Core/Validator'
  4. import OcrRecord from 'App/Models/OcrRecord'
  5. import Drive from '@ioc:Adonis/Core/Drive'
  6. export default class OcrRecordController {
  7. private paginationService = new PaginationService(OcrRecord)
  8. public async index({ request }: HttpContextContract) {
  9. const res = await this.paginationService.paginate(request.all())
  10. for (let e of res) {
  11. if (e.img) {
  12. e.img = await Drive.getSignedUrl(new URL(e.img).pathname.replace(/^\//, ''))
  13. }
  14. }
  15. return res
  16. }
  17. public async store({ request, bouncer }: HttpContextContract) {
  18. // await bouncer.authorize('admin')
  19. await request.validate({
  20. schema: schema.create({
  21. deviceId: schema.string(),
  22. record: schema.string()
  23. })
  24. })
  25. return await OcrRecord.create(request.all())
  26. }
  27. }