Skip to content

Commit 19351b0

Browse files
committed
style: change TextField.root to Input
1 parent 215fce5 commit 19351b0

File tree

14 files changed

+391
-278
lines changed

14 files changed

+391
-278
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ XUGOU 采用现代化的系统架构,包含以下组件:
9090

9191
## 🏢 赞助
9292

93+
**目前缺少机器来作为 agent 验证监控告警等功能,导致有时候出了 bug 我自己反而发现不了,招个赞助商,有意愿的老板邮件联系**
94+
9395
感谢以下赞助商支持 XUGOU 的开发:
9496

9597
[Cloudflare](https://www.cloudflare.com/)

backend/src/api/agents.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ agents.delete("/:id", async (c) => {
7777
}
7878
});
7979

80-
8180
// 生成客户端Token
8281
agents.post("/token/generate", async (c) => {
8382
// 生成新令牌
@@ -95,7 +94,8 @@ agents.post("/token/generate", async (c) => {
9594

9695
// 客户端自注册接口
9796
agents.post("/register", async (c) => {
98-
const { token, name, hostname, ip_addresses, os, version } = await c.req.json();
97+
const { token, name, hostname, ip_addresses, os, version } =
98+
await c.req.json();
9999

100100
const result = await registerAgentService(
101101
c.env,
@@ -122,8 +122,6 @@ agents.post("/status", async (c) => {
122122
// 获取客户端发送的所有数据并打印日志
123123
const statusData = await c.req.json();
124124

125-
console.log("statusData: ", statusData);
126-
127125
try {
128126
await updateAgentStatusService(statusData);
129127
return c.json(

backend/src/db/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ export async function createNotificationChannelsAndSettings(): Promise<void> {
127127

128128
await db.insert(notificationChannels).values({
129129
id: 1,
130-
name: "默认Telegram通知渠道(https://t.me/xugou_group)",
130+
name: "测试Bot(https://t.me/xugou_bot)",
131131
type: "telegram",
132132
config:
133-
'{"botToken": "8163201319:AAGyY7FtdaRb6o8NCVXSbBUb6ofDK45cNJU", "chatId": "-1002608818360"}',
133+
'{"botToken": "8538953065:AAG51lJ31MNLWe3na5wai4SBRiZ8T-sOC3c", "chatId": "1111111111"}',
134134
enabled: 1,
135135
created_by: userId,
136136
created_at: now,

backend/src/services/AgentService.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export async function deleteAgentService(agentId: number, userId: number) {
156156
}
157157
}
158158

159-
160159
/**
161160
* 生成客户端注册令牌
162161
* @param env 环境变量
@@ -347,7 +346,6 @@ export async function updateAgentStatusService(status: any) {
347346
console.log("metrics", metrics);
348347

349348
const result = await AgentRepository.insertAgentMetrics(metrics);
350-
console.log("插入指标结果:", result);
351349

352350
// 取出 metrics中的最新一条数据用于通知
353351
const latestMetric = metrics[metrics.length - 1];

backend/src/services/NotificationService.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as models from "../models";
22
import * as repositories from "../repositories";
33

44
// 通知渠道相关服务
5-
export async function getNotificationChannels(userId: number): Promise<
6-
models.NotificationChannel[]
7-
> {
5+
export async function getNotificationChannels(
6+
userId: number
7+
): Promise<models.NotificationChannel[]> {
88
return await repositories.getNotificationChannels(userId);
99
}
1010

@@ -39,7 +39,11 @@ export async function updateNotificationChannel(
3939
>
4040
): Promise<{ success: boolean; message?: string }> {
4141
try {
42-
const result = await repositories.updateNotificationChannel(id, userId, channel);
42+
const result = await repositories.updateNotificationChannel(
43+
id,
44+
userId,
45+
channel
46+
);
4347
return {
4448
success: result,
4549
message: result ? "通知渠道更新成功" : "通知渠道不存在或未做任何更改",
@@ -55,7 +59,7 @@ export async function updateNotificationChannel(
5559

5660
export async function deleteNotificationChannel(
5761
id: number,
58-
userId: number,
62+
userId: number
5963
): Promise<{ success: boolean; message?: string }> {
6064
try {
6165
const result = await repositories.deleteNotificationChannel(id, userId);
@@ -76,15 +80,15 @@ export async function deleteNotificationChannel(
7680
}
7781

7882
// 通知模板相关服务
79-
export async function getNotificationTemplates(userId: number): Promise<
80-
models.NotificationTemplate[]
81-
> {
83+
export async function getNotificationTemplates(
84+
userId: number
85+
): Promise<models.NotificationTemplate[]> {
8286
return await repositories.getNotificationTemplates(userId);
8387
}
8488

8589
export async function getNotificationTemplateById(
8690
id: number,
87-
userId: number,
91+
userId: number
8892
): Promise<models.NotificationTemplate | null> {
8993
return await repositories.getNotificationTemplateById(id, userId);
9094
}
@@ -115,7 +119,11 @@ export async function updateNotificationTemplate(
115119
>
116120
): Promise<{ success: boolean; message?: string }> {
117121
try {
118-
const result = await repositories.updateNotificationTemplate(id, userId, template);
122+
const result = await repositories.updateNotificationTemplate(
123+
id,
124+
userId,
125+
template
126+
);
119127
return {
120128
success: result,
121129
message: result ? "通知模板更新成功" : "通知模板不存在或未做任何更改",
@@ -131,7 +139,7 @@ export async function updateNotificationTemplate(
131139

132140
export async function deleteNotificationTemplate(
133141
id: number,
134-
userId: number,
142+
userId: number
135143
): Promise<{ success: boolean; message?: string }> {
136144
try {
137145
const result = await repositories.deleteNotificationTemplate(id, userId);
@@ -149,7 +157,9 @@ export async function deleteNotificationTemplate(
149157
}
150158

151159
// 通知设置相关服务,获取所有的通知设置
152-
export async function getNotificationConfig(userId: number): Promise<models.NotificationConfig> {
160+
export async function getNotificationConfig(
161+
userId: number
162+
): Promise<models.NotificationConfig> {
153163
return await repositories.getNotificationConfig(userId);
154164
}
155165

@@ -218,8 +228,6 @@ interface WeComConfig {
218228
webhookUrl: string;
219229
}
220230

221-
222-
223231
/**
224232
* 解析通知渠道配置
225233
*/
@@ -277,7 +285,6 @@ function parseChannelConfig<T>(channel: models.NotificationChannel): T {
277285
}
278286
}
279287

280-
281288
// =================================================================
282289
// Section: 各渠道发送器实现 (Sender Implementations)
283290
// =================================================================
@@ -470,7 +477,7 @@ interface NotificationSender {
470477
/**
471478
* 发送器注册表。
472479
* 这是一个从渠道类型字符串到其发送器实现的映射。
473-
* "Talk is cheap. Show me the code."
480+
* "Talk is cheap. Show me the code."
474481
* 这段代码取代了原来愚蠢的 if-else 链。
475482
*/
476483
const senderRegistry: Record<string, NotificationSender> = {};
@@ -488,7 +495,6 @@ function registerSender(type: string, sender: NotificationSender) {
488495
console.log(`[通知注册] 成功注册发送器: ${type}`);
489496
}
490497

491-
492498
/**
493499
* 根据渠道类型发送通知 (重构后)
494500
* 这个函数现在只负责查找和调用,不再关心具体实现。
@@ -518,8 +524,6 @@ async function sendNotificationByChannel(
518524
}
519525
}
520526

521-
522-
523527
/**
524528
* 发送飞书通知
525529
*/
@@ -557,7 +561,7 @@ async function sendFeishuNotification(
557561
],
558562
},
559563
};
560-
564+
561565
console.log("[飞书通知] 准备发送通知到:", webhookUrl);
562566
const response = await fetch(webhookUrl, {
563567
method: "POST",
@@ -707,7 +711,9 @@ export async function sendNotification(
707711
// 获取所有通知渠道
708712
console.log(`[发送通知] 开始获取${channelIds.length}个通知渠道的详细信息`);
709713
const channels = await Promise.all(
710-
channelIds.map((id) => repositories.getNotificationChannelById(id, userId))
714+
channelIds.map((id) =>
715+
repositories.getNotificationChannelById(id, userId)
716+
)
711717
);
712718

713719
// 过滤掉不存在的渠道
@@ -853,7 +859,11 @@ export async function shouldSendNotification(
853859
}
854860

855861
// 获取此对象的特定设置
856-
const specificSettings = await repositories.getSpecificSettings(userId, type, id);
862+
const specificSettings = await repositories.getSpecificSettings(
863+
userId,
864+
type,
865+
id
866+
);
857867

858868
console.log(
859869
`[通知触发检查] 获取到特定设置数量: ${
@@ -993,7 +1003,9 @@ export async function deleteNotificationSettings(
9931003
userId: number
9941004
): Promise<{ success: boolean; message?: string }> {
9951005
try {
996-
console.log(`[删除通知设置] 开始删除${type}通知设置,ID=${id},用户ID=${userId}`);
1006+
console.log(
1007+
`[删除通知设置] 开始删除${type}通知设置,ID=${id},用户ID=${userId}`
1008+
);
9971009
// 执行删除操作
9981010
await repositories.deleteNotificationSettings(type, id, userId);
9991011
} catch (error) {
@@ -1013,7 +1025,9 @@ export async function deleteNotificationSettings(
10131025
* 为新用户创建默认的通知设置
10141026
* @param userId 新用户的ID
10151027
*/
1016-
export async function createDefaultNotificationSettingsForUser(userId: number): Promise<void> {
1028+
export async function createDefaultNotificationSettingsForUser(
1029+
userId: number
1030+
): Promise<void> {
10171031
try {
10181032
console.log(`为新用户 ${userId} 创建默认通知设置...`);
10191033
const now = new Date().toISOString();
@@ -1041,10 +1055,10 @@ export async function createDefaultNotificationSettingsForUser(userId: number):
10411055

10421056
// 创建默认通知渠道
10431057
const defaultChannelId = await repositories.createNotificationChannel({
1044-
name: "默认Telegram通知渠道",
1058+
name: "TG测试Bot(仅提供了Token,请自行填写ChatID或者使用你的Bot)",
10451059
type: "telegram",
10461060
config:
1047-
'{"botToken": "8163201319:AAGyY7FtdaRb6o8NCVXSbBUb6ofDK45cNJU", "chatId": "-1002608818360"}',
1061+
'{"botToken": "8538953065:AAG51lJ31MNLWe3na5wai4SBRiZ8T-sOC3c", "chatId": "111111111"}',
10481062
enabled: true,
10491063
created_by: userId,
10501064
});
@@ -1089,4 +1103,4 @@ export async function createDefaultNotificationSettingsForUser(userId: number):
10891103
console.error(`为新用户 ${userId} 创建默认通知设置失败:`, error);
10901104
// 此处不向上抛出异常,以免影响用户创建的主流程
10911105
}
1092-
}
1106+
}

frontend/src/pages/agents/CreateAgent.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect } from "react";
22
import { useNavigate } from "react-router-dom";
3-
import { Box, Flex, Heading, Text, Code, TextField } from "@radix-ui/themes";
4-
import { Button, Card, Separator, Switch } from "@/components/ui";
3+
import { Box, Flex, Heading, Text, Code } from "@radix-ui/themes";
4+
import { Button, Card, Separator, Switch, Input } from "@/components/ui";
55
import {
66
ArrowLeftIcon,
77
CopyIcon,
@@ -66,7 +66,8 @@ const CreateAgent = () => {
6666

6767
// 根据是否使用代理生成安装脚本 URL
6868
const getInstallScriptUrl = () => {
69-
const baseUrl = "https://github.com/zaunist/xugou/blob/main/install-agent.sh";
69+
const baseUrl =
70+
"https://github.com/zaunist/xugou/blob/main/install-agent.sh";
7071
if (useProxy) {
7172
return `${customProxyUrl}${baseUrl}`;
7273
}
@@ -109,7 +110,11 @@ const CreateAgent = () => {
109110
</Text>
110111
<Flex gap="2" align="center">
111112
<Text className="token-display">{serverUrl}</Text>
112-
<Button variant="secondary" onClick={handleCopyServerUrl} className="ml-2">
113+
<Button
114+
variant="secondary"
115+
onClick={handleCopyServerUrl}
116+
className="ml-2"
117+
>
113118
{serverUrlCopied ? <CheckIcon /> : <CopyIcon />}
114119
{serverUrlCopied ? t("common.copied") : t("common.copy")}
115120
</Button>
@@ -171,7 +176,8 @@ const CreateAgent = () => {
171176
{useProxy && (
172177
<Flex direction="column" gap="1" pl="6">
173178
<Text size="2">自定义代理地址 (可选):</Text>
174-
<TextField.Input
179+
<Input
180+
className="h-10"
175181
value={customProxyUrl}
176182
onChange={(e) => setCustomProxyUrl(e.target.value)}
177183
placeholder="例如: https://gh-proxy.com/"
@@ -188,7 +194,9 @@ const CreateAgent = () => {
188194
"一键安装命令 (Linux/macOS/Windows):"
189195
)}
190196
</Text>
191-
<Code size="2" className="break-all">{oneLinerInstallCommand}</Code>
197+
<Code size="2" className="break-all">
198+
{oneLinerInstallCommand}
199+
</Code>
192200
<Button variant="secondary" onClick={handleCopyInstallCommand}>
193201
{installCommandCopied ? <CheckIcon /> : <CopyIcon />}
194202
{installCommandCopied ? t("common.copied") : t("common.copy")}

frontend/src/pages/agents/EditAgent.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from "react";
22
import { useNavigate, useParams } from "react-router-dom";
3-
import { Box, Flex, Heading, Text, TextField } from "@radix-ui/themes";
4-
import { Button, Card } from "@/components/ui";
3+
import { Box, Flex, Heading, Text } from "@radix-ui/themes";
4+
import { Button, Card, Input } from "@/components/ui";
55
import { ArrowLeftIcon } from "@radix-ui/react-icons";
66
import { getAgent, updateAgent } from "../../api/agents";
77
import { useTranslation } from "react-i18next";
@@ -125,7 +125,8 @@ const EditAgent = () => {
125125
*
126126
</Text>
127127
</Text>
128-
<TextField.Input
128+
<Input
129+
className="h-10"
129130
name="name"
130131
value={formData.name}
131132
onChange={handleChange}

0 commit comments

Comments
 (0)