mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix(admin): correct TeamSpeak member counts and action feedback
This commit is contained in:
1 parent
88439181ae
commit
4bff2133b6
9 files changed
+196
-26
No files matched your search
@@ -5,6 +5,7 @@
|
||||
<div v-if="!settings.fixedMode" class="alert info admin-fixed-notice"><Icon name="info" :size="18"/><div><p>{{ tr('tsAdminFixedOnly') }}</p><RouterLink to="/admin/server">{{ tr('adminInstanceSettings') }}</RouterLink></div></div>
|
||||
<template v-else>
|
||||
<div v-if="noticeMessage" class="alert success" role="status">{{ noticeMessage }}</div>
|
||||
<div v-if="refreshWarning" class="alert info" role="status">{{ refreshWarning }}</div>
|
||||
<article v-if="!settings.enabled && !loading" class="operation-card admin-ts-setup">
|
||||
<Icon name="server" :size="26"/><div><h3>{{ tr('adminTsSetupTitle') }}</h3><p>{{ tr('adminTsSetupLead') }}</p></div>
|
||||
<button class="secondary-button" type="button" @click="configureConnection">{{ tr('adminTsConfigure') }}</button>
|
||||
@@ -63,7 +64,7 @@
|
||||
<template v-if="editor.action === 'channel.create'">
|
||||
<label><span>{{ tr('tsAdminParent') }}</span><select v-model="editor.parentId"><option value="0">{{ tr('tsAdminRoot') }}</option><option v-for="channel in overview?.channels" :key="channel.id" :value="channel.id">{{ channel.name }}</option></select></label>
|
||||
<label class="ts-admin-wide"><span>{{ tr('tsAdminDescription') }}</span><textarea v-model="editor.description" maxlength="8192" rows="3"></textarea></label>
|
||||
<label><span>{{ tr('tsAdminPassword') }}</span><input v-model="editor.password" type="password" autocomplete="new-password" maxlength="512" /></label><label class="choice"><input v-model="editor.permanent" type="checkbox" /><span>{{ tr('tsAdminPermanent') }}</span></label>
|
||||
<label><span>{{ tr('tsAdminChannelPassword') }}</span><input v-model="editor.password" type="password" autocomplete="new-password" maxlength="512" /></label><label class="choice"><input v-model="editor.permanent" type="checkbox" /><span>{{ tr('tsAdminPermanent') }}</span></label>
|
||||
</template>
|
||||
<label v-if="editor.action === 'client.move'"><span>{{ tr('tsAdminChannel') }}</span><select v-model="editor.channelId" required><option v-for="channel in overview?.channels" :key="channel.id" :value="channel.id">{{ channel.name }}</option></select></label>
|
||||
<template v-if="editor.action === 'client.group'"><label><span>{{ tr('tsAdminGroup') }}</span><select v-model="editor.groupId" required><option v-for="group in overview?.groups" :key="group.id" :value="group.id">{{ group.name }} (#{{ group.id }})</option></select></label><label class="choice"><input v-model="editor.remove" type="checkbox" /><span>{{ tr('tsAdminRemoveGroup') }}</span></label></template>
|
||||
@@ -87,12 +88,12 @@
|
||||
<tr v-if="!overview.channels.length"><td colspan="4">{{ tr('tsAdminNoChannels') }}</td></tr></tbody></table></div></section>
|
||||
</div>
|
||||
<div v-show="activeSection === 'clients'" data-admin-section="clients" class="admin-ts-section">
|
||||
<p v-if="!overview.groupsAvailable" class="field-help">{{ tr('tsAdminGroup') }}: {{ tr('tsAdminRestricted') }}</p>
|
||||
<p v-if="!overview.groupsAvailable" class="field-help">{{ tr('tsAdminGroup') }}: {{ listErrorText(overview.groupsErrorCode) }}</p>
|
||||
<section class="operation-card"><header><h3>{{ tr('tsAdminClients') }}</h3><strong>{{ overview.clients.length }}</strong></header><div class="table-wrap" role="region" tabindex="0" :aria-label="tr('tsAdminClients')"><table><thead><tr><th>{{ tr('nickname') }}</th><th>{{ tr('tsAdminChannel') }}</th><th>{{ tr('tsAdminGroup') }}</th><th>{{ tr('tsAdminTitle') }}</th></tr></thead><tbody>
|
||||
<tr v-for="client in overview.clients" :key="client.id"><td><strong>{{ client.nickname }}</strong><small>#{{ client.id }}</small></td><td>{{ channelNames.get(client.channelID) || client.channelID }}</td><td>{{ client.serverGroups.map(id => groupNames.get(id) || id).join(', ') || '—' }}</td><td><div class="ts-admin-row-actions"><button type="button" :disabled="settingsDirty || loading || saving || acting || !client.uid" @click="beginAction('client.move', client)">{{ tr('tsAdminMove') }}</button><button type="button" :disabled="settingsDirty || loading || saving || acting || !client.uid || !overview.groupsAvailable" @click="beginAction('client.group', client)">{{ tr('tsAdminGroupAction') }}</button><button class="danger" type="button" :disabled="settingsDirty || loading || saving || acting || !client.uid" @click="beginAction('client.kick', client)">{{ tr('tsAdminKick') }}</button><button class="danger" type="button" :disabled="settingsDirty || loading || saving || acting || !client.uid" @click="beginAction('client.ban', client)">{{ tr('tsAdminBan') }}</button></div></td></tr>
|
||||
<tr v-if="!overview.clients.length"><td colspan="4">{{ tr('tsAdminNoClients') }}</td></tr></tbody></table></div></section>
|
||||
</div>
|
||||
<div v-show="activeSection === 'bans'" data-admin-section="bans" class="admin-ts-section"><section class="operation-card"><header><h3>{{ tr('tsAdminBans') }}</h3><strong>{{ overview.bans.length }}</strong></header><p v-if="!overview.bansAvailable" class="field-help">{{ tr('tsAdminRestricted') }}</p><div v-else class="table-wrap"><table><thead><tr><th>{{ tr('nickname') }} / UID</th><th>{{ tr('tsAdminReason') }}</th><th>{{ tr('tsAdminBanDuration') }}</th><th>{{ tr('tsAdminTitle') }}</th></tr></thead><tbody><tr v-for="ban in overview.bans" :key="ban.id"><td>{{ ban.name || ban.uid || `#${ban.id}` }}</td><td>{{ ban.reason || '—' }}</td><td>{{ ban.durationSeconds }}</td><td><button type="button" class="secondary-button" :disabled="settingsDirty || loading || saving || acting" @click="beginAction('ban.delete', ban)">{{ tr('remove') }}</button></td></tr><tr v-if="!overview.bans.length"><td colspan="4">{{ tr('tsAdminNoBans') }}</td></tr></tbody></table></div></section></div>
|
||||
<div v-show="activeSection === 'bans'" data-admin-section="bans" class="admin-ts-section"><section class="operation-card"><header><h3>{{ tr('tsAdminBans') }}</h3><strong>{{ overview.bans.length }}</strong></header><p v-if="!overview.bansAvailable" class="field-help">{{ listErrorText(overview.bansErrorCode) }}</p><div v-else class="table-wrap"><table><thead><tr><th>{{ tr('nickname') }} / UID</th><th>{{ tr('tsAdminReason') }}</th><th>{{ tr('tsAdminBanDuration') }}</th><th>{{ tr('tsAdminTitle') }}</th></tr></thead><tbody><tr v-for="ban in overview.bans" :key="ban.id"><td>{{ ban.name || ban.uid || `#${ban.id}` }}</td><td>{{ ban.reason || '—' }}</td><td>{{ ban.durationSeconds }}</td><td><button type="button" class="secondary-button" :disabled="settingsDirty || loading || saving || acting" @click="beginAction('ban.delete', ban)">{{ tr('remove') }}</button></td></tr><tr v-if="!overview.bans.length"><td colspan="4">{{ tr('tsAdminNoBans') }}</td></tr></tbody></table></div></section></div>
|
||||
</template>
|
||||
</article>
|
||||
</template>
|
||||
@@ -109,7 +110,7 @@ import type { AdminTranslationKey } from '../../i18n/admin.js';
|
||||
import Icon from '../Icon.vue';
|
||||
const props = defineProps<{ model: ReturnType<typeof useAdminTsAdmin>; i18n: Pick<ReturnType<typeof useAdminI18n>, 'tr' | 'formatDate'>; targetAddress: string; targetPort: string }>();
|
||||
const {tr, formatDate} = props.i18n;
|
||||
const {settings, form, editor, overview, settingsDirty, noticeMessage, loading, saving, connecting, acting, saveSettings, connectAndRefresh, beginAction, closeAction, runAction} = props.model;
|
||||
const {settings, form, editor, overview, settingsDirty, noticeMessage, refreshWarning, listErrorText, loading, saving, connecting, acting, saveSettings, connectAndRefresh, beginAction, closeAction, runAction} = props.model;
|
||||
const connectionOpen = ref(false);
|
||||
const connectionPanel = ref<HTMLDetailsElement | null>(null);
|
||||
async function configureConnection() {
|
||||
|
||||
@@ -50,6 +50,7 @@ const errorLabels: Record<string, AdminTranslationKey> = {
|
||||
TS_ADMIN_PERMISSION_DENIED: "tsAdminPermissionError", TS_ADMIN_AUTH_FAILED: "tsAdminAuthError", TS_ADMIN_OPERATION_FAILED: "tsAdminActionError",
|
||||
TS_ADMIN_CLIENT_CHANGED: "tsAdminClientChanged", TS_ADMIN_CONFIG_CHANGED: "tsAdminConfigChanged", TS_ADMIN_PARTIAL_SUCCESS: "tsAdminPartialError",
|
||||
TS_ADMIN_RATE_LIMITED: "tsAdminRateError", TS_ADMIN_TLS_FAILED: "tsAdminTlsError",
|
||||
TS_ADMIN_READ_FAILED: "tsAdminReadError", TS_ADMIN_TIMEOUT: "tsAdminTimeoutError",
|
||||
};
|
||||
const connectionErrors: Record<string, AdminTranslationKey> = {
|
||||
PASSWORD_REQUIRED: "serverPasswordRequiredError", SERVER_PASSWORD_REQUIRED: "serverPasswordRequiredError",
|
||||
|
||||
@@ -25,6 +25,7 @@ export function useAdminTsAdmin(options: Options) {
|
||||
const settings = reactive(emptySettings()), form = reactive(emptyForm()), editor = reactive(emptyEditor());
|
||||
const overview = ref<Awaited<ReturnType<AdminApi["tsAdminOverview"]>> | null>(null);
|
||||
const noticeMessage = ref("");
|
||||
const refreshWarning = ref("");
|
||||
const loading = ref(false), saving = ref(false), connecting = ref(false), acting = ref(false);
|
||||
const settingsDirty = computed(() => form.enabled !== settings.enabled || form.transport !== settings.transport
|
||||
|| form.queryHost !== settings.queryHost || form.webQueryUrl !== settings.webQueryUrl
|
||||
@@ -40,6 +41,7 @@ export function useAdminTsAdmin(options: Options) {
|
||||
function cancelRequests() {
|
||||
requests.reset(); loading.value = false; saving.value = false; connecting.value = false; acting.value = false;
|
||||
Object.assign(editor, emptyEditor());
|
||||
refreshWarning.value = "";
|
||||
}
|
||||
function reset() {
|
||||
cancelRequests(); Object.assign(settings, emptySettings()); Object.assign(form, emptyForm()); overview.value = null; noticeMessage.value = "";
|
||||
@@ -51,6 +53,7 @@ export function useAdminTsAdmin(options: Options) {
|
||||
function mergeSettings(value: Awaited<ReturnType<AdminApi["tsAdminSettings"]>>, baseline: Form) {
|
||||
if (settings.configurationRevision && settings.configurationRevision !== value.configurationRevision) {
|
||||
requests.cancel("overview"); connecting.value = false; overview.value = null; Object.assign(editor, emptyEditor());
|
||||
refreshWarning.value = "";
|
||||
}
|
||||
Object.assign(settings, value);
|
||||
const next: Form = { enabled: value.enabled, transport: value.transport, queryHost: value.queryHost, webQueryUrl: value.webQueryUrl,
|
||||
@@ -77,7 +80,7 @@ export function useAdminTsAdmin(options: Options) {
|
||||
if (saving.value || acting.value) return;
|
||||
requests.cancel("overview"); connecting.value = false;
|
||||
const request = requests.begin("settings"), baseline = { ...form };
|
||||
saving.value = true; loading.value = false; options.errorMessage.value = ""; noticeMessage.value = "";
|
||||
saving.value = true; loading.value = false; options.errorMessage.value = ""; noticeMessage.value = ""; refreshWarning.value = "";
|
||||
try {
|
||||
const saved = await options.api.saveTsAdminSettings({ ...baseline, queryPort: Number(baseline.queryPort),
|
||||
password: baseline.passwordAction === "replace" ? baseline.password : undefined,
|
||||
@@ -89,12 +92,19 @@ export function useAdminTsAdmin(options: Options) {
|
||||
} catch (error) { if (request.isCurrent()) report(error); }
|
||||
finally { if (request.isCurrent()) saving.value = false; request.finish(); }
|
||||
}
|
||||
async function connectAndRefresh() {
|
||||
function listErrorText(code?: string | null) { return options.errorText(code || "TS_ADMIN_READ_FAILED"); }
|
||||
async function connectAndRefresh() { await readOverview(false); }
|
||||
async function readOverview(afterAction: boolean) {
|
||||
if (loading.value || connecting.value || saving.value || acting.value || settingsDirty.value || !settings.enabled || !settings.fixedMode) return;
|
||||
const request = requests.begin("overview");
|
||||
connecting.value = true; options.errorMessage.value = "";
|
||||
connecting.value = true; options.errorMessage.value = ""; refreshWarning.value = "";
|
||||
try { const value = await options.api.tsAdminOverview(request.signal); if (request.isCurrent()) overview.value = value; }
|
||||
catch (error) { if (request.isCurrent()) report(error); }
|
||||
catch (error) {
|
||||
if (request.isCurrent() && !isAdminRequestCancelled(error)) {
|
||||
if (afterAction) refreshWarning.value = options.tr("tsAdminRefreshError", { error: listErrorText((error as { code?: string }).code) });
|
||||
else report(error);
|
||||
}
|
||||
}
|
||||
finally { if (request.isCurrent()) connecting.value = false; request.finish(); }
|
||||
}
|
||||
function beginAction(action: TsAdminAction["action"], target?: { id: number | string; uid?: string; nickname?: string; name?: string; channelID?: string }) {
|
||||
@@ -125,17 +135,17 @@ export function useAdminTsAdmin(options: Options) {
|
||||
if (acting.value || saving.value || loading.value || settingsDirty.value || !settings.enabled || !settings.fixedMode || !editor.action || !overview.value) return;
|
||||
requests.cancel("overview"); connecting.value = false;
|
||||
const request = requests.begin("action"), body = { operation: actionPayload(), configurationRevision: overview.value.configurationRevision };
|
||||
acting.value = true; options.errorMessage.value = ""; noticeMessage.value = "";
|
||||
acting.value = true; options.errorMessage.value = ""; noticeMessage.value = ""; refreshWarning.value = "";
|
||||
try {
|
||||
await options.api.tsAdminAction(body, request.signal);
|
||||
if (!request.isCurrent()) return;
|
||||
Object.assign(editor, emptyEditor()); noticeMessage.value = options.tr("tsAdminActionSaved"); overview.value = null;
|
||||
// A failed refresh must never retry the write or report that it did not happen.
|
||||
acting.value = false;
|
||||
await connectAndRefresh();
|
||||
await readOverview(true);
|
||||
} catch (error) { if (request.isCurrent()) report(error); }
|
||||
finally { if (request.isCurrent()) acting.value = false; request.finish(); }
|
||||
}
|
||||
return { settings, form, editor, overview, settingsDirty, noticeMessage, loading, saving, connecting, acting,
|
||||
return { settings, form, editor, overview, settingsDirty, noticeMessage, refreshWarning, listErrorText, loading, saving, connecting, acting,
|
||||
loadSettings, saveSettings, connectAndRefresh, beginAction, closeAction, runAction, cancelRequests, reset };
|
||||
}
|
||||
@@ -17,6 +17,10 @@ const zh = {
|
||||
tsAdminRemoveKey: "移除 API Key",
|
||||
tsAdminKeepKey: "保留 API Key",
|
||||
tsAdminActionSaved: "TeamSpeak 操作已完成。",
|
||||
tsAdminRefreshError: "操作已完成,但状态刷新失败。{{error}} 请手动刷新,勿重复执行操作。",
|
||||
tsAdminReadError: "无法读取 TeamSpeak 状态,请检查管理连接后手动刷新。",
|
||||
tsAdminTimeoutError: "TeamSpeak 请求超时,请检查连接并稍后重试。",
|
||||
tsAdminChannelPassword: "频道密码",
|
||||
tsAdminServerSettings: "服务器设置",
|
||||
tsAdminWelcome: "欢迎消息",
|
||||
tsAdminSlots: "最大在线人数",
|
||||
@@ -78,6 +82,10 @@ const en = {
|
||||
tsAdminRemoveKey: "Remove API key",
|
||||
tsAdminKeepKey: "Keep API key",
|
||||
tsAdminActionSaved: "TeamSpeak operation completed.",
|
||||
tsAdminRefreshError: "The operation completed, but refreshing the state failed. {{error}} Refresh manually; do not repeat the operation.",
|
||||
tsAdminReadError: "Could not read TeamSpeak state. Check the management connection and refresh manually.",
|
||||
tsAdminTimeoutError: "The TeamSpeak request timed out. Check the connection and try again later.",
|
||||
tsAdminChannelPassword: "Channel password",
|
||||
tsAdminServerSettings: "Server settings",
|
||||
tsAdminWelcome: "Welcome message",
|
||||
tsAdminSlots: "Maximum clients",
|
||||
@@ -139,6 +147,10 @@ const de = {
|
||||
tsAdminRemoveKey: "API-Schlüssel entfernen",
|
||||
tsAdminKeepKey: "API-Schlüssel behalten",
|
||||
tsAdminActionSaved: "TeamSpeak-Aktion abgeschlossen.",
|
||||
tsAdminRefreshError: "Die Aktion wurde ausgeführt, aber der Status konnte nicht aktualisiert werden. {{error}} Aktualisieren Sie manuell, ohne die Aktion zu wiederholen.",
|
||||
tsAdminReadError: "Der TeamSpeak-Status konnte nicht gelesen werden. Prüfen Sie die Verwaltungsverbindung und aktualisieren Sie manuell.",
|
||||
tsAdminTimeoutError: "Zeitüberschreitung bei der TeamSpeak-Anfrage. Prüfen Sie die Verbindung und versuchen Sie es später erneut.",
|
||||
tsAdminChannelPassword: "Kanalpasswort",
|
||||
tsAdminServerSettings: "Servereinstellungen",
|
||||
tsAdminWelcome: "Willkommensnachricht",
|
||||
tsAdminSlots: "Maximale Clientzahl",
|
||||
@@ -200,6 +212,10 @@ const ru = {
|
||||
tsAdminRemoveKey: "Удалить API-ключ",
|
||||
tsAdminKeepKey: "Сохранить API-ключ",
|
||||
tsAdminActionSaved: "Операция TeamSpeak выполнена.",
|
||||
tsAdminRefreshError: "Операция выполнена, но обновить состояние не удалось. {{error}} Обновите вручную, не повторяя операцию.",
|
||||
tsAdminReadError: "Не удалось получить состояние TeamSpeak. Проверьте подключение управления и обновите вручную.",
|
||||
tsAdminTimeoutError: "Время ожидания запроса TeamSpeak истекло. Проверьте соединение и повторите позже.",
|
||||
tsAdminChannelPassword: "Пароль канала",
|
||||
tsAdminServerSettings: "Настройки сервера",
|
||||
tsAdminWelcome: "Приветствие",
|
||||
tsAdminSlots: "Максимум клиентов",
|
||||
@@ -261,6 +277,10 @@ const ja = {
|
||||
tsAdminRemoveKey: "API キーを削除",
|
||||
tsAdminKeepKey: "API キーを維持",
|
||||
tsAdminActionSaved: "TeamSpeak の操作が完了しました。",
|
||||
tsAdminRefreshError: "操作は完了しましたが、状態の更新に失敗しました。{{error}} 操作を繰り返さず、手動で更新してください。",
|
||||
tsAdminReadError: "TeamSpeak の状態を取得できませんでした。管理接続を確認し、手動で更新してください。",
|
||||
tsAdminTimeoutError: "TeamSpeak のリクエストがタイムアウトしました。接続を確認し、後で再試行してください。",
|
||||
tsAdminChannelPassword: "チャンネルパスワード",
|
||||
tsAdminServerSettings: "サーバー設定",
|
||||
tsAdminWelcome: "ウェルカムメッセージ",
|
||||
tsAdminSlots: "最大接続数",
|
||||
|
||||
Reference in new issue
Block a user