Skip to content
Merged
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
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 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]
}
40 changes: 0 additions & 40 deletions src/command/pinning/reupload.ts

This file was deleted.

52 changes: 52 additions & 0 deletions src/command/reupload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Argument, LeafCommand, Option } from 'furious-commander'
import { pickStamp } from '../service/stamp'
import { stampProperties } from '../utils/option'
import { RootCommand } from './root-command'
import { History } from '../service/history'

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

public readonly name = 'reupload'

public readonly description = 'Reupload and restamp content on the network'

@Argument({
key: 'address',
type: 'hex-string',
description: 'Pin address, reference of the collection or feed',
required: true,
length: 64,
})
public address!: string

@Option(stampProperties)
public stamp!: string

public async run(): Promise<void> {
await super.init()

if (!this.stamp) {
this.stamp = await pickStamp(this.bee, this.console)
}

this.console.log('Reuploading ' + this.address + '...')
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 content found with that address.' })
}
}
}
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
}
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