mirror of
https://github.com/open-webui/computer.git
synced 2026-11-25 06:47:38 -05:00
refac
This commit is contained in:
1 parent
e06ee9338f
commit
149f34bfd2
16 files changed
+118
-30
No files matched your search
@@ -20,6 +20,7 @@ export interface NotificationTarget {
|
||||
id: string;
|
||||
type: NotificationTargetType;
|
||||
enabled: boolean;
|
||||
is_default?: boolean;
|
||||
events: ChatNotificationEvent[];
|
||||
delivery: NotificationDelivery;
|
||||
config: {
|
||||
@@ -77,6 +78,10 @@ export function testNotificationTarget(id: string) {
|
||||
return fetchJSON<{ ok: boolean }>(`/api/notifications/targets/${id}/test`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function setDefaultNotificationTarget(id: string) {
|
||||
return fetchJSON<NotificationTarget>(`/api/notifications/targets/${id}/default`, { method: 'PUT' });
|
||||
}
|
||||
|
||||
export async function listNotificationBotOptions(): Promise<BotOption[]> {
|
||||
const data = await fetchJSON<{ bots: BotOption[] }>('/api/notifications/bot-options');
|
||||
return data.bots;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
listNotificationBotOptions,
|
||||
listNotificationEvents,
|
||||
listNotificationTargets,
|
||||
setDefaultNotificationTarget,
|
||||
testNotificationTarget,
|
||||
updateNotificationTarget,
|
||||
type BotOption,
|
||||
@@ -63,20 +64,22 @@
|
||||
|
||||
async function loadNotificationTargets() {
|
||||
loadingTargets = true;
|
||||
try {
|
||||
const [nextTargets, bots, events] = await Promise.all([
|
||||
listNotificationTargets(),
|
||||
listNotificationBotOptions(),
|
||||
listNotificationEvents()
|
||||
]);
|
||||
targets = nextTargets;
|
||||
botOptions = bots;
|
||||
eventOptions = events.length ? events : fallbackEventOptions;
|
||||
} catch {
|
||||
const [targetResult, botResult, eventResult] = await Promise.allSettled([
|
||||
listNotificationTargets(),
|
||||
listNotificationBotOptions(),
|
||||
listNotificationEvents()
|
||||
]);
|
||||
if (targetResult.status === 'fulfilled') {
|
||||
targets = targetResult.value;
|
||||
} else {
|
||||
toast.error($t('general.notificationTargetsLoadFailed'));
|
||||
} finally {
|
||||
loadingTargets = false;
|
||||
}
|
||||
botOptions = botResult.status === 'fulfilled' ? botResult.value : [];
|
||||
eventOptions =
|
||||
eventResult.status === 'fulfilled' && eventResult.value.length
|
||||
? eventResult.value
|
||||
: fallbackEventOptions;
|
||||
loadingTargets = false;
|
||||
}
|
||||
|
||||
async function toggleNotifications() {
|
||||
@@ -150,12 +153,12 @@
|
||||
destination_chat_id: form.destination_chat_id.trim()
|
||||
};
|
||||
}
|
||||
const saved = originalId
|
||||
? await updateNotificationTarget(originalId, payload)
|
||||
: await createNotificationTarget(payload);
|
||||
targets = originalId
|
||||
? targets.map((target) => (target.id === originalId ? saved : target))
|
||||
: [...targets, saved];
|
||||
if (originalId) {
|
||||
await updateNotificationTarget(originalId, payload);
|
||||
} else {
|
||||
await createNotificationTarget(payload);
|
||||
}
|
||||
await loadNotificationTargets();
|
||||
formOpen = false;
|
||||
toast.success($t('settings.saved'));
|
||||
} catch (error) {
|
||||
@@ -167,8 +170,8 @@
|
||||
|
||||
async function patchTarget(target: NotificationTarget, patch: Partial<NotificationTarget>) {
|
||||
try {
|
||||
const saved = await updateNotificationTarget(target.id, patch as any);
|
||||
targets = targets.map((item) => (item.id === saved.id ? saved : item));
|
||||
await updateNotificationTarget(target.id, patch as any);
|
||||
await loadNotificationTargets();
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : $t('general.notificationTargetSaveFailed'));
|
||||
}
|
||||
@@ -177,7 +180,16 @@
|
||||
async function removeTarget(target: NotificationTarget) {
|
||||
try {
|
||||
await deleteNotificationTarget(target.id);
|
||||
targets = targets.filter((item) => item.id !== target.id);
|
||||
await loadNotificationTargets();
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : $t('general.notificationTargetSaveFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
async function makeDefault(target: NotificationTarget) {
|
||||
try {
|
||||
await setDefaultNotificationTarget(target.id);
|
||||
await loadNotificationTargets();
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : $t('general.notificationTargetSaveFailed'));
|
||||
}
|
||||
@@ -255,6 +267,11 @@
|
||||
<span class="shrink-0 text-[0.625rem] text-gray-400 dark:text-gray-600">
|
||||
{target.type === 'webhook' ? $t('general.webhook') : $t('general.bot')}
|
||||
</span>
|
||||
{#if target.is_default}
|
||||
<span class="shrink-0 text-[0.625rem] text-gray-400 dark:text-gray-600">
|
||||
{$t('general.default')}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="truncate text-[0.625rem] text-gray-400 dark:text-gray-600 leading-tight">
|
||||
{targetDestination}
|
||||
@@ -274,6 +291,14 @@
|
||||
>
|
||||
{$t('general.sendTest')}
|
||||
</button>
|
||||
{#if !target.is_default}
|
||||
<button
|
||||
class="text-[0.625rem] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => makeDefault(target)}
|
||||
>
|
||||
{$t('general.makeDefault')}
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
class="text-[0.625rem] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => openEditTarget(target)}
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Nur wenn ich abwesend bin",
|
||||
"general.always": "Immer",
|
||||
"general.sendTest": "Test senden",
|
||||
"general.makeDefault": "Als Standard festlegen",
|
||||
"general.platformDestinationId": "Plattform-Ziel-ID",
|
||||
"general.targetId": "Ziel-ID",
|
||||
"general.targetIdForNotify": "Ziel-ID",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Only when I'm away",
|
||||
"general.always": "Always",
|
||||
"general.sendTest": "Send test",
|
||||
"general.makeDefault": "Make default",
|
||||
"general.platformDestinationId": "Platform destination ID",
|
||||
"general.targetId": "Target ID",
|
||||
"general.targetIdForNotify": "Target ID",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Solo cuando estoy ausente",
|
||||
"general.always": "Siempre",
|
||||
"general.sendTest": "Enviar prueba",
|
||||
"general.makeDefault": "Hacer predeterminado",
|
||||
"general.platformDestinationId": "ID de destino de la plataforma",
|
||||
"general.targetId": "ID del destino",
|
||||
"general.targetIdForNotify": "ID del destino",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Seulement quand je suis absent",
|
||||
"general.always": "Toujours",
|
||||
"general.sendTest": "Envoyer un test",
|
||||
"general.makeDefault": "Définir par défaut",
|
||||
"general.platformDestinationId": "ID de destination de la plateforme",
|
||||
"general.targetId": "ID de la cible",
|
||||
"general.targetIdForNotify": "ID de la cible",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "離席中のみ",
|
||||
"general.always": "常に",
|
||||
"general.sendTest": "テスト送信",
|
||||
"general.makeDefault": "既定に設定",
|
||||
"general.platformDestinationId": "プラットフォーム送信先ID",
|
||||
"general.targetId": "通知先ID",
|
||||
"general.targetIdForNotify": "通知先ID",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "자리 비움일 때만",
|
||||
"general.always": "항상",
|
||||
"general.sendTest": "테스트 보내기",
|
||||
"general.makeDefault": "기본값으로 설정",
|
||||
"general.platformDestinationId": "플랫폼 대상 ID",
|
||||
"general.targetId": "대상 ID",
|
||||
"general.targetIdForNotify": "대상 ID",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Só quando eu estiver ausente",
|
||||
"general.always": "Sempre",
|
||||
"general.sendTest": "Enviar teste",
|
||||
"general.makeDefault": "Definir como padrão",
|
||||
"general.platformDestinationId": "ID do destino na plataforma",
|
||||
"general.targetId": "ID do destino",
|
||||
"general.targetIdForNotify": "ID do destino",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "Только когда меня нет",
|
||||
"general.always": "Всегда",
|
||||
"general.sendTest": "Отправить тест",
|
||||
"general.makeDefault": "Сделать по умолчанию",
|
||||
"general.platformDestinationId": "ID назначения платформы",
|
||||
"general.targetId": "ID цели",
|
||||
"general.targetIdForNotify": "ID цели",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "仅在我离开时",
|
||||
"general.always": "始终",
|
||||
"general.sendTest": "发送测试",
|
||||
"general.makeDefault": "设为默认",
|
||||
"general.platformDestinationId": "平台目标 ID",
|
||||
"general.targetId": "目标 ID",
|
||||
"general.targetIdForNotify": "目标 ID",
|
||||
|
||||
@@ -412,6 +412,7 @@
|
||||
"general.onlyWhenAway": "僅在我離開時",
|
||||
"general.always": "一律",
|
||||
"general.sendTest": "傳送測試",
|
||||
"general.makeDefault": "設為預設",
|
||||
"general.platformDestinationId": "平台目標 ID",
|
||||
"general.targetId": "目標 ID",
|
||||
"general.targetIdForNotify": "目標 ID",
|
||||
|
||||
Reference in new issue
Block a user