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
38 changes: 26 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"cafe-utility": "^33.3.1",
"chalk": "^2.4.2",
"cli-progress": "^3.11.2",
"cli-table3": "^0.6.5",
"ethers": "^5.7.2",
"furious-commander": "^1.7.1",
"inquirer": "^8.2.5",
Expand Down
6 changes: 5 additions & 1 deletion src/command/feed/feed-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class FeedCommand extends RootCommand {
this.console.error('The provided identity does not exist. Please select one that exists.')
}

return identities[this.identity] || identities[await pickIdentity(this.commandConfig, this.console)]
if (!identities[this.identity]) {
this.identity = await pickIdentity(this.commandConfig, this.console)
}

return identities[this.identity]
}

private async writeFeed(stamp: string, wallet: Wallet, topic: Topic, chunkReference: Reference): Promise<FeedInfo> {
Expand Down
11 changes: 11 additions & 0 deletions src/command/feed/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { pickStamp } from '../../service/stamp'
import { stampProperties } from '../../utils/option'
import { Upload as FileUpload } from '../upload'
import { FeedCommand } from './feed-command'
import { History } from '../../service/history'

export class Upload extends FeedCommand implements LeafCommand {
public readonly name = 'upload'
Expand Down Expand Up @@ -34,6 +35,16 @@ export class Upload extends FeedCommand implements LeafCommand {

const reference = await this.runUpload()
this.feedManifest = await this.updateFeedAndPrint(this.stamp, reference)
const history = new History(this.commandConfig.configFolderPath, this.console)
history.addItem({
timestamp: Date.now(),
reference: reference.toHex(),
stamp: this.stamp,
path: this.fileUpload.path,
uploadType: this.fileUpload.uploadType(),
feedIdentity: this.identity,
feedAddress: this.feedManifest.toHex(),
})
this.console.dim('Successfully uploaded to feed.')
}

Expand Down
3 changes: 3 additions & 0 deletions src/command/history/history-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RootCommand } from '../root-command'

export class HistoryCommand extends RootCommand {}
11 changes: 11 additions & 0 deletions src/command/history/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GroupCommand } from 'furious-commander'
import { List } from './list'
import { Show } from './show'

export class History implements GroupCommand {
public readonly name = 'history'

public readonly description = 'Get upload history'

public subCommandClasses = [List, Show]
}
40 changes: 40 additions & 0 deletions src/command/history/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { HistoryCommand } from './history-command'
import { History } from '../../service/history'
import Table from 'cli-table3'
import { LeafCommand } from 'furious-commander'
import { ellipsis } from '../../utils/text'
import { HistoryItem } from '../../service/history/types/history-item'

export class List extends HistoryCommand implements LeafCommand {
public readonly name = 'list'
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.

Please add alias ls


public readonly alias = 'ls'

public readonly description = 'Get upload history list'

public run() {
super.init()
const table = new Table({
head: ['Index', 'Timestamp', 'Reference', 'Postage stamp batch ID', 'File path', 'Upload type'],
style: {
head: ['green', 'bold'],
},
wordWrap: true,
})

const history = new History(this.commandConfig.configFolderPath, this.console)
table.push(
...history
.getItems()
.map((h: HistoryItem) => [
h.index,
new Date(h.timestamp).toLocaleString(),
h.reference.slice(0, 12),
ellipsis(h.stamp, 6, -6),
h.path,
h.uploadType,
]),
)
this.console.log(table.toString())
}
}
46 changes: 46 additions & 0 deletions src/command/history/show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { HistoryCommand } from './history-command'
import { Argument, LeafCommand } from 'furious-commander'
import { createKeyValue } from '../../utils/text'
import { exit } from 'process'
import { History } from '../../service/history'

export class Show extends HistoryCommand implements LeafCommand {
public readonly name = 'show'

public readonly description = 'Get upload history item'

@Argument({
key: 'index',
description: 'Index of the history item',
required: true,
type: 'number',
})
public index!: number

public run() {
super.init()
const history = new History(this.commandConfig.configFolderPath, this.console)
const historyItem = history.getItemByIndex(this.index)

if (historyItem === undefined) {
this.console.error(`Cound not find history item with index '${this.index}'`)
exit(1)
}
this.console.log(createKeyValue('Timestamp', new Date(historyItem.timestamp).toUTCString()))
this.console.log(createKeyValue('Swarm hash', historyItem.reference))
this.console.log(createKeyValue('Stamp ID', historyItem.stamp))
this.console.log(createKeyValue('Upload type', historyItem.uploadType))

if (historyItem.path) {
this.console.log(createKeyValue('Path', historyItem.path))
}

if (historyItem.feedAddress) {
this.console.log(createKeyValue('Feed address', historyItem.feedAddress))
}

if (historyItem.feedIdentity) {
this.console.log(createKeyValue('Feed identity', historyItem.feedIdentity))
}
}
}
29 changes: 28 additions & 1 deletion src/command/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createSpinner } from '../utils/spinner'
import { createKeyValue, warningSymbol, warningText } from '../utils/text'
import { RootCommand } from './root-command'
import { VerbosityLevel } from './root-command/command-log'
import { History } from '../service/history'

export class Upload extends RootCommand implements LeafCommand {
public readonly name = 'upload'
Expand Down Expand Up @@ -166,7 +167,8 @@ export class Upload extends RootCommand implements LeafCommand {
const url = await this.uploadAnyWithSpinner(tag, uploadingFolder)

this.console.dim('Data has been sent to the Bee node successfully!')
this.console.log(createKeyValue('Swarm hash', this.result.getOrThrow().toHex()))
const swarmHash = this.result.getOrThrow().toHex()
this.console.log(createKeyValue('Swarm hash', swarmHash))

if (this.act) {
this.console.log(createKeyValue('Swarm history address', this.historyAddress.getOrThrow().toHex()))
Expand All @@ -180,6 +182,18 @@ export class Upload extends RootCommand implements LeafCommand {
this.console.dim('Uploading was successful!')
this.console.log(createKeyValue('URL', url))

const history = new History(this.commandConfig.configFolderPath, this.console)

if (!usedFromOtherCommand) {
history.addItem({
timestamp: Date.now(),
reference: swarmHash,
stamp: this.stamp,
path: this.path,
uploadType: this.uploadType(),
})
}

if (!usedFromOtherCommand) {
this.console.quiet(this.result.getOrThrow().toHex())

Expand Down Expand Up @@ -512,4 +526,17 @@ export class Upload extends RootCommand implements LeafCommand {
throw new CommandLineError(`Invalid redundancy level: ${this.redundancy}`)
}
}

public uploadType(): 'stdin' | 'folder' | 'file' {
if (this.stdin) {
return 'stdin'
}
const stats = FS.lstatSync(this.path)

if (stats.isDirectory()) {
return 'folder'
} else {
return 'file'
}
}
}
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Status } from './command/status'
import { Upload } from './command/upload'
import { Utility } from './command/utility'
import { Wallet } from './command/wallet'
import { History } from './command/history'

export const beeApiUrl: IOption<string> = {
key: 'bee-api-url',
Expand Down Expand Up @@ -133,4 +134,5 @@ export const rootCommandClasses = [
Utility,
Grantee,
Quickstart,
History,
]
Loading