handle local domains

This commit is contained in:
2025-03-19 22:08:30 +01:00
parent 90bb276622
commit c3be23d369
2 changed files with 45 additions and 16 deletions
+21 -8
View File
@@ -4,8 +4,8 @@ import { codes } from '@/utils/codes';
export default function ServerInfo({ data }: { data: ServerData }) { export default function ServerInfo({ data }: { data: ServerData }) {
const countryName = data.country const countryName = data.country
? codes[data.country.toLowerCase()] || "N/A" ? codes[data.country.toLowerCase()] || "N/A"
: "N/A"; : "N/A";
if (data.isBrowserResource) { if (data.isBrowserResource) {
return ( return (
@@ -32,13 +32,26 @@ export default function ServerInfo({ data }: { data: ServerData }) {
Internal Network Internal Network
</h2> </h2>
</div> </div>
<div className="flex items-center space-x-3">
<ServerIcon className="w-6 h-6 text-yellow-400 flex-shrink-0" /> {data.ip && (
<div> <div className="flex items-center space-x-3">
<p className="text-sm text-gray-400">IP Address</p> <ServerIcon className="w-6 h-6 text-yellow-400 flex-shrink-0" />
<p className="font-medium">{data.ip}</p> <div>
<p className="text-sm text-gray-400">IP Address</p>
<p className="font-medium">{data.ip}</p>
</div>
</div> </div>
</div> )}
{data.hostname && (
<div className="flex items-center space-x-3">
<LinkIcon className="w-6 h-6 text-green-400 flex-shrink-0" />
<div>
<p className="text-sm text-gray-400">Hostname</p>
<p className="font-medium break-all">{data.hostname}</p>
</div>
</div>
)}
</div> </div>
); );
} }
+24 -8
View File
@@ -1,7 +1,11 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react'
import browser from 'webextension-polyfill'; import { isPrivateIP } from '@/utils'
import { isPrivateIP } from '@/utils'; import {
import { FetchServerInfoRequest, FetchServerInfoResponse, ServerData } from '@/utils/model'; FetchServerInfoRequest,
FetchServerInfoResponse,
ServerData,
} from '@/utils/model'
import browser from 'webextension-polyfill'
export function useTabData() { export function useTabData() {
const [data, setData] = useState<ServerData | null>(null) const [data, setData] = useState<ServerData | null>(null)
@@ -39,7 +43,7 @@ export function useTabData() {
return setData({ return setData({
origin: '', origin: '',
ip: hostname, ip: hostname,
hostname: url.href, hostname: '',
country: '', country: '',
city: '', city: '',
org: '', org: '',
@@ -48,7 +52,10 @@ export function useTabData() {
}) })
} }
const response = await browser.runtime.sendMessage<FetchServerInfoRequest, FetchServerInfoResponse>({ const response = await browser.runtime.sendMessage<
FetchServerInfoRequest,
FetchServerInfoResponse
>({
type: 'FETCH_SERVER_INFO', type: 'FETCH_SERVER_INFO',
hostname: hostname, hostname: hostname,
}) })
@@ -58,7 +65,16 @@ export function useTabData() {
} }
if (response.error) { if (response.error) {
throw new Error(response.error) return setData({
origin: '',
ip: '',
hostname: hostname,
country: '',
city: '',
org: '',
isLocal: true,
isBrowserResource: false,
})
} }
if (!response.data?.ip) { if (!response.data?.ip) {
@@ -68,7 +84,7 @@ export function useTabData() {
setData(response.data) setData(response.data)
setError(null) setError(null)
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch data') setError(err instanceof Error ? err.message : 'No data found')
setData(null) setData(null)
} finally { } finally {
setLoading(false) setLoading(false)