Skip to content

Commit

Permalink
chore: optimise manifest sync (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Feb 8, 2024
1 parent 90fc2d0 commit bb66ea8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/command/feed/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export class Print extends FeedCommand implements LeafCommand {
spinner.stop()
this.console.verbose(createKeyValue('Chunk Reference', reference))
this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`))
this.console.verbose(createKeyValue('Feed Index', feedIndex))
this.console.verbose(createKeyValue('Feed Index', feedIndex as string))
this.console.verbose(createKeyValue('Next Index', feedIndexNext))
this.console.verbose(createKeyValue('Feed Manifest', manifest))

this.console.quiet(manifest)
this.console.log(createKeyValue('Topic', `${topic}`))
this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`))
this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex, 16) + 1))
this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex as string, 16) + 1))
} catch (error) {
spinner.stop()
const message = getFieldOrNull(error, 'message')
Expand Down
15 changes: 8 additions & 7 deletions src/command/manifest/sync.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { makeChunkedFile } from '@fairdatasociety/bmt-js'
import chalk from 'chalk'
import { readFileSync } from 'fs'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { Reference } from 'mantaray-js'
import { join } from 'path'
import { makeChunkedFile } from '@fairdatasociety/bmt-js'
import { pickStamp } from '../../service/stamp'
import { readdirDeepAsync } from '../../utils'
import { BzzAddress } from '../../utils/bzz-address'
import { bytesToHex } from '../../utils/hex'
import { stampProperties } from '../../utils/option'
import { ManifestCommand } from './manifest-command'
import { bytesToHex } from '../../utils/hex'

export class Sync extends ManifestCommand implements LeafCommand {
public readonly name = 'sync'
Expand Down Expand Up @@ -57,23 +58,23 @@ export class Sync extends ManifestCommand implements LeafCommand {
const localAddress = bytesToHex(rootChunk.address())

if (localAddress === remoteAddress) {
this.console.log('ok -> ' + file)
this.console.log(chalk.gray(file) + ' ' + chalk.blue('UNCHANGED'))
} else {
const { reference } = await this.bee.uploadData(this.stamp, readFileSync(join(this.folder, file)))
const { reference } = await this.bee.uploadData(this.stamp, localData)
node.addFork(this.encodePath(file), Buffer.from(reference, 'hex') as Reference)
this.console.log('updated -> ' + file)
this.console.log(chalk.gray(file) + ' ' + chalk.yellow('CHANGED'))
}
} else {
const { reference } = await this.bee.uploadData(this.stamp, readFileSync(join(this.folder, file)))
node.addFork(this.encodePath(file), Buffer.from(reference, 'hex') as Reference)
this.console.log('new -> ' + file)
this.console.log(chalk.gray(file) + ' ' + chalk.green('NEW'))
}
}

if (this.remove) {
for (const fork of Object.values(forks).filter(x => !x.found)) {
node.removePath(this.encodePath(fork.path))
this.console.log('removed -> ' + fork.path)
this.console.log(chalk.gray(fork.path) + ' ' + chalk.red('REMOVED'))
}
}
await this.saveAndPrintNode(node, this.stamp)
Expand Down

0 comments on commit bb66ea8

Please sign in to comment.