braidfs 0.0.69 → 0.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +32 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -90,32 +90,40 @@ console.log(`braidfs version: ${require(`${__dirname}/package.json`).version}`)
90
90
  if (argv.length === 1 && argv[0].match(/^(run|serve)$/)) {
91
91
  return main()
92
92
  } else if (argv.length && argv.length % 2 == 0 && argv.every((x, i) => i % 2 != 0 || x.match(/^(sync|unsync)$/))) {
93
- let operations = []
94
- for (let i = 0; i < argv.length; i += 2) {
95
- var operation = argv[i],
96
- url = argv[i + 1]
97
- if (!url.match(/^https?:\/\//)) {
98
- if (url.startsWith('/')) url = require('path').relative(proxy_base, url)
99
- url = `https://${url}`
100
- }
101
- console.log(`${operation}ing ${url}`)
102
- operations.push({ operation, url })
103
- }
104
- return Promise.all(operations.map(({ operation, url }) =>
105
- braid_fetch(`http://localhost:${config.port}/.braidfs/config`, {
106
- method: 'PUT',
107
- patches: [{
108
- unit: 'json',
109
- range: `sync[${JSON.stringify(url)}]`,
110
- content: operation === 'sync' ? 'true' : ''
111
- }]
112
- }).then(() => console.log(`${operation}ed: ${url}`))
113
- )).then(() => console.log('All operations completed successfully.'))
114
- .catch(() => {
115
- return console.log(`The braidfs daemon does not appear to be running.
93
+ return (async () => {
94
+ for (let i = 0; i < argv.length; i += 2) {
95
+ var operation = argv[i],
96
+ url = argv[i + 1]
97
+ if (!url.match(/^https?:\/\//)) {
98
+ if (url.startsWith('/')) url = require('path').relative(proxy_base, url)
99
+ url = `https://${url}`
100
+ }
101
+ console.log(`${operation}ing ${url}`)
102
+ try {
103
+ var res = await braid_fetch(`http://localhost:${config.port}/.braidfs/config`, {
104
+ method: 'PUT',
105
+ patches: [{
106
+ unit: 'json',
107
+ range: `sync[${JSON.stringify(url)}]`,
108
+ content: operation === 'sync' ? 'true' : ''
109
+ }]
110
+ })
111
+ if (res.ok) {
112
+ console.log(`${operation}ed: ${url}`)
113
+ } else {
114
+ console.log(`failed to ${operation} ${url}`)
115
+ console.log(`server responded with ${res.status}: ${await res.text()}`)
116
+ return
117
+ }
118
+ } catch (e) {
119
+ console.log(`The braidfs daemon does not appear to be running.
116
120
  You can run it with:
117
121
  braidfs run${to_run_in_background}`)
118
- })
122
+ return
123
+ }
124
+ }
125
+ console.log('All operations completed successfully.')
126
+ })()
119
127
  } else {
120
128
  return console.log(`Usage:
121
129
  braidfs run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",