Skip to content
Draft
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be removed

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be removed

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>First updated CLI webpage</title>
</head>

<body>
<div>
Let's roll!
</div>
<image src="images/swarm.png" width="200">
</body>
</html>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be removed

Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Run 'swarm-cli GROUP --help' to see available commands in a group

█ Available Commands:

reupload Reupload locally pinned content

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The copy also needs a change here since we are no longer in the context of pinning. Suggested: "Reupload and restamp content on the network"

upload Upload file to Swarm
download Download arbitrary Swarm hash
hash Print the Swarm hash of a file
Expand Down
3 changes: 1 addition & 2 deletions src/command/pinning/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GroupCommand } from 'furious-commander'
import { List } from './list'
import { Pin } from './pin'
import { Reupload } from './reupload'
import { ReuploadAll } from './reupload-all'
import { Unpin } from './unpin'

Expand All @@ -10,5 +9,5 @@ export class Pinning implements GroupCommand {

public readonly description = 'Pin, unpin and check pinned chunks'

public subCommandClasses = [Pin, Unpin, List, Reupload, ReuploadAll]
public subCommandClasses = [Pin, Unpin, List, ReuploadAll]
}
20 changes: 16 additions & 4 deletions src/command/pinning/reupload.ts → src/command/reupload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Argument, LeafCommand, Option } from 'furious-commander'
import { pickStamp } from '../../service/stamp'
import { stampProperties } from '../../utils/option'
import { PinningCommand } from './pinning-command'
import { pickStamp } from '../service/stamp'
import { stampProperties } from '../utils/option'
import { RootCommand } from './root-command'
import { History } from '../service/history'

export class Reupload extends PinningCommand implements LeafCommand {
export class Reupload extends RootCommand implements LeafCommand {
// CLI FIELDS

public readonly name = 'reupload'
Expand Down Expand Up @@ -33,6 +34,17 @@ export class Reupload extends PinningCommand implements LeafCommand {
try {
await this.bee.reuploadPinnedData(this.stamp, this.address)
this.console.log('Reuploaded successfully.')

if (this.commandConfig.config.historyEnabled) {
const history = new History(this.commandConfig, this.console)
history.addItem({
timestamp: Date.now(),
reference: this.address,
stamp: this.stamp,
path: null,
uploadType: 'reupload',
})
}
} catch (error) {
this.console.printBeeError(error, { notFoundMessage: 'No locally pinned content found with that address.' })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This error message no longer makes sense as a root level command.
Something like "No content found with that address." would be better.

}
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { Upload } from './command/upload'
import { Utility } from './command/utility'
import { Wallet } from './command/wallet'
import { Reupload } from './command/reupload'

export const beeApiUrl: IOption<string> = {
key: 'bee-api-url',
Expand Down Expand Up @@ -95,7 +96,7 @@
description: 'Agree to all prompts',
}

export const optionParameters: IOption<any>[] = [

Check warning on line 99 in src/config.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Unexpected any. Specify a different type
beeApiUrl,
configFolder,
configFile,
Expand Down Expand Up @@ -127,4 +128,5 @@
Quickstart,
History,
Access,
Reupload,
]
2 changes: 1 addition & 1 deletion src/service/history/types/history-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type HistoryItem = {
reference: string
stamp: string
path: string | null
uploadType: 'file' | 'folder' | 'stdin'
uploadType: 'file' | 'folder' | 'stdin' | 'reupload'
feedAddress?: string | null
feedIdentity?: string | null
}
Binary file added swarm.png

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be removed

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions test/command/reupload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { readFileSync } from 'fs'
import type { Reupload } from '../../src/command/reupload'
import type { Upload } from '../../src/command/upload'
import { HistoryItem } from '../../src/service/history/types/history-item'
import { describeCommand, invokeTestCli } from '../utility'
import { getStampOption } from '../utility/stamp'
import { Buy } from '../../src/command/stamp/buy'

describeCommand(
'Test Reupload command',
({ consoleMessages, hasMessageContaining }) => {
it('should reupload pinned content and add it to the upload history', async () => {
// 1. Upload with --pin so there is locally pinned content
const uploadBuilder = await invokeTestCli([
'upload',
`${__dirname}/../testpage/images/swarm.png`,
'--pin',
...getStampOption(),
])
const uploadCommand = uploadBuilder.runnable as Upload
const reference = uploadCommand.result.getOrThrow().toHex()

// assert the upload itself succeeded before moving on
expect(uploadCommand.name).toBe('upload')
expect(reference).toHaveLength(64)
expect(hasMessageContaining('Swarm hash')).toBeTruthy()

consoleMessages.length = 0 // clear messages from the upload

// 2. buy a NEW stamp for the reupload
const buyExecution = await invokeTestCli([
'stamp',
'buy',
'--depth',
'20',
'--amount',
'555m',
'--wait-usable',
'--yes',
])
const newStampId = (buyExecution.runnable as Buy).postageBatchId.toHex()
expect(newStampId).not.toBe(getStampOption()[1])

consoleMessages.length = 0

// 3. Reupload it
const reuploadBuilder = await invokeTestCli(['reupload', reference, '--stamp', newStampId])
expect(hasMessageContaining('Reuploaded successfully')).toBeTruthy()

// 4. Verify the history entry
const reuploadCommand = reuploadBuilder.runnable as Reupload
const historyPath = (reuploadCommand as any).commandConfig.getHistoryFilePath()

Check warning on line 52 in test/command/reupload.spec.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Unexpected any. Specify a different type
const items = JSON.parse(readFileSync(historyPath, 'utf-8')) as HistoryItem[]

const lastItem = items[items.length - 1]
expect(lastItem.reference).toBe(reference)
expect(lastItem.uploadType).toBe('reupload')
expect(lastItem.path).toBeNull()
expect(lastItem.stamp).toBe(newStampId)
})
},
{ configFileName: 'reupload' },
)
Loading
Loading