fix: handle elevated proxy pool services and Windows output
This commit is contained in:
+93
-18
@@ -46,6 +46,8 @@ import type {
|
||||
Log,
|
||||
Config,
|
||||
Proxy,
|
||||
PoolServiceStatus,
|
||||
PoolManageResult,
|
||||
Auth,
|
||||
History,
|
||||
Filters,
|
||||
@@ -954,11 +956,17 @@ function ImportDialog({
|
||||
if (year) body.set("year", year);
|
||||
setBusy(true);
|
||||
try {
|
||||
const result = await api<{ records: number; scores: number; indexed_schools: number }>("/import", {
|
||||
const result = await api<{
|
||||
records: number;
|
||||
scores: number;
|
||||
indexed_schools: number;
|
||||
}>("/import", {
|
||||
method: "POST",
|
||||
body,
|
||||
});
|
||||
notify(`已导入 ${result.records} 条目录/计划、${result.scores} 条分数线${result.indexed_schools ? `,${result.indexed_schools} 所院校索引` : ""}`);
|
||||
notify(
|
||||
`已导入 ${result.records} 条目录/计划、${result.scores} 条分数线${result.indexed_schools ? `,${result.indexed_schools} 所院校索引` : ""}`,
|
||||
);
|
||||
done();
|
||||
close();
|
||||
} catch (e) {
|
||||
@@ -996,8 +1004,8 @@ function ImportDialog({
|
||||
</label>
|
||||
<div className="info-box">
|
||||
文件本身有年份时使用文件年份。yzw CSV 和 YAM
|
||||
无年份目录必须明确填写;分数线仍保留其原始年份。
|
||||
无详情的 YAM 种子仅导入院校索引。
|
||||
无年份目录必须明确填写;分数线仍保留其原始年份。 无详情的 YAM
|
||||
种子仅导入院校索引。
|
||||
</div>
|
||||
<button className="primary" disabled={busy || !file}>
|
||||
{busy ? <Loader2 className="spin" size={17} /> : <FileUp size={17} />}
|
||||
@@ -1594,33 +1602,43 @@ function Tasks({ overview, majors, notify, refresh }: Shared) {
|
||||
|
||||
function ProxyPanel({ notify }: { notify: Notify }) {
|
||||
const [data, setData] = useState<Proxy | null>(null),
|
||||
[services, setServices] = useState<PoolServiceStatus | null>(null),
|
||||
[busy, setBusy] = useState(false),
|
||||
[output, setOutput] = useState("");
|
||||
const load = useCallback(
|
||||
async () => setData(await api<Proxy>("/proxy?refresh=true")),
|
||||
[],
|
||||
);
|
||||
const loadServices = useCallback(
|
||||
async () => setServices(await api<PoolServiceStatus>("/proxy/services")),
|
||||
[],
|
||||
);
|
||||
useEffect(() => {
|
||||
load().catch((e) => notify(e.message, true));
|
||||
}, [load, notify]);
|
||||
Promise.all([load(), loadServices()]).catch((e) => notify(e.message, true));
|
||||
}, [load, loadServices, notify]);
|
||||
async function operate(action: string) {
|
||||
setBusy(true);
|
||||
try {
|
||||
if (action === "rotate") {
|
||||
setData(await post<Proxy>("/proxy/rotate"));
|
||||
notify("已切换当前路由");
|
||||
} else if (action === "refresh") await load();
|
||||
} else if (action === "refresh")
|
||||
await Promise.all([load(), loadServices()]);
|
||||
else {
|
||||
const result = await post<{ output: string; ok: boolean }>(
|
||||
"/proxy/manage",
|
||||
{ action },
|
||||
);
|
||||
setOutput(result.output);
|
||||
const result = await post<PoolManageResult>("/proxy/manage", {
|
||||
action,
|
||||
});
|
||||
setServices(result.status);
|
||||
setOutput(action === "status" ? "" : result.output);
|
||||
notify(
|
||||
result.ok ? "代理池操作完成" : "代理池返回异常,请查看输出",
|
||||
result.ok
|
||||
? result.message
|
||||
: result.status.warning
|
||||
? "服务操作受限,请查看下方说明"
|
||||
: result.message,
|
||||
!result.ok,
|
||||
);
|
||||
await load();
|
||||
if (result.changed) await load();
|
||||
}
|
||||
} catch (e) {
|
||||
notify((e as Error).message, true);
|
||||
@@ -1730,8 +1748,46 @@ function ProxyPanel({ notify }: { notify: Notify }) {
|
||||
</div>
|
||||
</section>
|
||||
<section className="card pool-controls">
|
||||
<h2>本机代理池服务</h2>
|
||||
<p>通过现有项目的 manage.ps1 控制 Redis、API 与抓取调度器。</p>
|
||||
<div className="card-title">
|
||||
<h2>本机代理池服务</h2>
|
||||
<Badge tone={services?.api_ready ? "green" : ""}>
|
||||
{services
|
||||
? services.api_ready
|
||||
? "API 正常"
|
||||
: "API 未响应"
|
||||
: "正在查询"}
|
||||
</Badge>
|
||||
</div>
|
||||
<p>查看 API、代理抓取与检测、Redis 的运行状态,管理本机服务。</p>
|
||||
{services && (
|
||||
<ul className="pool-service-list">
|
||||
{services.items.map((service) => (
|
||||
<li key={service.name}>
|
||||
<div>
|
||||
<strong>{service.label}</strong>
|
||||
{service.pid && <small>PID {service.pid}</small>}
|
||||
</div>
|
||||
<Badge
|
||||
tone={
|
||||
["running", "restricted", "external"].includes(
|
||||
service.state,
|
||||
)
|
||||
? service.state === "restricted"
|
||||
? "amber"
|
||||
: "green"
|
||||
: ["conflict", "invalid", "unknown"].includes(
|
||||
service.state,
|
||||
)
|
||||
? "red"
|
||||
: ""
|
||||
}
|
||||
>
|
||||
{service.detail}
|
||||
</Badge>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<div className="button-group">
|
||||
<button disabled={busy} onClick={() => operate("start")}>
|
||||
<Play size={15} />
|
||||
@@ -1740,7 +1796,15 @@ function ProxyPanel({ notify }: { notify: Notify }) {
|
||||
<button disabled={busy} onClick={() => operate("status")}>
|
||||
检查状态
|
||||
</button>
|
||||
<button disabled={busy} onClick={() => operate("stop")}>
|
||||
<button
|
||||
disabled={busy || !services?.can_stop}
|
||||
title={
|
||||
services?.can_stop
|
||||
? "停止本项目管理的代理池服务"
|
||||
: services?.warning || "没有可停止的本项目服务"
|
||||
}
|
||||
onClick={() => operate("stop")}
|
||||
>
|
||||
<Square size={14} />
|
||||
停止
|
||||
</button>
|
||||
@@ -1751,7 +1815,18 @@ function ProxyPanel({ notify }: { notify: Notify }) {
|
||||
正在处理…
|
||||
</p>
|
||||
)}
|
||||
{output && <pre className="service-output">{output}</pre>}
|
||||
{services?.warning && (
|
||||
<div className="info-box warning service-warning">
|
||||
<p>{services.warning}</p>
|
||||
{services.admin_command && <code>{services.admin_command}</code>}
|
||||
</div>
|
||||
)}
|
||||
{output && (
|
||||
<details className="pool-service-log">
|
||||
<summary>查看操作输出</summary>
|
||||
<pre className="service-output">{output}</pre>
|
||||
</details>
|
||||
)}
|
||||
<div className="info-box">
|
||||
切换 IP
|
||||
保留原代理;连接失败仅在本次工作台运行中隔离。代理池的持续可用性由其检测服务维护。
|
||||
|
||||
Reference in New Issue
Block a user