Bỏ qua, đến nội dung

@digiforce-nc/plugin-file-manager

Plugin quản lý file upload/storage — hỗ trợ nhiều backend lưu trữ (local, S3, Ali OSS, Tencent COS, MinIO), cung cấp pipeline upload và URL resolution.

Plugin này làm gì?

Hãy hình dung một hệ thống kho lưu trữ file: bạn có nhiều nhà kho (local disk, S3, MinIO...) nhưng chỉ cần một cửa gửi hàng duy nhất. Plugin nhận file từ người dùng, quyết định gửi vào kho nào, trả lại phiếu nhận (URL) để lấy file sau này.

Ba nhiệm vụ chính

#Nhiệm vụChi tiết
1Upload & lưu trữNhận file qua multer, lưu vào storage backend được cấu hình
2Quản lý storageCRUD storage backend, kiểm tra kết nối, lấy thông tin dung lượng
3URL resolutionTạo URL truy cập / preview cho attachment, cleanup file không dùng

Kiến trúc

Tổng quan 4 tầng

TầngVai tròThành phần
Client UIUpload file, cấu hình storageFileManagerProvider, FileStoragePane
Server APIXử lý upload, quản lý storageUpload pipeline (multer), storage registry
Storage BackendLưu trữ file vật lýLocal, S3, Ali OSS, Tencent COS, MinIO
DatabaseMetadata file & cấu hình storage2 bảng: storages, attachments

API endpoints

EndpointMô tả
storages CRUDTạo, sửa, xóa, liệt kê storage backend
storages:getBasicInfoThông tin cơ bản (dung lượng, loại) của storage
storages:checkKiểm tra kết nối storage
attachments:uploadUpload file mới
attachments:createTạo attachment record (cho file đã có URL)

Storage Registry

Storage typeBackendGhi chú
localLocal diskPhù hợp dev, single-server
s3AWS S3Production, multi-region
ali-ossAlibaba Cloud OSSChina region
tx-cosTencent Cloud COSChina region
minioMinIOSelf-hosted, S3-compatible

Database — 2 bảng

BảngChứa gìVí dụ
storagesCấu hình storage backend{ type: 's3', options: { bucket: 'uploads', region: 'ap-southeast-1' } }
attachmentsMetadata file đã upload{ filename: 'report.pdf', storageId: 1, url: '...' }

Thành phần client

Thành phầnMô tả
FileManagerProviderContext provider quản lý storage state
FileStoragePaneTrang cấu hình storage trong Settings
UploadFieldWidgetWidget upload file cho form field

Dependencies

PackageVai trò
@digiforce-nc/actionsAction context types (peer)
@digiforce-nc/databaseDatabase ORM (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/clientClient framework (peer)

Mục lục chi tiết