-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import fetchPonyfill from 'fetch-ponyfill' | ||
|
||
import { CheckBase } from './CheckBase' | ||
import { IPNS_PATH_TO_TEST } from './constants' | ||
import type { GatewayNode } from './GatewayNode' | ||
|
||
import { Log } from './Log' | ||
|
||
const { fetch } = fetchPonyfill() | ||
|
||
const log = new Log('Ipns') | ||
|
||
class IPNSCheck extends CheckBase implements Checkable { | ||
_className = 'Ipns' | ||
_tagName = 'div' | ||
constructor (protected parent: GatewayNode) { | ||
super(parent, 'div', 'Ipns') | ||
} | ||
|
||
async check (): Promise<void> { | ||
const now = Date.now() | ||
// Since gateway URLs are hard coded with /ipfs/, we need to parse URLs and override the path to /ipns/. | ||
const gatewayUrl = new URL(this.parent.gateway) | ||
gatewayUrl.pathname = IPNS_PATH_TO_TEST | ||
const testUrl = `${gatewayUrl.href}?now=${now}` | ||
try { | ||
const response = await fetch(testUrl) | ||
if (response.status === 200) { | ||
this.tag.win() | ||
} else { | ||
log.debug(`${this.parent.gateway} does not support IPNS`) | ||
throw new Error(`URL '${testUrl} is not reachable`) | ||
} | ||
} catch (err) { | ||
log.error(err) | ||
this.onerror() | ||
throw err | ||
} | ||
} | ||
|
||
checked (): void { | ||
log.warn('Not implemented yet') | ||
} | ||
|
||
onerror (): void { | ||
this.tag.err() | ||
} | ||
} | ||
|
||
export { IPNSCheck } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters