Skip to content

Commit 213507e

Browse files
authored
feat: improve gateway checks (#627)
* feat: use bee-js isGateway method to check for gateways * fix: use https for gateway * test(fix): use proper gateway url
1 parent 6addbdb commit 213507e

File tree

11 files changed

+22
-27
lines changed

11 files changed

+22
-27
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@ethereumjs/wallet": "^2.0.4",
66-
"@ethersphere/bee-js": "^9.5.0",
66+
"@ethersphere/bee-js": "^9.6.0",
6767
"cafe-utility": "^27.14.0",
6868
"chalk": "^2.4.2",
6969
"cli-progress": "^3.11.2",

src/command/pinning/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class List extends PinningCommand implements LeafCommand {
1010
public readonly description = 'List pinned root hashes'
1111

1212
public async run(): Promise<void> {
13-
super.init()
13+
await super.init()
1414
this.console.info('Getting pinned root hashes...')
1515

1616
const pins = await this.bee.getAllPins()

src/command/pinning/pin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Pin extends PinningCommand implements LeafCommand {
1212
public address!: string
1313

1414
public async run(): Promise<void> {
15-
super.init()
15+
await super.init()
1616

1717
try {
1818
await this.bee.pin(this.address)

src/command/pinning/pinning-command.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { exit } from 'process'
2-
import { isGateway } from '../../utils'
32
import { RootCommand } from '../root-command'
43

54
export class PinningCommand extends RootCommand {
6-
protected init(): void {
5+
protected async init(): Promise<void> {
76
super.init()
87

9-
if (isGateway(this.beeApiUrl)) {
8+
if (await this.bee.isGateway()) {
109
this.console.error('Pinning is currently not supported on the gateway node.')
1110
this.console.error('You can use the pinning API with your local Bee node.')
1211

src/command/pinning/reupload-all.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ReuploadAll extends PinningCommand implements LeafCommand {
1111
public stamp!: string
1212

1313
public async run(): Promise<void> {
14-
super.init()
14+
await super.init()
1515

1616
const chunks = await this.bee.getAllPins()
1717

src/command/pinning/reupload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Reupload extends PinningCommand implements LeafCommand {
2323
public stamp!: string
2424

2525
public async run(): Promise<void> {
26-
super.init()
26+
await super.init()
2727

2828
if (!this.stamp) {
2929
this.stamp = await pickStamp(this.bee, this.console)

src/command/pinning/unpin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Unpin extends PinningCommand implements LeafCommand {
1212
public address!: string
1313

1414
public async run(): Promise<void> {
15-
super.init()
15+
await super.init()
1616

1717
try {
1818
await this.bee.unpin(this.address)

src/command/upload.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { join, parse } from 'path'
77
import { exit } from 'process'
88
import { setCurlStore } from '../curl'
99
import { pickStamp, printStamp } from '../service/stamp'
10-
import { fileExists, isGateway, readStdin } from '../utils'
10+
import { fileExists, readStdin } from '../utils'
1111
import { CommandLineError } from '../utils/error'
1212
import { getMime } from '../utils/mime'
1313
import { stampProperties } from '../utils/option'
@@ -127,7 +127,7 @@ export class Upload extends RootCommand implements LeafCommand {
127127
public async run(usedFromOtherCommand = false): Promise<void> {
128128
super.init()
129129

130-
if (this.hasUnsupportedGatewayOptions()) {
130+
if (await this.hasUnsupportedGatewayOptions()) {
131131
exit(1)
132132
}
133133

@@ -145,7 +145,7 @@ export class Upload extends RootCommand implements LeafCommand {
145145
}
146146

147147
if (!this.stamp) {
148-
if (isGateway(this.beeApiUrl)) {
148+
if (await this.bee.isGateway()) {
149149
this.stamp = '0'.repeat(64)
150150
} else {
151151
this.stamp = await pickStamp(this.bee, this.console)
@@ -183,7 +183,7 @@ export class Upload extends RootCommand implements LeafCommand {
183183
if (!usedFromOtherCommand) {
184184
this.console.quiet(this.result.getOrThrow().toHex())
185185

186-
if (!isGateway(this.beeApiUrl) && !this.quiet) {
186+
if (!(await this.bee.isGateway()) && !this.quiet) {
187187
printStamp(await this.bee.getPostageBatch(this.stamp), this.console, { shortenBatchId: true })
188188
}
189189
}
@@ -419,8 +419,8 @@ export class Upload extends RootCommand implements LeafCommand {
419419
return size
420420
}
421421

422-
private hasUnsupportedGatewayOptions(): boolean {
423-
if (!isGateway(this.beeApiUrl)) {
422+
private async hasUnsupportedGatewayOptions(): Promise<boolean> {
423+
if (!(await this.bee.isGateway())) {
424424
return false
425425
}
426426

src/utils/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export function directoryExists(path: string): boolean {
2929
}
3030
}
3131

32-
export function isGateway(url: string): boolean {
33-
return url.includes('gateway.ethswarm.org')
34-
}
35-
3632
export function getByteSize(data: string | Uint8Array): number {
3733
if (data instanceof Uint8Array) {
3834
return data.byteLength

0 commit comments

Comments
 (0)