braid-text 0.3.23 → 0.3.24
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.
- package/client/cursor-highlights.js +2 -1
- package/client/cursor-sync.js +4 -2
- package/package.json +1 -1
- package/server.js +14 -7
|
@@ -297,7 +297,7 @@ function peer_bg_color(peer_id) {
|
|
|
297
297
|
// cursors.on_edit(patches) // call after local edit; patches optional
|
|
298
298
|
// cursors.destroy()
|
|
299
299
|
//
|
|
300
|
-
function cursor_highlights(textarea, url) {
|
|
300
|
+
function cursor_highlights(textarea, url, options) {
|
|
301
301
|
var peer = Math.random().toString(36).slice(2)
|
|
302
302
|
var hl = textarea_highlights(textarea)
|
|
303
303
|
var applying_remote = false
|
|
@@ -307,6 +307,7 @@ function cursor_highlights(textarea, url) {
|
|
|
307
307
|
|
|
308
308
|
cursor_client(url, {
|
|
309
309
|
peer,
|
|
310
|
+
headers: options?.headers,
|
|
310
311
|
get_text: () => textarea.value,
|
|
311
312
|
on_change: (sels) => {
|
|
312
313
|
for (var [id, ranges] of Object.entries(sels)) {
|
package/client/cursor-sync.js
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
// cursors.changed(patches)
|
|
16
16
|
// cursors.destroy()
|
|
17
17
|
//
|
|
18
|
-
async function cursor_client(url, { peer, get_text, on_change }) {
|
|
18
|
+
async function cursor_client(url, { peer, get_text, on_change, headers: user_headers }) {
|
|
19
19
|
// --- feature detection: HEAD probe ---
|
|
20
20
|
try {
|
|
21
21
|
var head_res = await braid_fetch(url, {
|
|
22
22
|
method: 'HEAD',
|
|
23
|
-
headers: { 'Accept': 'application/text-cursors+json' }
|
|
23
|
+
headers: { ...user_headers, 'Accept': 'application/text-cursors+json' }
|
|
24
24
|
})
|
|
25
25
|
var ct = head_res.headers.get('content-type') || ''
|
|
26
26
|
if (!ct.includes('application/text-cursors+json')) return null
|
|
@@ -124,6 +124,7 @@ async function cursor_client(url, { peer, get_text, on_change }) {
|
|
|
124
124
|
braid_fetch(url, {
|
|
125
125
|
method: 'PUT',
|
|
126
126
|
headers: {
|
|
127
|
+
...user_headers,
|
|
127
128
|
'Content-Type': 'application/text-cursors+json',
|
|
128
129
|
Peer: peer,
|
|
129
130
|
'Content-Range': 'json [' + JSON.stringify(peer) + ']',
|
|
@@ -155,6 +156,7 @@ async function cursor_client(url, { peer, get_text, on_change }) {
|
|
|
155
156
|
}},
|
|
156
157
|
peer,
|
|
157
158
|
headers: {
|
|
159
|
+
...user_headers,
|
|
158
160
|
Accept: 'application/text-cursors+json',
|
|
159
161
|
Heartbeats: '10',
|
|
160
162
|
},
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -578,7 +578,9 @@ function create_braid_text() {
|
|
|
578
578
|
|
|
579
579
|
res.setHeader("Version", get_current_version())
|
|
580
580
|
|
|
581
|
-
options.put_cb(options.key, resource.val,
|
|
581
|
+
options.put_cb(options.key, resource.val,
|
|
582
|
+
{old_val, patches: put_patches,
|
|
583
|
+
version: resource.version, parents: old_version})
|
|
582
584
|
} catch (e) {
|
|
583
585
|
console.log(`${req.method} ERROR: ${e.stack}`)
|
|
584
586
|
return done_my_turn(500, "The server failed to apply this version. The error generated was: " + e)
|
|
@@ -3114,12 +3116,17 @@ async function handle_cursors(resource, req, res) {
|
|
|
3114
3116
|
res.sendUpdate({ body: JSON.stringify(cursors.snapshot()) })
|
|
3115
3117
|
}
|
|
3116
3118
|
} else if (req.method === 'PUT' || req.method === 'POST' || req.method === 'PATCH') {
|
|
3117
|
-
var raw_body
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3119
|
+
var raw_body
|
|
3120
|
+
if (req.already_buffered_body != null) {
|
|
3121
|
+
raw_body = req.already_buffered_body.toString()
|
|
3122
|
+
} else {
|
|
3123
|
+
raw_body = await new Promise((resolve, reject) => {
|
|
3124
|
+
var chunks = []
|
|
3125
|
+
req.on('data', chunk => chunks.push(chunk))
|
|
3126
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString()))
|
|
3127
|
+
req.on('error', reject)
|
|
3128
|
+
})
|
|
3129
|
+
}
|
|
3123
3130
|
var range = req.headers['content-range']
|
|
3124
3131
|
if (!range || !range.startsWith('json ')) {
|
|
3125
3132
|
res.writeHead(400)
|