-
Notifications
You must be signed in to change notification settings - Fork 25
feat: move reupload command to root level #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -224,6 +224,7 @@ Run 'swarm-cli GROUP --help' to see available commands in a group | |
|
|
||
| █ Available Commands: | ||
|
|
||
| reupload Reupload locally pinned content | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| 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' | ||
|
|
@@ -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.' }) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message no longer makes sense as a root level command. |
||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,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() | ||
| 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' }, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed