braid-text 0.2.5 → 0.2.7
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/README.md +1 -1
- package/index.js +5 -5
- package/package.json +1 -1
- package/server-demo.js +5 -13
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Now open these URLs in your browser:
|
|
|
35
35
|
|
|
36
36
|
Or try opening the URL in [Braid-Chrome](https://github.com/braid-org/braid-chrome), or [another Braid client](https://bloop.monster/simpleditor), to edit it directly!
|
|
37
37
|
|
|
38
|
-
Check out the `server-demo.js` file to see examples for how to add access control, and a `/pages` endpoint to show all the edited pages.
|
|
38
|
+
Check out the `server-demo.js` file to see examples for how to add simple access control, where a user need only enter a password into a cookie in the javascript console like: `document.cookie = 'password'`; and a `/pages` endpoint to show all the edited pages.
|
|
39
39
|
|
|
40
40
|
## General Use on Server
|
|
41
41
|
|
package/index.js
CHANGED
|
@@ -386,9 +386,12 @@ braid_text.put = async (key, options) => {
|
|
|
386
386
|
|
|
387
387
|
let og_v = version?.[0] || `${(is_valid_actor(peer) && peer) || Math.random().toString(36).slice(2, 7)}-${change_count - 1}`
|
|
388
388
|
|
|
389
|
-
// reduce the version sequence by the number of char-edits
|
|
390
389
|
let v = decode_version(og_v)
|
|
391
390
|
|
|
391
|
+
resource.length_cache.put(`${v[0]}-${v[1]}`, patches.reduce((a, b) =>
|
|
392
|
+
a + (b.content_codepoints.length ? b.content_codepoints.length : -(b.range[1] - b.range[0])),
|
|
393
|
+
max_pos))
|
|
394
|
+
|
|
392
395
|
// validate version: make sure we haven't seen it already
|
|
393
396
|
if (v[1] <= (resource.actor_seqs[v[0]] ?? -1)) {
|
|
394
397
|
|
|
@@ -453,10 +456,7 @@ braid_text.put = async (key, options) => {
|
|
|
453
456
|
}
|
|
454
457
|
resource.actor_seqs[v[0]] = v[1]
|
|
455
458
|
|
|
456
|
-
|
|
457
|
-
a + (b.content_codepoints.length ? b.content_codepoints.length : -(b.range[1] - b.range[0])),
|
|
458
|
-
max_pos))
|
|
459
|
-
|
|
459
|
+
// reduce the version sequence by the number of char-edits
|
|
460
460
|
v = `${v[0]}-${v[1] + 1 - change_count}`
|
|
461
461
|
|
|
462
462
|
let ps = og_parents
|
package/package.json
CHANGED
package/server-demo.js
CHANGED
|
@@ -77,22 +77,14 @@ var server = require("http").createServer(async (req, res) => {
|
|
|
77
77
|
// return
|
|
78
78
|
// }
|
|
79
79
|
|
|
80
|
-
// TODO: uncomment
|
|
81
|
-
//
|
|
80
|
+
// TODO: uncomment out the code below to add basic access control,
|
|
81
|
+
// where a user logs in by openning the javascript console
|
|
82
|
+
// and entering: document.cookie = 'fake_password'
|
|
82
83
|
//
|
|
83
84
|
// var admin_pass = "fake_password"
|
|
84
|
-
//
|
|
85
|
-
// if (req.url === '/login_' + admin_pass) {
|
|
86
|
-
// res.writeHead(200, {
|
|
87
|
-
// "Content-Type": "text/plain",
|
|
88
|
-
// "Set-Cookie": `admin_pass=${admin_pass}; Path=/`,
|
|
89
|
-
// });
|
|
90
|
-
// res.end("Logged in successfully");
|
|
91
|
-
// return;
|
|
92
|
-
// }
|
|
93
|
-
//
|
|
85
|
+
//
|
|
94
86
|
// if (req.method == "PUT" || req.method == "POST" || req.method == "PATCH") {
|
|
95
|
-
// if (!req.headers.cookie?.
|
|
87
|
+
// if (!req.headers.cookie?.split(/;/).map(x => x.trim()).some(x => x === admin_pass)) {
|
|
96
88
|
// console.log("Blocked PUT:", { cookie: req.headers.cookie })
|
|
97
89
|
// res.statusCode = 401
|
|
98
90
|
// return res.end()
|