Skip to content

Commit b876f5d

Browse files
authored
Merge pull request #22 from PaiJi/fix-request-ip-not-pure
fix: fix ip string isn't pure
2 parents 97708a9 + 8d316a7 commit b876f5d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/pages/Requests/components/RequestModal.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from 'react'
1+
import React, { useCallback, useMemo } from 'react'
22
import { toast } from 'react-hot-toast'
33
import { useTranslation } from 'react-i18next'
44
import { css } from '@emotion/react'
@@ -25,7 +25,7 @@ import {
2525
TabsTrigger,
2626
} from '@/components/ui/tabs'
2727
import { RequestItem } from '@/types'
28-
import { isFalsy, isTruthy } from '@/utils'
28+
import { isFalsy, isTruthy, onlyIP } from '@/utils'
2929
import fetcher from '@/utils/fetcher'
3030

3131
import MethodBadge from './MethodBadge'
@@ -66,6 +66,11 @@ const RequestModal: React.FC<RequestModalProps> = ({ req, ...props }) => {
6666
[t],
6767
)
6868

69+
const pureIP = useMemo(
70+
() => req?.remoteAddress && onlyIP(req.remoteAddress),
71+
[req?.remoteAddress],
72+
)
73+
6974
const content = req ? (
7075
<>
7176
<DialogHeader>
@@ -153,7 +158,7 @@ const RequestModal: React.FC<RequestModalProps> = ({ req, ...props }) => {
153158
<div>{t('requests.remote_ip')}</div>
154159
<div>
155160
<a
156-
href={`https://ip.sb/ip/${req.remoteAddress}`}
161+
href={`https://ip.sb/ip/${pureIP}`}
157162
target="_blank"
158163
rel="noreferrer noopener"
159164
>

src/pages/Scripting/Evaluate/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { lazy, Suspense, useCallback, useState } from 'react'
22
import { toast } from 'react-hot-toast'
33
import { useTranslation } from 'react-i18next'
4-
import { css } from '@emotion/react'
54
import { LifeBuoy } from 'lucide-react'
65

76
import CodeContent from '@/components/CodeContent'

src/utils/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ export const forceRefresh = async (): Promise<void> => {
1616

1717
window.location.reload()
1818
}
19+
20+
/**
21+
* The following IP formats can be handled:
22+
* 1.1.1.1(Proxy),
23+
* 1.1.1.1 (Proxy),
24+
* 2001:0db8:85a3:0000:0000:8a2e:0370:7334(Proxy),
25+
* 2001:0db8:85a3:0000:0000:8a2e:0370:7334 (Proxy),
26+
*/
27+
export const onlyIP = (ip: string) => {
28+
const ipAddressRegex =
29+
/(?:\d{1,3}\.){3}\d{1,3}|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}/g
30+
const matchArray = ip.match(ipAddressRegex)
31+
return matchArray?.length ? matchArray[0] : ip
32+
}

0 commit comments

Comments
 (0)