Skip to content

Commit

Permalink
chore: update eslint-config-ipfs and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Jun 8, 2023
1 parent 1b7fbce commit 66b84db
Show file tree
Hide file tree
Showing 19 changed files with 833 additions and 367 deletions.
1,001 changes: 737 additions & 264 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"browserslist": "^4.21.4",
"check-aegir-project": "^1.1.1",
"cp-cli": "^2.0.0",
"eslint-config-ipfs": "^3.1.2",
"eslint-config-ipfs": "^4.0.3",
"eslint-plugin-compat": "^4.0.2",
"fetch-ponyfill": "^7.1.0",
"ipfs": "^0.65.0",
Expand Down
3 changes: 2 additions & 1 deletion src/CheckBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { UiComponent } from './UiComponent'
import type { Checker } from './Checker'
import type { GatewayNode } from './GatewayNode'
import type { Tag } from './Tag'
import { UiComponent } from './UiComponent'
import type { Checkable } from './types'

/**
* Base Check functionality
Expand Down
4 changes: 2 additions & 2 deletions src/Checker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import { GatewayNode } from './GatewayNode'
import { Log } from './Log'
import { Results } from './Results'
import { Stats } from './Stats'
import { Log } from './Log'

const log = new Log('Checker')

Expand Down Expand Up @@ -34,7 +34,7 @@ class Checker {
this.results.append(node.tag)
// void node.check()
setTimeout(() => {
allChecks.push(node.check().catch((err) => log.error(err)).finally(this.updateStats))
allChecks.push(node.check().catch((err) => { log.error(err) }).finally(this.updateStats))
}, 100 * this.nodes.length)
}
// await Promise.all(allChecks).finally(this.updateStats)
Expand Down
5 changes: 2 additions & 3 deletions src/Cors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fetchPonyfill from 'fetch-ponyfill'

import { CheckBase } from './CheckBase'
import { Log } from './Log'
import { HASH_STRING, HASH_TO_TEST } from './constants'
import type { GatewayNode } from './GatewayNode'

import { Log } from './Log'
import type { Checkable } from './types'

const { fetch } = fetchPonyfill()

Expand Down
11 changes: 6 additions & 5 deletions src/Flag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { GatewayNode } from './GatewayNode'
import { Log } from './Log'
import { TokenBucketLimiter } from '@dutu/rate-limiter'
import { lookup as IpfsGeoIpLookup } from 'ipfs-geoip'
import { Log } from './Log'
import { UiComponent } from './UiComponent'
import { TokenBucketLimiter } from '@dutu/rate-limiter'
import { DEFAULT_IPFS_GATEWAY } from './constants'
import type { GatewayNode } from './GatewayNode'
import type { DnsQueryResponse } from './types'

const log = new Log('Flag')

Expand Down Expand Up @@ -71,7 +72,7 @@ class Flag extends UiComponent {
if (url == null) {
// No available tokens...
log.info('we awaited tokens, but could not retrieve any.. restarting dnsRequest')
return await this.waitForAvailableEndpoint()
return this.waitForAvailableEndpoint()
} else {
return url
}
Expand All @@ -97,7 +98,7 @@ class Flag extends UiComponent {
async handleDnsQueryResponse (response: DnsQueryResponse): Promise<void> {
if (response.Answer == null) {
log.error('Response does not contain the "Answer" property:', response)
return this.onError()
this.onError(); return
}
let ip = null
for (let i = 0; i < response.Answer.length && ip == null; i++) {
Expand Down
24 changes: 11 additions & 13 deletions src/GatewayNode.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { URL } from 'url-ponyfill'

import { Cors } from './Cors'
import { Flag } from './Flag'
import { IPNSCheck } from './Ipns'
import { Log } from './Log'
import { Origin } from './Origin'
import { Trustless } from './Trustless'
import type { Results } from './Results'
import { Status } from './Status'
import { Trustless } from './Trustless'
import { UiComponent } from './UiComponent'

import { Log } from './Log'
import { gatewayHostname } from './gatewayHostname'
import { HASH_TO_TEST } from './constants'
import { IPNSCheck } from './Ipns'
import { gatewayHostname } from './gatewayHostname'
import type { Results } from './Results'

const log = new Log('GatewayNode')

Expand Down Expand Up @@ -77,15 +75,15 @@ class GatewayNode extends UiComponent /* implements Checkable */ {
this.checkingTime = Date.now()
// const onFailedCheck = () => { this.status.down = true }
// const onSuccessfulCheck = () => { this.status.up = true }
void this.flag.check().then(() => log.debug(this.gateway, 'Flag success'))
void this.flag.check().then(() => { log.debug(this.gateway, 'Flag success') })
const onlineChecks = [
// this.flag.check().then(() => log.debug(this.gateway, 'Flag success')),
this.status.check().then(() => log.debug(this.gateway, 'Status success')).then(this.onSuccessfulCheck.bind(this)),
this.cors.check().then(() => log.debug(this.gateway, 'CORS success')).then(this.onSuccessfulCheck.bind(this)),
this.ipns.check().then(() => log.debug(this.gateway, 'IPNS success')).then(this.onSuccessfulCheck.bind(this)),
this.origin.check().then(() => log.debug(this.gateway, 'Origin success')).then(this.onSuccessfulCheck.bind(this)),
this.status.check().then(() => { log.debug(this.gateway, 'Status success') }).then(this.onSuccessfulCheck.bind(this)),
this.cors.check().then(() => { log.debug(this.gateway, 'CORS success') }).then(this.onSuccessfulCheck.bind(this)),
this.ipns.check().then(() => { log.debug(this.gateway, 'IPNS success') }).then(this.onSuccessfulCheck.bind(this)),
this.origin.check().then(() => { log.debug(this.gateway, 'Origin success') }).then(this.onSuccessfulCheck.bind(this)),
this.trustless.check().then(
() => log.debug(this.gateway, 'Trustless success')).then(this.onSuccessfulCheck.bind(this))
() => { log.debug(this.gateway, 'Trustless success') }).then(this.onSuccessfulCheck.bind(this))
]

