Skip to content

Commit f183176

Browse files
committed
Improvements
1 parent 0c1a652 commit f183176

8 files changed

Lines changed: 40 additions & 74 deletions

File tree

‎api/ipchecking.js‎

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { get } from 'https';
21
import { isValidIP } from '../common/valid-ip.js';
32
import { refererCheck } from '../common/referer-check.js';
4-
import verifyToken from '../common/verify-token.js';
53

64
export default async (req, res) => {
75

@@ -11,10 +9,6 @@ export default async (req, res) => {
119
return res.status(403).json({ error: referer ? 'Access denied' : 'What are you doing?' });
1210
}
1311

14-
// 验证用户 Token
15-
const { isValid, email } = await verifyToken(req);
16-
const isValidUser = isValid;
17-
1812
// 从请求中获取 IP 地址
1913
const ipAddress = req.query.ip;
2014
if (!ipAddress) {
@@ -34,39 +28,24 @@ export default async (req, res) => {
3428

3529
const lang = req.query.lang || 'en';
3630

37-
// 构建请求 IPCheck.ing 的 URL
38-
const url = new URL(`https://api.ipcheck.ing/ipinfo?key=${key}&ip=${ipAddress}&lang=${lang}&email=${email}`);
39-
40-
get(url, apiRes => {
41-
let data = '';
42-
apiRes.on('data', chunk => data += chunk);
43-
apiRes.on('end', () => {
44-
try {
45-
const originalJson = JSON.parse(data);
46-
if (isValidUser) {
47-
res.json(originalJson);
48-
} else {
49-
const modifiedJson = modifyJsonForIPChecking(originalJson);
50-
res.json(modifiedJson);
51-
}
31+
// 构建请求
32+
const url = new URL(`https://api.ipcheck.ing/ipinfo?key=${key}&ip=${ipAddress}&lang=${lang}`);
5233

53-
} catch (e) {
54-
res.status(500).json({ error: 'Error parsing JSON' });
34+
try {
35+
const apiResponse = await fetch(url, {
36+
headers: {
37+
...req.headers,
5538
}
5639
});
57-
}).on('error', (e) => {
58-
res.status(500).json({ error: e.message });
59-
});
60-
}
6140

62-
// 修改返回的数据
63-
function modifyJsonForIPChecking(json) {
64-
const modifiedJson = JSON.parse(JSON.stringify(json));
65-
if (modifiedJson.proxyDetect) {
66-
for (const key in modifiedJson.proxyDetect) {
67-
modifiedJson.proxyDetect[key] = "sign_in_required";
41+
if (!apiResponse.ok) {
42+
throw new Error(`API responded with status: ${apiResponse.status}`);
6843
}
69-
}
7044

71-
return modifiedJson;
45+
const data = await apiResponse.json();
46+
res.json(data);
47+
} catch (error) {
48+
console.error("Error during API request:", error);
49+
res.status(500).json({ error: error.message });
50+
}
7251
}

‎backend-server.js‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ import ipapiisHandler from './api/ipapiis.js';
1919
import invisibilitytestHandler from './api/invisibilitytest.js';
2020
import macChecker from './api/macchecker.js';
2121
import maxmindHandler from './api/maxmind.js';
22-
import admin from 'firebase-admin';
2322

2423
dotenv.config();
2524

26-
const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);
27-
admin.initializeApp({
28-
credential: admin.credential.cert(serviceAccount),
29-
});
30-
3125
const app = express();
3226
const backEndPort = parseInt(process.env.BACKEND_PORT || 11966, 10);
3327
const blackListIPLogFilePath = process.env.SECURITY_BLACKLIST_LOG_FILE_PATH || 'logs/blacklist-ip.log';

‎common/verify-token.js‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎frontend/components/Nav.vue‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</div>
5252

5353
<!-- Sign In -->
54-
<div id="signin" class="d-flex align-items-center ms-2">
54+
<div v-if="isFireBaseSet" id="signin" class="d-flex align-items-center ms-2">
5555

5656
<div class="dropstart">
5757
<button class="btn dropdown-toggle d-flex align-items-center flex-row jn-fs"
@@ -70,8 +70,6 @@
7070
<ul class="dropdown-menu" :data-bs-theme="isDarkMode ? 'dark' : ''">
7171
<li v-if="!store.user"><a type="button" class="dropdown-item" @click="store.signInWithGoogle"><i
7272
class="bi bi-google"></i> {{ t('user.SignInWithGoogle') }}</a></li>
73-
<li v-if="!store.user"><a type="button" class="dropdown-item" @click="store.signInWithGithub"><i
74-
class="bi bi-github"></i> {{ t('user.SignInWithGithub') }}</a></li>
7573
<li v-if="store.user"><a type="button" class="dropdown-item" @click="store.signOut">{{ t('user.SignOut')
7674
}}</a></li>
7775
<li>
@@ -152,6 +150,7 @@ const isMobile = computed(() => store.isMobile);
152150
const loaded = ref(false);
153151
154152
const currentSection = computed(() => store.currentSection);
153+
const isFireBaseSet = computed(() => store.isFireBaseSet);
155154
156155
// 打开偏好设置
157156
const OpenPreferences = () => {

‎frontend/firebase-init.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { initializeApp } from "firebase/app";
33
import { getAuth } from "firebase/auth";
44

5+
let auth;
56
const firebaseConfig = {
67
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
78
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
89
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
910
};
1011

12+
const isFireBaseSet = !!firebaseConfig.apiKey && !!firebaseConfig.authDomain && !!firebaseConfig.projectId;
13+
14+
if (isFireBaseSet) {
15+
1116
const app = initializeApp(firebaseConfig);
12-
const auth = getAuth(app);
17+
auth = getAuth(app);
18+
19+
} else {
20+
auth = null;
21+
}
1322

1423
export { auth };

‎frontend/main.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ handleResize();
3939
// 监听窗口大小变化
4040
window.addEventListener('resize', handleResize);
4141

42-
// 检查 Firebase 登录环境变量是否存在
43-
const isFireBaseSet = import.meta.env.VITE_FIREBASE_API_KEY && import.meta.env.VITE_FIREBASE_AUTH_DOMAIN && import.meta.env.VITE_FIREBASE_PROJECT_ID;
44-
4542
// 启动 Google Analytics
4643
analytics.page();
4744
app.config.globalProperties.$analytics = analytics;
@@ -83,9 +80,12 @@ app.directive('tooltip', {
8380
}
8481
})
8582

83+
// 检查 Firebase 环境
84+
store.checkFirebaseEnv();
85+
8686
// 获取后端配置和用户偏好
8787
Promise.all([
88-
isFireBaseSet ? store.initializeAuthListener() : Promise.resolve(),
88+
store.isFireBaseSet ? store.initializeAuthListener() : Promise.resolve(),
8989
store.loadPreferences(), // 加载用户偏好设置
9090
store.fetchConfigs() // 获取后端配置
9191
]).then(() => {

‎frontend/store.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const useMainStore = defineStore('main', {
2222
ipv6Domain: import.meta.env.VITE_CURL_IPV6_DOMAIN,
2323
ipv64Domain: import.meta.env.VITE_CURL_IPV64_DOMAIN,
2424
},
25+
isFireBaseSet: false,
2526
loadingStatus: {
2627
ipcheck: false,
2728
connectivity: false,
@@ -165,6 +166,15 @@ export const useMainStore = defineStore('main', {
165166
changeSection(section) {
166167
this.currentSection = section;
167168
},
169+
// 检查 Firebase 环境
170+
checkFirebaseEnv() {
171+
const envConfigs = {
172+
key: import.meta.env.VITE_FIREBASE_API_KEY,
173+
domain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
174+
project: import.meta.env.VITE_FIREBASE_PROJECT_ID,
175+
}
176+
this.isFireBaseSet = !!envConfigs.key && !!envConfigs.domain && !!envConfigs.project;
177+
},
168178
// 通过 Google 登录
169179
async signInWithGoogle() {
170180
const provider = new GoogleAuthProvider();
@@ -177,8 +187,6 @@ export const useMainStore = defineStore('main', {
177187
console.error("Google sign-in failed:", error);
178188
}
179189
},
180-
181-
182190
// 通过 GitHub 登录
183191
async signInWithGithub() {
184192
const provider = new GithubAuthProvider();

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"express-rate-limit": "^7.5.0",
3030
"express-slow-down": "^2.0.3",
3131
"firebase": "^11.2.0",
32-
"firebase-admin": "^13.0.2",
3332
"flag-icons": "^7.3.2",
3433
"http-proxy-middleware": "^3.0.3",
3534
"maxmind": "^4.3.23",

0 commit comments

Comments
 (0)