This commit is contained in:
2025-11-16 13:32:35 +08:00
parent e35712820f
commit 2c800d336c
11 changed files with 414 additions and 18 deletions

View File

@@ -1,10 +1,8 @@
const baseURLv4 = 'https://4.ipw.cn/';
const baseURLv6 = 'https://6.ipw.cn/';
import { app } from './app.ts';
app.route({
path: 'ip',
key: 'v4',
@@ -12,7 +10,7 @@ app.route({
}).define(async (ctx) => {
const response = await fetch(baseURLv4);
const ip = (await response.text()).trim();
if(!isIpv4(ip)) {
if (!isIpv4(ip)) {
ctx.throw?.('获取地址失败');
}
ctx.body = { ip };
@@ -25,7 +23,7 @@ app.route({
}).define(async (ctx) => {
const response = await fetch(baseURLv6);
const ip = (await response.text()).trim();
if(!isIpv6(ip)) {
if (!isIpv6(ip)) {
ctx.throw?.('获取地址失败');
}
ctx.body = { ip };
@@ -38,4 +36,5 @@ export const isIpv6 = (ip: string): boolean => {
export const isIpv4 = (ip: string): boolean => {
return ip.split('.').length === 4;
}
}