Skip to content

Commit

Permalink
Implement export cmd (bluesky-social#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms authored Apr 12, 2022
1 parent 60e0b49 commit 36f7520
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.DS_STORE
DS_STORE
node_modules
yarn-error.log
dist
analytics.txt

Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './interactions/like.js'
import './interactions/unlike.js'
// import './net/pull.js'
// import './repo/pull.js'
import './repo/export.js'
import './posts/delete-post.js'
import './posts/edit-post.js'
import './posts/feed.js'
Expand Down
20 changes: 20 additions & 0 deletions cli/src/commands/repo/export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import cmd from '../../lib/command.js'
import path from 'path'
import { promises as fsp } from 'fs'
import { loadDelegate } from '../../lib/client.js'
import { REPO_PATH } from '../../lib/env.js'

export default cmd({
name: 'export',
category: 'repo',
help: 'Export repo as a CAR file',
args: [],
opts: [],
async command(args) {
const client = await loadDelegate(REPO_PATH)
const car = await client.export()
const p = path.join(REPO_PATH, 'export.car')
await fsp.writeFile(p, car)
console.log('Exported repo to: ', p)
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cmd from '../../lib/command.js'

export default cmd({
name: 'pull',
category: 'net',
category: 'repo',
help: 'Pull the latest data for all followed users or for a given user.',
args: [{ name: 'id', optional: true }],
opts: [],
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const registeredCommands: RegisteredCmd[] = []

export const CATEGORIES = {
setup: 'Setup',
net: 'Networking',
repo: 'Repo',
social: 'Social',
posts: 'Posts',
interactions: 'Interactions',
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function usage(err: any) {
cats.push({ label: CATEGORIES[category], lhs, rhs })
}
addcat('setup')
addcat('net')
addcat('repo')
addcat('social')
addcat('posts')
addcat('interactions')
Expand Down
8 changes: 8 additions & 0 deletions common/src/microblog/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ export class MicroblogDelegator {
throw new Error(err.message)
}
}

async export(): Promise<Uint8Array> {
const car = await service.pullRepo(this.url, this.did)
if (car === null) {
throw new Error(`Could not fetch repo ${this.did} from ${this.url}`)
}
return car
}
}

export default MicroblogDelegator

0 comments on commit 36f7520

Please sign in to comment.