Plugin cho Strapi 5: Real-time presence (ai đang xem/sửa), Action History (audit log), Version Snapshot & Restore (khôi phục phiên bản cũ).
- Avatars user đang xem/sửa entry trong Content Manager
- Typing indicators
- Socket.io, deduplication nhiều tab
- Ghi nhận: create, update, publish, unpublish, delete, discardDraft
- Hỗ trợ admin & API user, lưu before/after cho audit
- Tự động snapshot khi create/update/publish/delete
- Giao diện Recovery: xem chi tiết, phục hồi phiên bản cũ
- Đánh giá % khôi phục: fields, relations, media, dynamic zone
- Bật plugin trong
config/plugins.ts:
presence: {
enabled: true,
resolve: './src/plugins/strapi-plugin-presence',
config: {
retentionDays: 90,
minActionRecords: 500,
maxVersionsPerDoc: 5,
snapshotContentTypes: [
'api::about-page.about-page',
'api::department.department',
// ...
],
},
},- Build (chạy từ source):
cd src/plugins/strapi-plugin-presence
npm install && npm run build- Chạy Strapi:
cd backend
npm run build && npm run dev| Tham số | Mặc định | Mô tả |
|---|---|---|
retentionDays |
90 | Ngày giữ action history & versions trước cleanup |
minActionRecords |
500 | Số action tối thiểu trước khi cleanup |
maxVersionsPerDoc |
5 | Version tối đa mỗi document (cũ nhất bị xóa trước) |
snapshotContentTypes |
[] | UIDs Single/Collection types cần snapshot |
Restore yêu cầu plugin::presence.restore → Settings > Roles.
| Biến | Ghi đè |
|---|---|
PRESENCE_RETENTION_DAYS |
retentionDays |
PRESENCE_MIN_ACTION_RECORDS |
minActionRecords |
PRESENCE_MAX_VERSIONS_PER_DOC |
maxVersionsPerDoc |
strapi-plugin-presence/
├── admin/src/
│ ├── components/ # PresenceAvatars, PublishHistoryButton, RecoveryView, DetailModal
│ ├── pages/ # ActionHistoryPage
│ └── index.ts
├── server/
│ ├── audit.ts, audit-auth.ts
│ ├── content-types/ # action-history, version
│ ├── services/ # history, retention, restore-steps
│ └── index.ts
└── VERSION-RESTORE.md
Prefix: /presence hoặc /api/presence
| Method | Path | Mô tả |
|---|---|---|
| GET | /list?documentId=&contentType= |
Danh sách versions |
| GET | /assess/:versionId |
Đánh giá version (%) |
| GET | /version/:documentId |
Chi tiết version |
| GET | /restore-stream/:versionId?token= |
SSE stream restore |
| POST | /restore |
Restore (body: versionId) |
| POST | /cancel-restore |
Hủy restore (body: token) |
| GET/POST | /snapshot-now?contentType=&locale= |
Snapshot thủ công (debug) |
| Method | Path | Mô tả |
|---|---|---|
| GET | /action-history |
Danh sách |
| GET | /action-history/:id |
Chi tiết |
Snapshot lưu: fields thông thường, components, dynamic zones, danh sách documentId relations (không clone bản ghi liên quan).
Restore làm: ghi đè fields, gán lại relations theo ID, giữ thứ tự many-to-many. Relations mới (không có trong version cũ) bị remove.
Không làm: khôi phục nội dung đã sửa của relation, tạo relation cho bản ghi đã xóa.
→ Chi tiết: VERSION-RESTORE.md
npm run watch # Watch mode
npm run verify # Kiểm tra pluginDependencies: socket.io (realtime), @strapi/design-system, @strapi/icons (Admin UI)