feat(webui): EULA/PRIVACY consent gate — frontend
ConsentPage shown after login, before the forced password change: tabbed EULA/PRIVACY rendered by an in-house, dependency-free markdown renderer (React elements only, XSS-safe; single-pass bounded-class inline parser to avoid ReDoS on large docs). App gate order is login -> consent -> password -> app; api client gains agreements.get / recordConsent with a 409 stale-version re-prompt that refetches the new text.
This commit is contained in:
5 files changed
+583
-31
No files matched your search
@@ -2,6 +2,7 @@ import type { AccountConnections, BackupBundle, BackupImportResult, DebugActionD
|
||||
import type { PasswordRule } from '@/components/pages/change-password-page';
|
||||
import { normalizeOneBotConfig } from '@/lib/onebot-config';
|
||||
import {
|
||||
type AgreementsPayload,
|
||||
ApiError,
|
||||
type ApiClient,
|
||||
type ChangePasswordResult,
|
||||
@@ -47,6 +48,7 @@ class HttpApiClient implements ApiClient {
|
||||
readonly notifications: ApiClient['notifications'];
|
||||
readonly systemSettings: ApiClient['systemSettings'];
|
||||
readonly debug: ApiClient['debug'];
|
||||
readonly agreements: ApiClient['agreements'];
|
||||
|
||||
constructor(opts: CreateApiClientOptions = {}) {
|
||||
this.tokenStore = opts.tokenStore ?? localStorageTokenStore(DEFAULT_TOKEN_KEY);
|
||||
@@ -185,6 +187,26 @@ class HttpApiClient implements ApiClient {
|
||||
channelId,
|
||||
}),
|
||||
};
|
||||
|
||||
this.agreements = {
|
||||
get: () => this.getJson<AgreementsPayload>('/api/agreements'),
|
||||
recordConsent: async (version) => {
|
||||
// Read the body even on non-2xx so a 409 can surface currentVersion to
|
||||
// the caller (instead of fetchJson throwing it away as an ApiError).
|
||||
// A network failure (fetch reject) must resolve to {success:false}, not
|
||||
// throw, or the consent button hangs on "提交中…" with no error shown.
|
||||
try {
|
||||
const res = await this.request('/api/agreements/record-consent', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ version }),
|
||||
});
|
||||
const data = await readJson<{ success?: boolean; message?: string; currentVersion?: string }>(res);
|
||||
return { success: res.ok && !!data.success, message: data.message, currentVersion: data.currentVersion };
|
||||
} catch (e) {
|
||||
return { success: false, message: e instanceof Error ? e.message : '网络错误,请重试' };
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- HTTP helpers ----------
|
||||
|
||||
Reference in new issue
Block a user