github-actions[bot]
commited on
Commit
·
f83effb
1
Parent(s):
0b827be
Update from GitHub Actions
Browse files- functions/api/ip.ts +94 -0
- index.ts +5 -1
- src/App.vue +25 -2
- src/services/ipApi.ts +21 -0
functions/api/ip.ts
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* 从多个外部服务获取服务器IP地址
|
3 |
+
*/
|
4 |
+
async function getServerIP(): Promise<string> {
|
5 |
+
// 尝试多个IP查询服务,按顺序尝试,直到成功获取IP
|
6 |
+
const ipServices = [
|
7 |
+
'https://api.ipify.org?format=json',
|
8 |
+
'https://api.ip.sb/ip',
|
9 |
+
'https://api4.my-ip.io/ip.json',
|
10 |
+
'https://ipinfo.io/json'
|
11 |
+
];
|
12 |
+
|
13 |
+
for (const service of ipServices) {
|
14 |
+
try {
|
15 |
+
const response = await fetch(service, {
|
16 |
+
method: 'GET',
|
17 |
+
headers: {
|
18 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
19 |
+
}
|
20 |
+
});
|
21 |
+
|
22 |
+
if (!response.ok) {
|
23 |
+
continue; // 尝试下一个服务
|
24 |
+
}
|
25 |
+
|
26 |
+
const contentType = response.headers.get('content-type');
|
27 |
+
|
28 |
+
if (contentType && contentType.includes('application/json')) {
|
29 |
+
const data = await response.json() as Record<string, any>;
|
30 |
+
// 不同服务返回格式不同,需要适配
|
31 |
+
if (data.ip) return data.ip;
|
32 |
+
if (data.query) return data.query;
|
33 |
+
if (data.YourFuckingIPAddress) return data.YourFuckingIPAddress;
|
34 |
+
if (data.address) return data.address;
|
35 |
+
} else {
|
36 |
+
// 纯文本响应
|
37 |
+
const ip = await response.text();
|
38 |
+
return ip.trim();
|
39 |
+
}
|
40 |
+
} catch (error) {
|
41 |
+
console.error(`从 ${service} 获取IP失败:`, error);
|
42 |
+
// 继续尝试下一个服务
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
return 'Unknown'; // 所有服务都失败时返回
|
47 |
+
}
|
48 |
+
|
49 |
+
export const onRequest = async (context: RouteContext): Promise<Response> => {
|
50 |
+
const request = context.request;
|
51 |
+
|
52 |
+
try {
|
53 |
+
// 获取客户端IP(来自请求头)
|
54 |
+
const clientIP = request.headers.get('CF-Connecting-IP') ||
|
55 |
+
request.headers.get('X-Forwarded-For') ||
|
56 |
+
request.headers.get('X-Real-IP') ||
|
57 |
+
'Unknown';
|
58 |
+
|
59 |
+
// 获取服务器主机名
|
60 |
+
const hostname = request.headers.get('Host') || 'Unknown';
|
61 |
+
|
62 |
+
// 从外部服务获取服务器的公网IP
|
63 |
+
const serverIP = await getServerIP();
|
64 |
+
|
65 |
+
return new Response(
|
66 |
+
JSON.stringify({
|
67 |
+
success: true,
|
68 |
+
data: {
|
69 |
+
clientIP: clientIP,
|
70 |
+
serverIP: serverIP,
|
71 |
+
hostname: hostname,
|
72 |
+
serverTime: new Date().toISOString()
|
73 |
+
}
|
74 |
+
}),
|
75 |
+
{
|
76 |
+
status: 200,
|
77 |
+
headers: { 'Content-Type': 'application/json' }
|
78 |
+
}
|
79 |
+
);
|
80 |
+
} catch (error) {
|
81 |
+
console.error(`获取IP地址失败:`, error);
|
82 |
+
|
83 |
+
return new Response(
|
84 |
+
JSON.stringify({
|
85 |
+
success: false,
|
86 |
+
error: 'Failed to get IP address'
|
87 |
+
}),
|
88 |
+
{
|
89 |
+
status: 500,
|
90 |
+
headers: { 'Content-Type': 'application/json' }
|
91 |
+
}
|
92 |
+
);
|
93 |
+
}
|
94 |
+
}
|
index.ts
CHANGED
@@ -19,6 +19,7 @@ import { get_access_token, getEmails } from './functions/utils/mail.js'
|
|
19 |
import { onRequest as handleAccount } from './functions/api/account.js'
|
20 |
import { onRequest as handleLogin } from './functions/api/login.js'
|
21 |
import { onRequest as handleSetting } from './functions/api/setting.js'
|
|
|
22 |
import { onRequest as handleMailAuth } from './functions/api/mail/auth.js'
|
23 |
import { onRequest as handleMailCallback } from './functions/api/mail/callback.js'
|
24 |
import { onRequest as handleMailAll } from './functions/api/mail/all.js'
|
@@ -135,6 +136,9 @@ app.all('/api/*', async (c) => {
|
|
135 |
case '/api/setting':
|
136 |
response = await handleSetting(context);
|
137 |
break;
|
|
|
|
|
|
|
138 |
case '/api/mail/auth':
|
139 |
response = await handleMailAuth(context);
|
140 |
break;
|
@@ -252,7 +256,7 @@ async function checkEmailsForNewMessages(env: Env) {
|
|
252 |
|
253 |
// 更新检查时间
|
254 |
monitor.lastCheckTime = currentTime;
|
255 |
-
|
256 |
|
257 |
// 获取最新邮件的时间戳
|
258 |
const latestEmailTime = new Date(latestEmail.date.received || latestEmail.date.created || latestEmail.date.sent || latestEmail.date.modified).getTime();
|
|
|
19 |
import { onRequest as handleAccount } from './functions/api/account.js'
|
20 |
import { onRequest as handleLogin } from './functions/api/login.js'
|
21 |
import { onRequest as handleSetting } from './functions/api/setting.js'
|
22 |
+
import { onRequest as handleIP } from './functions/api/ip.js'
|
23 |
import { onRequest as handleMailAuth } from './functions/api/mail/auth.js'
|
24 |
import { onRequest as handleMailCallback } from './functions/api/mail/callback.js'
|
25 |
import { onRequest as handleMailAll } from './functions/api/mail/all.js'
|
|
|
136 |
case '/api/setting':
|
137 |
response = await handleSetting(context);
|
138 |
break;
|
139 |
+
case '/api/ip':
|
140 |
+
response = await handleIP(context);
|
141 |
+
break;
|
142 |
case '/api/mail/auth':
|
143 |
response = await handleMailAuth(context);
|
144 |
break;
|
|
|
256 |
|
257 |
// 更新检查时间
|
258 |
monitor.lastCheckTime = currentTime;
|
259 |
+
|
260 |
|
261 |
// 获取最新邮件的时间戳
|
262 |
const latestEmailTime = new Date(latestEmail.date.received || latestEmail.date.created || latestEmail.date.sent || latestEmail.date.modified).getTime();
|
src/App.vue
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
<script setup lang="ts">
|
2 |
import { useRoute, useRouter } from 'vue-router';
|
3 |
-
import { ref } from 'vue';
|
4 |
import logo from './assets/logo.png'
|
|
|
|
|
5 |
const router = useRouter();
|
6 |
const route = useRoute();
|
7 |
const menuVisible = ref(false);
|
|
|
8 |
|
9 |
const menu = [
|
10 |
{
|
@@ -33,6 +36,23 @@ const toggleMenu = () => {
|
|
33 |
menuVisible.value = !menuVisible.value;
|
34 |
};
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
//解析token
|
38 |
const parseToken = () => {
|
@@ -131,7 +151,10 @@ const jwtToken = parseToken();
|
|
131 |
|
132 |
<!-- 页脚 -->
|
133 |
<t-footer class="footer backdrop-blur-sm py-4 text-center text-sm text-gray-600">
|
134 |
-
<
|
|
|
|
|
|
|
135 |
</t-footer>
|
136 |
</t-layout>
|
137 |
|
|
|
1 |
<script setup lang="ts">
|
2 |
import { useRoute, useRouter } from 'vue-router';
|
3 |
+
import { ref, onMounted } from 'vue';
|
4 |
import logo from './assets/logo.png'
|
5 |
+
import { ipApi } from './services/ipApi';
|
6 |
+
|
7 |
const router = useRouter();
|
8 |
const route = useRoute();
|
9 |
const menuVisible = ref(false);
|
10 |
+
const serverIP = ref('');
|
11 |
|
12 |
const menu = [
|
13 |
{
|
|
|
36 |
menuVisible.value = !menuVisible.value;
|
37 |
};
|
38 |
|
39 |
+
// 获取服务器IP
|
40 |
+
const fetchServerIP = async () => {
|
41 |
+
try {
|
42 |
+
const serverInfo = await ipApi.getServerInfo();
|
43 |
+
serverIP.value = serverInfo.serverIP;
|
44 |
+
} catch (error) {
|
45 |
+
console.error('获取服务器IP失败:', error);
|
46 |
+
serverIP.value = '获取失败';
|
47 |
+
}
|
48 |
+
};
|
49 |
+
|
50 |
+
// 组件挂载时获取服务器IP
|
51 |
+
onMounted(() => {
|
52 |
+
if (route.path !== '/login') {
|
53 |
+
fetchServerIP();
|
54 |
+
}
|
55 |
+
});
|
56 |
|
57 |
//解析token
|
58 |
const parseToken = () => {
|
|
|
151 |
|
152 |
<!-- 页脚 -->
|
153 |
<t-footer class="footer backdrop-blur-sm py-4 text-center text-sm text-gray-600">
|
154 |
+
<div class="flex flex-col items-center gap-1">
|
155 |
+
<span class="opacity-75">© 微软邮箱管理系统</span>
|
156 |
+
<span v-if="serverIP" class="text-xs opacity-60">服务器IP: {{ serverIP }}</span>
|
157 |
+
</div>
|
158 |
</t-footer>
|
159 |
</t-layout>
|
160 |
|
src/services/ipApi.ts
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { API_BASE_URL, getHeaders, handleResponse } from './util';
|
2 |
+
|
3 |
+
export interface ServerInfo {
|
4 |
+
clientIP: string;
|
5 |
+
serverIP: string;
|
6 |
+
hostname: string;
|
7 |
+
serverTime: string;
|
8 |
+
}
|
9 |
+
|
10 |
+
export const ipApi = {
|
11 |
+
async getServerInfo(): Promise<ServerInfo> {
|
12 |
+
const response = await fetch(
|
13 |
+
`${API_BASE_URL}/api/ip`,
|
14 |
+
{
|
15 |
+
headers: getHeaders()
|
16 |
+
}
|
17 |
+
);
|
18 |
+
const result = await handleResponse(response);
|
19 |
+
return result.data;
|
20 |
+
}
|
21 |
+
};
|