// we care only about the fastest method to return a success
Expand Down
5 changes: 2 additions & 3 deletions src/Ipns.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fetchPonyfill from 'fetch-ponyfill'

import { CheckBase } from './CheckBase'
import { Log } from './Log'
import { IPNS_PATH_TO_TEST } from './constants'
import type { GatewayNode } from './GatewayNode'

import { Log } from './Log'
import type { Checkable } from './types'

const { fetch } = fetchPonyfill()

Expand Down
12 changes: 5 additions & 7 deletions src/Origin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { URL } from 'url-ponyfill'

import type { GatewayNode } from './GatewayNode'
import { Tag } from './Tag'

import { Log } from './Log'
import { expectSubdomainRedirect } from './expectSubdomainRedirect'
import { Tag } from './Tag'
import { checkViaImgSrc } from './checkViaImgSrc'
import { IMG_HASH } from './constants'
import { expectSubdomainRedirect } from './expectSubdomainRedirect'
import type { GatewayNode } from './GatewayNode'

const log = new Log('Origin')

Expand All @@ -25,13 +23,13 @@ class Origin {
const imgSubdomainUrl = new URL(`${gwUrl.protocol}//${IMG_HASH}.ipfs.${gwUrl.hostname}/?now=${Date.now()}&filename=1x1.png#x-ipfs-companion-no-redirect`)
const imgRedirectedPathUrl = new URL(`${gwUrl.protocol}//${gwUrl.hostname}/ipfs/${IMG_HASH}?now=${Date.now()}&filename=1x1.png#x-ipfs-companion-no-redirect`)
await checkViaImgSrc(imgSubdomainUrl)
.then(async () => await expectSubdomainRedirect(imgRedirectedPathUrl))
.then(async () => expectSubdomainRedirect(imgRedirectedPathUrl))
.then(() => {
this.tag.win(imgSubdomainUrl.toString())
this.parent.tag.classList.add('origin')
// this.parent.checked()
})
.catch((err) => this.onerror(err))
.catch((err) => { this.onerror(err) })
}

onerror (err: Error): void {
Expand Down
2 changes: 1 addition & 1 deletion src/Stats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Checker } from './Checker'
import { Tag } from './Tag'
import { UiComponent } from './UiComponent'
import type { Checker } from './Checker'

