Jelajahi Sumber

feat(ocr): 分页展示数据权限

wui 9 bulan lalu
induk
melakukan
ea25a2f97c
1 mengubah file dengan 29 tambahan dan 6 penghapusan
  1. 29 6
      app/Controllers/Http/OcrRecordController.ts

+ 29 - 6
app/Controllers/Http/OcrRecordController.ts

@@ -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
     }