增加测速

This commit is contained in:
2025-08-08 21:03:01 +08:00
parent 18c5d72634
commit f5e326bde7
3 changed files with 132 additions and 29 deletions

View File

@@ -786,6 +786,26 @@ const CreateStationDialog: React.FC<{
</SelectContent>
</Select>
</div>
<Button
type="button"
variant="outline"
onClick={async () => {
setFormToast({ message: "正在测速,请稍候...", type: "success" });
try {
const best = await api.autoSelectBestNode();
setPackycodeNode(best.url);
setFormData(prev => ({ ...prev, api_url: best.url }));
setFormToast({
message: `已选择最快节点: ${best.name} (延迟: ${best.response_time}ms)`,
type: "success"
});
} catch (error) {
setFormToast({ message: "节点测速失败", type: "error" });
}
}}
>
</Button>
</div>
<p className="text-xs text-muted-foreground">
@@ -1163,6 +1183,26 @@ const EditStationDialog: React.FC<{
</SelectContent>
</Select>
</div>
<Button
type="button"
variant="outline"
onClick={async () => {
setFormToast({ message: "正在测速,请稍候...", type: "success" });
try {
const best = await api.autoSelectBestNode();
setPackycodeNode(best.url);
setFormData(prev => ({ ...prev, api_url: best.url }));
setFormToast({
message: `已选择最快节点: ${best.name} (延迟: ${best.response_time}ms)`,
type: "success"
});
} catch (error) {
setFormToast({ message: "节点测速失败", type: "error" });
}
}}
>
</Button>
</div>
<p className="text-xs text-muted-foreground">

View File

@@ -2349,12 +2349,11 @@ export const api = {
/**
* Tests all PackyCode nodes and returns speed test results
* @param token - API token for authentication
* @returns Promise resolving to array of node speed test results
*/
async testAllPackycodeNodes(token: string): Promise<NodeSpeedTestResult[]> {
async testAllPackycodeNodes(): Promise<NodeSpeedTestResult[]> {
try {
return await invoke<NodeSpeedTestResult[]>("test_all_packycode_nodes", { token });
return await invoke<NodeSpeedTestResult[]>("test_all_packycode_nodes");
} catch (error) {
console.error("Failed to test PackyCode nodes:", error);
throw error;
@@ -2363,12 +2362,11 @@ export const api = {
/**
* Automatically selects the best PackyCode node based on speed
* @param token - API token for authentication
* @returns Promise resolving to the best node
*/
async autoSelectBestNode(token: string): Promise<PackycodeNode> {
async autoSelectBestNode(): Promise<PackycodeNode> {
try {
return await invoke<PackycodeNode>("auto_select_best_node", { token });
return await invoke<PackycodeNode>("auto_select_best_node");
} catch (error) {
console.error("Failed to auto-select best node:", error);
throw error;