feat(storage): add managed storage controls

Enforce a global log quota with configurable retention and observable degradation. Add authenticated storage reporting and safe cleanup controls to the settings UI. Protect active stream transfers and isolate parallel test resources.
This commit is contained in:
DrSmoothl committed 2026-07-24 12:58:57 +08:00
1 parent b884a1c479
commit 87a604ecbd
33 files changed
+5115 -136

No files matched your search

+26 -1
View File
@@ -1,4 +1,4 @@
import type { AccountConnections, BackupBundle, BackupImportResult, DebugActionDoc, DebugInvokeResult, DebugStreamMessage, GlobalSettings, HookProcessInfo, LogEntry, LogLevel, NotificationDeliveryRecord, NotificationsConfig, QQInfo, SystemInfo, SystemSettingsPatch, SystemSettingsResponse, UiAppearance, UiConfig, UpdateInfo } from '@/types';
import type { AccountConnections, BackupBundle, BackupImportResult, DebugActionDoc, DebugInvokeResult, DebugStreamMessage, GlobalSettings, HookProcessInfo, LogEntry, LogLevel, LogStorageSettingsPatch, NotificationDeliveryRecord, NotificationsConfig, QQInfo, StorageCleanupRequest, StorageCleanupResponse, StorageOverviewResponse, StorageSettingsUpdateResponse, SystemInfo, SystemSettingsPatch, SystemSettingsResponse, UiAppearance, UiConfig, UpdateInfo } from '@/types';
import type { PasswordRule } from '@/components/pages/change-password-page';
import { normalizeOneBotConfig } from '@/lib/onebot-config';
import {
@@ -58,6 +58,7 @@ class HttpApiClient implements ApiClient {
readonly notifications: ApiClient['notifications'];
readonly globalConfig: ApiClient['globalConfig'];
readonly systemSettings: ApiClient['systemSettings'];
readonly storage: ApiClient['storage'];
readonly debug: ApiClient['debug'];
readonly agreements: ApiClient['agreements'];
@@ -167,6 +168,30 @@ class HttpApiClient implements ApiClient {
this.postJson<BackupImportResult>('/api/system/backup/import', { backup, restoreCredentials }),
};
this.storage = {
get: () => this.getJson<StorageOverviewResponse>('/api/system/storage'),
saveSettings: (patch: LogStorageSettingsPatch) =>
this.postJson<StorageSettingsUpdateResponse>('/api/system/storage/settings', patch),
cleanup: async (request: StorageCleanupRequest) => {
const response = await this.request('/api/system/storage/cleanup', {
method: 'POST',
body: JSON.stringify(request),
});
const payload = await readJson<StorageCleanupResponse & ErrorPayload>(response);
// A cleanup can partially succeed and return HTTP 500 with the exact
// deleted/failed items. Preserve that result so the operator sees the
// real outcome instead of a generic exception.
if (!response.ok && !payload.cleanup) {
throw new ApiError(
response.status,
extractErrorMessage(payload, response.statusText || '清理失败'),
payload.code,
);
}
return payload;
},
};
this.debug = {
actions: () => this.getJson<{ actions: DebugActionDoc[]; categories: { category: string; count: number }[] }>('/api/debug/actions'),
invoke: (uin: string, action: string, params: Record<string, unknown>) =>