Giao diện
Tham chiếu API
Endpoint chính
{collection}:export
Method: POST
Xuất dữ liệu collection ra file Excel (XLSX). Response là binary stream.
Request parameters:
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
columns | array | Có | Danh sách cột cần xuất (field name + tiêu đề hiển thị) |
filter | object | Không | Bộ lọc dữ liệu (giống list filter) |
sort | array | Không | Thứ tự sắp xếp |
appends | string[] | Không | Relation fields cần kèm theo |
title | string | Không | Tiêu đề file Excel (tên sheet / filename) |
Response: Binary XLSX stream (Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet).
Luồng xử lý server
- Server nhận request, acquire global mutex (chỉ 1 export chạy cùng lúc).
XlsxExporterquery dữ liệu từ DB theofilter,sort,appends.- Format dữ liệu theo cấu hình
columns(tên cột, format number/date). - Resolve relation fields thành giá trị hiển thị.
- Build file XLSX binary.
- Release mutex, trả binary stream về client.
Global mutex
Plugin sử dụng async-mutex để serialize export requests:
| Đặc điểm | Mô tả |
|---|---|
| Phạm vi | Toàn cục (toàn bộ server instance) |
| Mục đích | Ngăn nhiều export chạy đồng thời gây quá tải RAM/CPU |
| Hành vi khi bận | Request chờ đến khi mutex được release |
XlsxExporter
Class chịu trách nhiệm tạo file XLSX:
| Bước | Mô tả |
|---|---|
| Query | Đọc dữ liệu từ DB theo filter, sort, appends |
| Format | Map dữ liệu theo cấu hình columns (tên cột, format number/date) |
| Relations | Resolve relation fields (belongsTo, hasMany) thành giá trị hiển thị |
| Build XLSX | Sử dụng thư viện xlsx / node-xlsx để tạo file Excel binary |
| Stream | Trả binary stream về client qua HTTP response |
ACL
| Quyền | Mô tả |
|---|---|
export | Quyền riêng biệt, được thêm vào admin role khi install |
configureFields | allowConfigureFields: true — cho phép cấu hình field-level access |