From 2a367a9764160da42b93dd1ae739bff0700220fb Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Tue, 14 May 2024 00:50:07 +0800 Subject: [PATCH 1/8] Improvements --- frontend/{ => locales}/i18n.js | 6 +++--- frontend/main.js | 4 ++-- frontend/{ => style}/style.css | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename frontend/{ => locales}/i18n.js (91%) rename frontend/{ => style}/style.css (98%) diff --git a/frontend/i18n.js b/frontend/locales/i18n.js similarity index 91% rename from frontend/i18n.js rename to frontend/locales/i18n.js index 5a02971a..c67fe33c 100644 --- a/frontend/i18n.js +++ b/frontend/locales/i18n.js @@ -1,9 +1,9 @@ import { createI18n } from 'vue-i18n'; -import en from './locales/en.json'; -import zh from './locales/zh.json'; -import fr from './locales/fr.json'; +import en from './en.json'; +import zh from './zh.json'; +import fr from './fr.json'; const messages = { en, zh, fr }; diff --git a/frontend/main.js b/frontend/main.js index 6ed5e443..a9bca437 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -2,13 +2,13 @@ import { createApp } from 'vue' import { createPinia } from 'pinia'; import { useMainStore } from './store'; import App from './App.vue' -import i18n from './i18n'; +import i18n from './locales/i18n'; import router from './router'; import { analytics } from './utils/use-analytics'; import { Tooltip } from 'bootstrap'; import { detectOS } from './utils/system-detect'; -import './style.css' +import './style/style.css' const app = createApp(App); const pinia = createPinia(); diff --git a/frontend/style.css b/frontend/style/style.css similarity index 98% rename from frontend/style.css rename to frontend/style/style.css index c114de0b..cc463931 100644 --- a/frontend/style.css +++ b/frontend/style/style.css @@ -1,5 +1,5 @@ @import 'bootstrap/dist/css/bootstrap.min.css'; -@import 'bootstrap-icons/font/bootstrap-icons.css'; +@import 'bootstrap-icons/font/bootstrap-icons.min.css'; @import 'flag-icons/css/flag-icons.min.css'; .jn-title { From 63f85a5c939476d93c78d4689167e8fbe2878162 Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Tue, 14 May 2024 20:38:07 +0800 Subject: [PATCH 2/8] Bug Fixed --- .../advanced-tools/InvisibilityTest.vue | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/components/advanced-tools/InvisibilityTest.vue b/frontend/components/advanced-tools/InvisibilityTest.vue index f3bb008e..bbedbb13 100644 --- a/frontend/components/advanced-tools/InvisibilityTest.vue +++ b/frontend/components/advanced-tools/InvisibilityTest.vue @@ -278,6 +278,7 @@ const errorMsg = ref(''); const testResults = ref({}); const userID = ref(''); const isAgreed = ref(false); +const retryCount = ref(0); // 生成28位字符串 const generate28DigitString = () => { @@ -320,12 +321,12 @@ const onSubmit = () => { loadScript(); setTimeout(() => { - getResult(userID.value, 0); + getResult(); }, 6000); }; // 获取测试结果 -const getResult = async (retryCount = 0) => { +const getResult = async () => { try { const response = await fetch(`/api/invisibility?id=${userID.value}`); if (!response.ok) { @@ -334,20 +335,19 @@ const getResult = async (retryCount = 0) => { const data = await response.json(); // 检查并重试 - if (data.message === "Data not found" && retryCount < 3) { - console.log(`Data not found, retrying... (${retryCount + 1})`); + if (data.message === "Data not found" && retryCount.value < 3) { setTimeout(() => { - getResult(retryCount + 1); - }, 4000); + getResult(); + }, 4000, retryCount.value++ ); return; } testResults.value = data; } catch (error) { console.error('Error fetching InvisibilityTest results:', error); - if (retryCount < 3) { + if (retryCount.value < 3) { setTimeout(() => { - getResult(retryCount + 1); - }, 4000); + getResult(); + }, 4000, retryCount.value + 1); return; } else { errorMsg.value = t('invisibilitytest.fetchError'); @@ -356,6 +356,7 @@ const getResult = async (retryCount = 0) => { removeScript(); } checkingStatus.value = 'idle'; + retryCount.value = 0; }; From 612feb3829c966d046f68cac142d77d4f3be29e2 Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Tue, 14 May 2024 21:16:37 +0800 Subject: [PATCH 3/8] format asn info in BE --- api/cfradar.js | 28 +++++++++++++++++++++++++++- frontend/components/IpInfos.vue | 20 ++++---------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/api/cfradar.js b/api/cfradar.js index 1e4df3a6..61b060bd 100644 --- a/api/cfradar.js +++ b/api/cfradar.js @@ -1,4 +1,5 @@ +import { parse } from 'dotenv'; import { refererCheck } from '../lib/referer-check.js'; // 创建一个用于设置 headers 的通用函数 @@ -91,6 +92,30 @@ function isValidASN(asn) { return /^[0-9]+$/.test(asn); }; + +// 格式化输出 + +function formatData(data) { + const { asnName, asnOrgName, estimatedUsers, IPv4_Pct, IPv6_Pct, HTTP_Pct, HTTPS_Pct, Desktop_Pct, Mobile_Pct, Bot_Pct, Human_Pct } = data; + const formattedData = { + asnName, + asnOrgName, + estimatedUsers: parseFloat(estimatedUsers).toLocaleString(), + IPv4_Pct: `${parseFloat(IPv4_Pct).toFixed(2)}%`, + IPv6_Pct: `${parseFloat(IPv6_Pct).toFixed(2)}%`, + HTTP_Pct: `${parseFloat(HTTP_Pct).toFixed(2)}%`, + HTTPS_Pct: `${parseFloat(HTTPS_Pct).toFixed(2)}%`, + Desktop_Pct: `${parseFloat(Desktop_Pct).toFixed(2)}%`, + Mobile_Pct: `${parseFloat(Mobile_Pct).toFixed(2)}%`, + Bot_Pct: `${parseFloat(Bot_Pct).toFixed(2)}%`, + Human_Pct: `${parseFloat(Human_Pct).toFixed(2)}%` + }; + + return formattedData; + +} + + // 导出函数 export default async (req, res) => { @@ -140,8 +165,9 @@ export default async (req, res) => { } const cleanedResponse = cleanUpResponseData(response); + const finalResponse = formatData(cleanedResponse); - res.json(cleanedResponse); + res.json(finalResponse); } catch (error) { console.error(error); res.status(500).json({ error: 'Internal server error' }); diff --git a/frontend/components/IpInfos.vue b/frontend/components/IpInfos.vue index 030e4739..e614cd65 100644 --- a/frontend/components/IpInfos.vue +++ b/frontend/components/IpInfos.vue @@ -154,11 +154,11 @@ {{ t('ipInfos.ASNInfo.note') }}
-