Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
14 changes: 12 additions & 2 deletions src/command/feed/feed-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class FeedCommand extends RootCommand {
@Option({ key: 'password', alias: 'P', description: 'Password for the wallet' })
public password!: string

@Option({ key: 'index', description: 'Index for the feed to write to, or read from', required: false })
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could simply say "Feed index to write to or read from"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll make this change.


public act!: boolean
protected async updateFeedAndPrint(chunkReference: string): Promise<string> {
const wallet = await this.getWallet()
const topic = this.topic || this.bee.makeFeedTopic(this.topicString)
Expand Down Expand Up @@ -79,7 +82,7 @@ export class FeedCommand extends RootCommand {
return identities[this.identity] || identities[await pickIdentity(this.commandConfig, this.console)]
}

private async writeFeed(wallet: Wallet, topic: string, chunkReference: string): Promise<FeedInfo> {
private async writeFeed(wallet: Wallet, topic: string, chunkReference: string, index?: number): Promise<FeedInfo> {
const spinner = createSpinner('Writing feed...')

if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) {
Expand All @@ -88,7 +91,14 @@ export class FeedCommand extends RootCommand {

try {
const writer = this.bee.makeFeedWriter('sequence', topic, wallet.getPrivateKey())
const reference = await writer.upload(this.stamp, chunkReference as Reference)
let reference: Reference
if (index === undefined) {
// Index was not specified
reference = await writer.upload(this.stamp, chunkReference as Reference)
} else {
// Index was specified
reference = await writer.upload(this.stamp, chunkReference as Reference, { index })
}
const { reference: manifest } = await this.bee.createFeedManifest(
this.stamp,
'sequence',
Expand Down
2 changes: 1 addition & 1 deletion src/command/feed/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FeedCommand } from './feed-command'
export class Update extends FeedCommand implements LeafCommand {
public readonly name = 'update'

public readonly description = 'Update feed'
public readonly description = 'Update feed (with reference)'

@Option({ key: 'reference', alias: 'r', description: 'The new reference', required: true })
public reference!: string
Expand Down
2 changes: 1 addition & 1 deletion src/command/feed/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FeedCommand } from './feed-command'
export class Upload extends FeedCommand implements LeafCommand {
public readonly name = 'upload'

public readonly description = 'Upload to a feed'
public readonly description = 'Upload to a feed (file or folder)'

public feedManifest?: string

Expand Down
85 changes: 85 additions & 0 deletions test/command/feed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,91 @@ describeCommand(
expect(getLastMessage()).toContain('Number of Updates')
expect(getLastMessage()).toContain('2')
})

it('should write to correct index', async () => {
// create identity
await invokeTestCli(['identity', 'create', 'test', '--password', 'test'])
// upload data to index 22
await invokeTestCli([
'feed',
'upload',
`${__dirname}/../testpage/images/swarm.png`,
'--identity',
'test',
'--topic-string',
'test',
'--password',
'test',
'--quiet',
'--index',
'22',
...getStampOption(),
])
// print with identity and password
await invokeTestCli([
'feed',
'print',
'--identity',
'test',
'--topic-string',
'test',
'--password',
'test',
'--quiet',
'--index',
'22',
...getStampOption(),
])
expect(getLastMessage()).toMatch(/[a-z0-9]{64}/)

// Zero index should work as well
await invokeTestCli(['identity', 'create', 'test', '--password', 'test'])
await invokeTestCli([
'feed',
'upload',
`${__dirname}/../testpage/images/swarm.png`,
'--identity', 'test',
'--topic-string',
'test',
'--password',
'test',
'--quiet',
'--index',
'0',
...getStampOption(),
])
await invokeTestCli([
'feed',
'print',
'--identity',
'test',
'--topic-string',
'test',
'--password',
'test',
'--quiet',
'--index',
'0',
...getStampOption(),
])
expect(getLastMessage()).toMatch(/[a-z0-9]{64}/)

// It should work without specifying the index as well
await invokeTestCli([
'feed',
'print',
'--identity',
'test',
'--topic-string',
'test',
'--password',
'test',
'--quiet',
...getStampOption(),
])
expect(getLastMessage()).toMatch(/[a-z0-9]{64}/)
})

},
{ configFileName: 'feed' },
)