mirror of
https://github.com/kremalicious/ipfs.git
synced 2025-02-14 21:10:43 +01:00
fix ping status
This commit is contained in:
parent
0a8f384e21
commit
baec08c0a9
@ -11,9 +11,9 @@ export default function Status({ type }: { type: string }): ReactElement {
|
|||||||
const url =
|
const url =
|
||||||
type === 'gateway'
|
type === 'gateway'
|
||||||
? `${ipfsGateway}/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme`
|
? `${ipfsGateway}/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme`
|
||||||
: `${ipfsNodeUri}/api/v0/id`
|
: `${ipfsNodeUri}/api/v0/version`
|
||||||
|
const method = type === 'gateway' ? 'get' : 'post'
|
||||||
const ping = await pingUrl(url)
|
const ping = await pingUrl(url, method)
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
setIsOnline(ping)
|
setIsOnline(ping)
|
||||||
}, [type])
|
}, [type])
|
||||||
|
@ -9,9 +9,12 @@ export function formatBytes(a: number, b: number): string {
|
|||||||
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
|
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function pingUrl(url: string): Promise<boolean> {
|
export async function pingUrl(
|
||||||
|
url: string,
|
||||||
|
method?: 'get' | 'post'
|
||||||
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const response = await axios(url, { timeout: 5000 })
|
const response = await axios[method || 'get'](url, { timeout: 5000 })
|
||||||
if (!response || response.status !== 200) return false
|
if (!response || response.status !== 200) return false
|
||||||
return true
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user