mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 03:03:24 +08:00
Sync bot chat language with DSH system locale.
Localize WhatsApp access-grant approvals via t() and push Host language from the UI on load and locale change. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6107692418
commit
45f430fb28
10 changed files with 181 additions and 33 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { getImHostLanguage, setImHostLanguage } from '../../src/channels/shared/i18n.mjs';
|
||||
import { createUpdateRuntime } from './update-runtime.mjs';
|
||||
import { createUpdateService } from './update-service.mjs';
|
||||
import { installConnectionRpcChannel } from './connection-rpc-mount.mjs';
|
||||
|
|
@ -5,8 +6,20 @@ import { resolveRpcAuthority } from './rpc-authority.mjs';
|
|||
|
||||
export const UPDATE_RPC_CHANNEL = '/dsh-im';
|
||||
export const UPDATE_ENDPOINTS = Object.freeze(['update.status', 'update.check', 'update.install']);
|
||||
export const HOST_LANGUAGE_SET_ENDPOINT = 'host.language.set';
|
||||
|
||||
function validLanguagePayload(payload) {
|
||||
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
||||
const keys = Object.keys(payload);
|
||||
return keys.length === 1
|
||||
&& keys[0] === 'language'
|
||||
&& typeof payload.language === 'string'
|
||||
&& payload.language.trim().length > 0
|
||||
&& payload.language.length <= 32;
|
||||
}
|
||||
|
||||
function validPayload(endpoint, payload) {
|
||||
if (endpoint === HOST_LANGUAGE_SET_ENDPOINT) return validLanguagePayload(payload);
|
||||
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
||||
const keys = Object.keys(payload);
|
||||
if (endpoint !== 'update.install') return keys.length === 0;
|
||||
|
|
@ -25,9 +38,14 @@ const PUBLIC_ERRORS = new Set([
|
|||
|
||||
export function createUpdateRpcHandler(service) {
|
||||
return async (endpoint, payload, signal) => {
|
||||
if (!UPDATE_ENDPOINTS.includes(endpoint) || !validPayload(endpoint, payload)) {
|
||||
if (endpoint !== HOST_LANGUAGE_SET_ENDPOINT && !UPDATE_ENDPOINTS.includes(endpoint)
|
||||
|| !validPayload(endpoint, payload)) {
|
||||
return { ok: false, error: { code: 'bad-request', message: 'Invalid update request.' } };
|
||||
}
|
||||
if (endpoint === HOST_LANGUAGE_SET_ENDPOINT) {
|
||||
setImHostLanguage(payload.language);
|
||||
return { ok: true, value: { language: getImHostLanguage() } };
|
||||
}
|
||||
if (signal?.aborted) return { ok: false, error: { code: 'cancelled', message: 'Request cancelled.' } };
|
||||
try {
|
||||
// The submitted install belongs to the Host, not the lifetime of this browser request.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue