diff --git a/src/command/download.ts b/src/command/download.ts index 9d5881c9..fb817d25 100644 --- a/src/command/download.ts +++ b/src/command/download.ts @@ -39,6 +39,13 @@ export class Download extends RootCommand implements LeafCommand { actTimestamp: this.manifestDownload.actTimestamp, }) response = responseAct.data + } else if (this.manifestDownload.access) { + const [publisher, historyAddress] = this.manifestDownload.access.split(':') + const responseAct = await this.bee.downloadFile(this.address.hash, this.manifestDownload.destination, { + actPublisher: publisher, + actHistoryAddress: historyAddress, + }) + response = responseAct.data } else { if (this.address.hash.length === 128) { const fileData = await this.bee.downloadFile(this.address.hash, undefined) diff --git a/src/command/manifest/download.ts b/src/command/manifest/download.ts index ad296ec4..b1311cbd 100644 --- a/src/command/manifest/download.ts +++ b/src/command/manifest/download.ts @@ -6,6 +6,7 @@ import { join, parse } from 'path' import { exit } from 'process' import { directoryExists } from '../../utils' import { BzzAddress, makeBzzAddress } from '../../utils/bzz-address' +import { deprecationWarningText } from '../../utils/text' import { RootCommand } from '../root-command' export class Download extends RootCommand implements LeafCommand { @@ -23,6 +24,9 @@ export class Download extends RootCommand implements LeafCommand { @Option({ key: 'stdout', type: 'boolean', description: 'Print to stdout (single files only)' }) public stdout!: boolean + @Option({ key: 'access', type: 'string', description: 'Download using grantee list', conflicts: 'act' }) + public access!: string + @Option({ key: 'act', type: 'boolean', description: 'Download with ACT', default: false }) public act!: boolean @@ -40,6 +44,14 @@ export class Download extends RootCommand implements LeafCommand { public async run(): Promise { super.init() + if (this.act) { + this.console.log( + deprecationWarningText( + '--act option is deprecated and will be removed in future versions. Please use --access option with publisher:historyAddress format instead.', + ), + ) + } + // can be already set from other command if (!this.address) { this.address = await makeBzzAddress(this.bee, this.bzzUrl) diff --git a/test/command/download.spec.ts b/test/command/download.spec.ts index b5f528ad..71167388 100644 --- a/test/command/download.spec.ts +++ b/test/command/download.spec.ts @@ -1,4 +1,4 @@ -import { Binary } from 'cafe-utility' +import { Binary, System } from 'cafe-utility' import { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -43,6 +43,29 @@ describeCommand('Test Download command', ({ consoleMessages }) => { expect(consoleMessages[0]).toContain('Hello Swarm!') }) + describe('when --access option is used', () => { + it('should download with act and print to stdout', async () => { + const addressesInvocation = await invokeTestCli(['addresses']) + const addressesCommand = addressesInvocation.runnable as Addresses + await invokeTestCli(['access', 'init', ...getStampOption(), '--list-name', 'test-download']) + System.sleepMillis(1000) + const uploadInvocation = await invokeTestCli([ + 'upload', + 'test/message.txt', + '--share-with', + 'test-download', + ...getStampOption(), + ]) + const uploadCommand = uploadInvocation.runnable as Upload + const ref = uploadCommand.result.getOrThrow().toHex() + const history = uploadCommand.historyAddress.getOrThrow().toHex() + const publicKey = addressesCommand.nodeAddresses.publicKey.toHex() + consoleMessages.length = 0 + await invokeTestCli(['download', ref, '--access', `${publicKey}:${history}`, '--stdout']) + expect(consoleMessages[0]).toContain('Hello Swarm!') + }) + }) + it('should fall back to manifest download', async () => { const tmpDir = makeTmpDir() const invocation = await invokeTestCli(['upload', 'test/testpage', ...getStampOption()])