class Stats extends UiComponent {
gateways: HTMLDivElement
Expand Down
6 changes: 2 additions & 4 deletions src/Status.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { URL } from 'url-ponyfill'

import type { GatewayNode } from './GatewayNode'
import { UiComponent } from './UiComponent'

import { Log } from './Log'
import { UiComponent } from './UiComponent'
import { checkViaImgSrc } from './checkViaImgSrc'
import { IMG_HASH } from './constants'
import type { GatewayNode } from './GatewayNode'

const log = new Log('Status')

Expand Down
2 changes: 1 addition & 1 deletion src/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Tag {
if (child instanceof Tag) {
child = child.element
}
return this.element.append(child)
this.element.append(child)
}

get classList (): DOMTokenList {
Expand Down
5 changes: 2 additions & 3 deletions src/Trustless.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fetchPonyfill from 'fetch-ponyfill'

import { CheckBase } from './CheckBase'
import { Log } from './Log'
import { HASH_TO_TEST, TRUSTLESS_RESPONSE_TYPES } from './constants'
import type { GatewayNode } from './GatewayNode'

import { Log } from './Log'
import type { Checkable } from './types'

const { fetch } = fetchPonyfill()

Expand Down
3 changes: 2 additions & 1 deletion src/UiComponent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Tag } from './Tag'
import type { Checker } from './Checker'
import type { GatewayNode } from './GatewayNode'
import type { Results } from './Results'
import { Tag } from './Tag'
import type { Visible } from './types'

class UiComponent {
tag: Tag
Expand Down
2 changes: 1 addition & 1 deletion src/checkViaImgSrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function checkViaImgSrc (imgUrl: string | URL): Promise<void> {
// this is more robust check than loading js, as it won't be blocked
// by privacy protections present in modern browsers or in extensions such as Privacy Badger
const imgCheckTimeout = 15000
return await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const img = new Image()
const timer: ReturnType<typeof setTimeout> = setTimeout(() => {
// clearTimeout(timer)
Expand Down
3 changes: 1 addition & 2 deletions src/expectSubdomainRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { URL } from 'url-ponyfill'
import { IMG_HASH } from './constants'

import { Log } from './Log'
import { IMG_HASH } from './constants'

const log = new Log('expectSubdomainRedirect')

Expand Down
53 changes: 0 additions & 53 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
/* eslint-disable etc/prefer-interface */

declare module '@dutu/rate-limiter'
declare module 'ipfs-geoip'

// declare global {
/**
* An interface that allows various properties for gateways to be checked
*/
interface Checkable {

// @todo: Update to async/await
// check: () => Promise<void>
check: () => void
checked: () => void

onerror: () => void
}

/**
* A class implementing the Visible interface supports functionality that can make it visible in the UI
*/
interface Visible {
tag: import('./Tag').Tag
_tagName: string
_className: string
}

interface Window {
OnScriptloaded: typeof import('./onScriptLoaded').onScriptLoaded
checker: import('./Checker').Checker
}

declare namespace IpfsGeoip {
interface LookupResponse {
country_code: string
country_name: string
}
}
interface DnsQueryResponseAnswer { name: string, type: number, TTL: number, data: string }
interface DnsQueryResponseQuestion { name: string, type: number }

interface DnsQueryResponseAuthority {
TTL: number
data: string // "aragorn.ns.cloudflare.com. dns.cloudflare.com. 2271826322 10000 2400 604800 3600"
name: string // "stibarc.com"
type: number
}

interface DnsQueryResponse {
AD: boolean
Answer?: DnsQueryResponseAnswer[]
Authority?: DnsQueryResponseAuthority[]
CD: boolean
Question: DnsQueryResponseQuestion[]
RA: boolean
RD: boolean
Status: number
TC: boolean
}
// }
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Workbox } from 'workbox-window'
import { Checker } from './Checker'
import { Log } from './Log'
import gateways from './gateways.json'
import { loadCountly } from './metrics'
import { Log } from './Log'
import { Workbox } from 'workbox-window'

const wb = new Workbox('/sw.js')
void wb.register()
Expand Down
53 changes: 53 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Checker } from './Checker'
import type { Tag } from './Tag'
// import type onScriptLoaded from './onScriptLoaded'

declare global {
interface Window {
// OnScriptloaded: onScriptLoaded
checker: Checker
}
}
/**
* An interface that allows various properties for gateways to be checked
*/
export interface Checkable {

// @todo: Update to async/await
// check: () => Promise<void>
check: () => void
checked: () => void

onerror: () => void
}

/**
* A class implementing the Visible interface supports functionality that can make it visible in the UI
*/
export interface Visible {
tag: Tag
_tagName: string
_className: string
}

export interface DnsQueryResponseAnswer { name: string, type: number, TTL: number, data: string }
export interface DnsQueryResponseQuestion { name: string, type: number }

export interface DnsQueryResponseAuthority {
TTL: number
data: string // "aragorn.ns.cloudflare.com. dns.cloudflare.com. 2271826322 10000 2400 604800 3600"
name: string // "stibarc.com"
type: number
}

export interface DnsQueryResponse {
AD: boolean
Answer?: DnsQueryResponseAnswer[]
Authority?: DnsQueryResponseAuthority[]
CD: boolean
Question: DnsQueryResponseQuestion[]
RA: boolean
RD: boolean
Status: number
TC: boolean
}

0 comments on commit 66b84db

Please sign in to comment.