Skip to content

Commit c5a7537

Browse files
committed
Add an option to upload the graph content to a specified URL
1 parent f81daad commit c5a7537

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

examples/cmd.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
const yargs = require( 'yargs' );
33
const fs = require( 'fs' );
4+
const fetch = require( 'node-fetch' );
45

56
const argv = yargs
67
.option( 'graph', {
@@ -89,16 +90,29 @@ const argv = yargs
8990
}
9091
)
9192
.command(
92-
'download <dir>',
93-
'Export your Roam database to a selected directory.',
93+
'export <dir> [exporturl]',
94+
'Export your Roam database to a selected directory. If URL is provided, then the concent will be sent by POST request to the specified URL.',
9495
() => {},
9596
( argv ) => {
9697
const RoamPrivateApi = require( '../' );
9798
const api = new RoamPrivateApi( argv.graph, argv.email, argv.password, {
9899
headless: ! argv.debug,
99100
folder: argv['dir']
100101
} );
101-
api.getExportData( argv['removezip'] ).then( data => console.log( 'Downloaded' ) );
102+
let promises = api.getExportData( argv['removezip'] );
103+
promises.then( data => console.log( 'Downloaded' ) );
104+
if ( argv['exporturl'] ) {
105+
promises.then( data => fetch( argv['exporturl'], {
106+
method: 'post',
107+
body: JSON.stringify( {
108+
graphContent: data,
109+
graphName: api.graph
110+
} ),
111+
headers: {'Content-Type': 'application/json'}
112+
} ) )
113+
.catch( err => console.log( err ) )
114+
.then( () => console.log( "Uploaded to export url." ) )
115+
}
102116
}
103117
)
104118
.help()

0 commit comments

Comments
 (0)