Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/command/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/command/manifest/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -40,6 +44,14 @@ export class Download extends RootCommand implements LeafCommand {
public async run(): Promise<void> {
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)
Expand Down
25 changes: 24 additions & 1 deletion test/command/download.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()])
Expand Down
Loading