From 97aeb8b8a43828ac5c3bb6b754fd8a9fad5b3334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20B=C3=A9k=C3=A9si?= Date: Thu, 4 Jun 2026 09:43:44 +0200 Subject: [PATCH 1/2] fix: generate qr from a publicly available url --- src/command/upload.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/command/upload.ts b/src/command/upload.ts index a13d6ea0..14f9f684 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -232,7 +232,7 @@ export class Upload extends RootCommand implements LeafCommand { } if (this.qr) { - printQRCodeWithLabel(url, 'QR for URL', this.console) + printQRCodeWithLabel(this.publicUrl(url), 'QR for URL', this.console) } if (this.shareWith) { @@ -646,4 +646,20 @@ export class Upload extends RootCommand implements LeafCommand { return options } + + private publicUrl(url: string): string { + let publicUrl: string = url + + const isLocal = ['localhost', '127.0.0.1', '::1'].includes(new URL(this.bee.url).hostname) + + if (isLocal) { + publicUrl = Object.assign(new URL(url), { + protocol: 'https:', + host: 'api.gateway.ethswarm.org', + port: '', + }).toString() + } + + return publicUrl + } } From df7ce52e09cebb928a9c293e20cc8dbfa7a0208a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20B=C3=A9k=C3=A9si?= Date: Thu, 4 Jun 2026 12:05:17 +0200 Subject: [PATCH 2/2] fix: add specs and update feed upload --- src/command/feed/feed-command.ts | 5 +++-- src/command/upload.ts | 19 ++----------------- src/utils/url.ts | 15 +++++++++++++++ test/command/feed.spec.ts | 27 +++++++++++++++++++++++++++ test/command/upload.spec.ts | 12 ++++++++++++ 5 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/utils/url.ts diff --git a/src/command/feed/feed-command.ts b/src/command/feed/feed-command.ts index a2c58900..bbbe26aa 100644 --- a/src/command/feed/feed-command.ts +++ b/src/command/feed/feed-command.ts @@ -6,11 +6,12 @@ import { getWalletFromIdentity, pickIdentity } from '../../service/identity' import { Identity } from '../../service/identity/types' import { printStamp } from '../../service/stamp' import { topicProperties, topicStringProperties } from '../../utils/option' +import { printQRCodeWithLabel } from '../../utils/qr' import { createSpinner } from '../../utils/spinner' import { createKeyValue } from '../../utils/text' +import { publicUrl } from '../../utils/url' import { RootCommand } from '../root-command' import { VerbosityLevel } from '../root-command/command-log' -import { printQRCodeWithLabel } from '../../utils/qr' interface FeedInfo { reference: Reference @@ -57,7 +58,7 @@ export class FeedCommand extends RootCommand { this.console.log(createKeyValue('Feed Manifest URL', manifestUrl)) if (this.qr) { - printQRCodeWithLabel(manifestUrl, 'QR for Manifest URL', this.console) + printQRCodeWithLabel(publicUrl(manifestUrl), 'QR for Manifest URL', this.console) } this.console.quiet(manifest.toHex()) diff --git a/src/command/upload.ts b/src/command/upload.ts index 14f9f684..09c61a90 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -18,6 +18,7 @@ import { stampProperties } from '../utils/option' import { printQRCodeWithLabel } from '../utils/qr' import { createSpinner } from '../utils/spinner' import { createKeyValue, deprecationWarningText, warningSymbol, warningText } from '../utils/text' +import { publicUrl } from '../utils/url' import { RootCommand } from './root-command' import { VerbosityLevel } from './root-command/command-log' @@ -232,7 +233,7 @@ export class Upload extends RootCommand implements LeafCommand { } if (this.qr) { - printQRCodeWithLabel(this.publicUrl(url), 'QR for URL', this.console) + printQRCodeWithLabel(publicUrl(url), 'QR for URL', this.console) } if (this.shareWith) { @@ -646,20 +647,4 @@ export class Upload extends RootCommand implements LeafCommand { return options } - - private publicUrl(url: string): string { - let publicUrl: string = url - - const isLocal = ['localhost', '127.0.0.1', '::1'].includes(new URL(this.bee.url).hostname) - - if (isLocal) { - publicUrl = Object.assign(new URL(url), { - protocol: 'https:', - host: 'api.gateway.ethswarm.org', - port: '', - }).toString() - } - - return publicUrl - } } diff --git a/src/utils/url.ts b/src/utils/url.ts new file mode 100644 index 00000000..df967b11 --- /dev/null +++ b/src/utils/url.ts @@ -0,0 +1,15 @@ +export function publicUrl(url: string): string { + let publicUrl: string = url + + const isLocal = ['localhost', '127.0.0.1', '::1'].includes(new URL(url).hostname) + + if (isLocal) { + publicUrl = Object.assign(new URL(url), { + protocol: 'https:', + host: 'api.gateway.ethswarm.org', + port: '', + }).toString() + } + + return publicUrl +} diff --git a/test/command/feed.spec.ts b/test/command/feed.spec.ts index 76002f5e..f01a0bcb 100644 --- a/test/command/feed.spec.ts +++ b/test/command/feed.spec.ts @@ -1,4 +1,5 @@ import { randomUUID } from 'crypto' +import QRCode from 'qrcode' import { Upload } from '../../src/command/upload' import { toBeQRCode, toMatchLinesInOrder } from '../custom-matcher' import { describeCommand, invokeTestCli } from '../utility' @@ -112,6 +113,32 @@ describeCommand( expect(hasMessageContaining('QR for Manifest URL:')).toBeTruthy() expect(consoleMessages[13]).toBeQRCode() }) + + describe('when the URL is local', () => { + it('should change the URL to use gateway', async () => { + const stampBatchId = await getOrBuyStamp() + // create identity + const identityName = randomUUID() + await invokeTestCli(['identity', 'create', identityName, '--password', 'test']) + jest.spyOn(QRCode, 'toString') + await invokeTestCli([ + 'feed', + 'upload', + '--identity', + identityName, + '--password', + 'test', + '--stamp', + stampBatchId.toHex(), + '--qr', + `${__dirname}/../testpage/images/swarm.png`, + ]) + expect(QRCode.toString).toHaveBeenCalledWith( + expect.stringContaining('https://api.gateway.ethswarm.org/bzz/'), + { type: 'terminal', small: true }, + ) + }) + }) }) it.skip('should increment number of updates for sequence feeds', async () => { diff --git a/test/command/upload.spec.ts b/test/command/upload.spec.ts index 29c8f73e..b9fbfe38 100644 --- a/test/command/upload.spec.ts +++ b/test/command/upload.spec.ts @@ -1,6 +1,7 @@ import { System } from 'cafe-utility' import { existsSync, unlinkSync, writeFileSync } from 'fs' import { LeafCommand } from 'furious-commander' +import QRCode from 'qrcode' import type { Upload } from '../../src/command/upload' import { toBeQRCode, toMatchLinesInOrder } from '../custom-matcher' import { describeCommand, invokeTestCli } from '../utility' @@ -212,6 +213,17 @@ describeCommand( expect(hasMessageContaining('QR for URL:')).toBeTruthy() expect(getLastMessage()).toBeQRCode() }) + + describe('when the URL is local', () => { + it('should change the URL to use gateway', async () => { + jest.spyOn(QRCode, 'toString') + await invokeTestCli(['upload', 'test/message.txt', '--qr', ...getStampOption()]) + expect(QRCode.toString).toHaveBeenCalledWith( + expect.stringContaining('https://api.gateway.ethswarm.org/bzz/'), + { type: 'terminal', small: true }, + ) + }) + }) }) describe('when using stdin and bee-api-url is a gateway', () => {