Bỏ qua, đến nội dung

@digiforce-nc/plugin-field-attachment-url

Plugin cung cấp kiểu field URL attachment — cho phép đính kèm file thông qua URL từ hệ thống file manager, tích hợp public storage để hiển thị trực tiếp.

Plugin này làm gì?

Hãy hình dung: bạn đã upload file lên hệ thống qua plugin-file-manager và muốn đính kèm file đó vào bản ghi mà không cần upload lại. Plugin này cung cấp field cho phép chọn file từ các collection có public storage, lưu URL tham chiếu và hiển thị preview.

Hai nhiệm vụ chính

#Nhiệm vụChi tiết
1Liệt kê file collectionsServer action truy vấn danh sách collection có public storage khả dụng
2Đính kèm & hiển thịClient component cho phép chọn file, lưu URL, hiển thị preview

Kiến trúc

Tổng quan

Plugin có cả server (action endpoint) và client (UI component). Server cung cấp endpoint để lấy danh sách file collection có public storage. Client hiển thị giao diện chọn và xem file.

Luồng hoạt động chi tiết

Server action

ActionMethodMô tả
collections:listFileCollectionsWithPublicStorageGETTrả về danh sách collection được cấu hình public storage, dùng để populate dropdown chọn file

Field Interface

Thuộc tínhGiá trị
nameattachmentURL
typestring
groupmedia
Mô tảLưu URL tham chiếu đến file trong hệ thống file manager

Components

ComponentChức năng
AttachmentUrlComponent chính — hiển thị input URL + preview, cho phép chọn từ file collection
AttachmentURLFieldWidgetWidget wrapper đăng ký vào schema component

Ví dụ sử dụng

Cấu hình field attachment URL

typescript
const attachmentField = {
  name: 'contractFile',
  type: 'string',
  interface: 'attachmentURL',
  uiSchema: {
    type: 'string',
    title: 'File hợp đồng',
    'x-component': 'AttachmentUrl',
  },
};

Gọi API lấy danh sách file collections

typescript
const response = await api.resource('collections').listFileCollectionsWithPublicStorage();
const collections = response.data.data;
// collections = [{ name: 'attachments', storage: { type: 's3', baseUrl: '...' } }, ...]

Thành phần client

Thành phầnMô tả
AttachmentURLFieldInterfaceĐịnh nghĩa interface cho field attachment URL
AttachmentUrlComponent hiển thị và chọn file
AttachmentURLFieldWidgetWidget đăng ký vào SchemaComponentManager

Dependencies

PackageVai trò
@digiforce-nc/clientClient framework — đăng ký component
@digiforce-nc/serverServer framework — đăng ký action
@digiforce-nc/plugin-file-managerQuản lý file và storage — plugin phụ thuộc

Mục lục chi tiết