fix: 修复系统图标与操作日志映射

This commit is contained in:
Nixevol
2026-07-07 02:10:05 +08:00
parent 7c6b0bff4c
commit 98b4b8b079
13 changed files with 165 additions and 29 deletions
@@ -0,0 +1,29 @@
import { actionOf, moduleOf } from './operation-log.interceptor';
describe('operation log route mapping', () => {
it('keeps backup create and delete as separate actions', () => {
expect(moduleOf('/api/backups')).toBe('backups');
expect(actionOf('POST', '/api/backups')).toBe('backup');
expect(actionOf('DELETE', '/api/backups/backup_001')).toBe('delete');
});
it('maps backup restore flow to upload and restore actions', () => {
expect(actionOf('POST', '/api/backups/restore/preview')).toBe('upload');
expect(actionOf('POST', '/api/backups/restore/commit')).toBe('restore');
expect(actionOf('GET', '/api/backups/backup_001/download')).toBe('download');
});
it('maps special business operations before generic HTTP actions', () => {
expect(actionOf('POST', '/api/trace-codes/batch/delete')).toBe('delete');
expect(actionOf('POST', '/api/outbound/import/preview')).toBe('upload');
expect(actionOf('POST', '/api/outbound/import-sessions/session_001/commit')).toBe('update');
expect(actionOf('POST', '/api/auth/change-password')).toBe('update');
expect(actionOf('POST', '/api/blockchain-proofs/1/retry')).toBe('onchain');
expect(actionOf('POST', '/api/blockchain-proofs/1/confirm')).toBe('onchain');
});
it('uses nested resource modules for certificates and trace nodes', () => {
expect(moduleOf('/api/artworks/1/certificates')).toBe('certificates');
expect(moduleOf('/api/artworks/1/nodes')).toBe('nodes');
});
});
@@ -25,24 +25,46 @@ function sanitize(value: unknown, depth = 0): unknown {
return out;
}
function moduleOf(path: string): string {
const p = path.replace(/^\/api\/?/, '');
const first = p.split('/').filter(Boolean)[0] || 'root';
if (p.includes('/export')) return 'export';
if (p.includes('/download')) return 'download';
return first;
function pathSegments(path: string): string[] {
return path
.split('?')[0]
.replace(/^\/api\/?/, '')
.split('/')
.filter(Boolean);
}
function actionOf(method: string, path: string): string {
if (path.includes('/login')) return 'login';
if (path.includes('/export')) return 'export';
if (path.includes('/download')) return 'download';
if (path.includes('/upload')) return 'upload';
if (path.includes('/audit')) return 'audit';
if (path.includes('/blockchain-proofs') && path.includes('/confirm')) return 'onchain';
if (path.includes('/onchain')) return 'onchain';
if (path.includes('/backup')) return 'backup';
if (path.includes('/restore')) return 'restore';
export function moduleOf(path: string): string {
const segments = pathSegments(path);
if (segments.includes('certificates')) return 'certificates';
if (segments.includes('nodes')) return 'nodes';
return segments[0] || 'root';
}
export function actionOf(method: string, path: string): string {
const segments = pathSegments(path);
const [resource, second, third] = segments;
const last = segments[segments.length - 1] || '';
if (resource === 'auth' && segments.includes('login')) return 'login';
if (resource === 'auth' && segments.includes('change-password')) return 'update';
if (resource === 'backups') {
if (method === 'POST' && segments.length === 1) return 'backup';
if (second === 'restore' && third === 'preview') return 'upload';
if (second === 'restore' && third === 'commit') return 'restore';
if (last === 'download') return 'download';
}
if (resource === 'trace-codes' && second === 'batch' && third === 'delete') return 'delete';
if (resource === 'outbound') {
if (second === 'import') return 'upload';
if (second === 'import-sessions' && last === 'commit') return 'update';
}
if (resource === 'storage' && ['test', 'migrate', 'confirm'].includes(second || '')) return 'update';
if (segments.includes('export')) return 'export';
if (segments.includes('download') || last === 'template') return 'download';
if (segments.includes('upload')) return 'upload';
if (segments.includes('audit')) return 'audit';
if (resource === 'blockchain-proofs' && ['retry', 'confirm'].includes(last)) return 'onchain';
if (segments.includes('onchain')) return 'onchain';
if (method === 'POST') return 'create';
if (method === 'PUT' || method === 'PATCH') return 'update';
if (method === 'DELETE') return 'delete';