From 2239f1fd4a03a78ba163591ab56ea39e1e54e673 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 21 May 2024 11:36:27 +0300 Subject: [PATCH] Revert IPerf changes in Node Finder --- .../node_details_cards/card_details.vue | 6 ++-- .../node_details_cards/iperf_details_card.vue | 35 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/playground/src/components/node_details_cards/card_details.vue b/packages/playground/src/components/node_details_cards/card_details.vue index 35ac452f2e..3e191f50fd 100644 --- a/packages/playground/src/components/node_details_cards/card_details.vue +++ b/packages/playground/src/components/node_details_cards/card_details.vue @@ -19,14 +19,14 @@ -

{{ item.name }}

+

{{ item.name }}/{{ item.type }}

- {{ item.uploadSpeed }} + {{ item.uploadSpeed }}
- {{ item.downloadSpeed }} + {{ item.downloadSpeed }}
diff --git a/packages/playground/src/components/node_details_cards/iperf_details_card.vue b/packages/playground/src/components/node_details_cards/iperf_details_card.vue index b557727e56..3f8cfe6407 100644 --- a/packages/playground/src/components/node_details_cards/iperf_details_card.vue +++ b/packages/playground/src/components/node_details_cards/iperf_details_card.vue @@ -15,7 +15,7 @@ import { onMounted, type PropType, ref } from "vue"; import type { NodeDetailsCard } from "@/types"; -import { gridProxyClient } from "../../clients"; +import { useGrid } from "../../stores"; import formatResourceSize from "../../utils/format_resource_size"; import CardDetails from "./card_details.vue"; @@ -30,6 +30,7 @@ export default { }, setup(props) { + const gridStore = useGrid(); const loading = ref(false); const IperfDetails = ref(); const errorMessage = ref(""); @@ -49,23 +50,29 @@ export default { }); function format(speed: number) { - return formatResourceSize(speed, true).toLocaleLowerCase() + "ps" || "-"; + return formatResourceSize(speed) + "/s" || "-"; + } + function isIPv4(ip: string) { + const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/; + return ipv4Regex.test(ip); } - const getNodeIPerfCard = async (): Promise => { - const { speed } = await gridProxyClient.nodes.byId(props.node.nodeId); - const upload = format(speed.upload); - const download = format(speed.download); - IperfDetails.value = [ - { - name: "Speed", - uploadSpeed: upload, - downloadSpeed: download, - }, - ]; + const res = await gridStore.grid.zos.getNodeIPerfTest({ nodeId: props.node.nodeId }); + // filter the returned result to show node other than the one being tested against + const array = res.result + .filter( + (node: any) => node.download_speed && node.upload_speed && !node.error && node.node_id !== props.node.nodeId, + ) + .slice(0, 4) + .map((node: any) => ({ + name: node.test_type.toLocaleUpperCase(), + type: isIPv4(node.node_ip) ? "IPv4" : "IPv6", + downloadSpeed: format(node.download_speed), + uploadSpeed: format(node.upload_speed), + })); + IperfDetails.value = array; return IperfDetails.value; }; - return { IperfDetails, loading,