|
|
@@ -5,17 +5,40 @@ import OcrRecord from 'App/Models/OcrRecord'
|
|
|
import Drive from '@ioc:Adonis/Core/Drive'
|
|
|
import BlockchainWalletService from 'App/Services/BlockchainWalletService'
|
|
|
import * as bip39 from 'bip39'
|
|
|
+import { HttpStatusCode } from 'axios'
|
|
|
+import { HttpException } from '@adonisjs/http-server/build/src/Exceptions/HttpException'
|
|
|
|
|
|
export default class OcrRecordController {
|
|
|
private paginationService = new PaginationService(OcrRecord)
|
|
|
|
|
|
- public async index({ request }: HttpContextContract) {
|
|
|
- const res = await this.paginationService.paginate(request.all())
|
|
|
- for (let e of res) {
|
|
|
- if (e.img && e.img !== '-') {
|
|
|
- e.img = await Drive.getSignedUrl(new URL(e.img).pathname.replace(/^\//, ''))
|
|
|
- }
|
|
|
+ public async index({ request, auth }: HttpContextContract) {
|
|
|
+ const user = auth.user
|
|
|
+ const isApiUser = user?.$attributes?.role === 'api'
|
|
|
+
|
|
|
+ const requestData = request.all()
|
|
|
+ if (isApiUser) {
|
|
|
+ requestData.channel = user.username
|
|
|
}
|
|
|
+
|
|
|
+ const res = await this.paginationService.paginate(requestData)
|
|
|
+ if (isApiUser) {
|
|
|
+ res.forEach((record) => {
|
|
|
+ record.content = ''
|
|
|
+ record.record = ''
|
|
|
+ record.img = ''
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ await Promise.all(
|
|
|
+ res.map(async (record) => {
|
|
|
+ if (record.img && record.img !== '-') {
|
|
|
+ record.img = await Drive.getSignedUrl(
|
|
|
+ new URL(record.img).pathname.replace(/^\//, '')
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
return res
|
|
|
}
|
|
|
|