braid-text 0.0.10 → 0.0.12

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 CHANGED
@@ -16,6 +16,8 @@ This library provides a simple http route handler, along with client code, enabl
16
16
 
17
17
  This library makes it safe, easy & efficient to add collaborative text editing to every user-editable string in your web app. Make your app multiplayer!
18
18
 
19
+ Check out the [**demo video**](https://braid.org/video/https://invisiblecollege.s3.us-west-1.amazonaws.com/braid-meeting-86.mp4#4755) 📺 from the Braid 86 release!
20
+
19
21
  ### Demo: a Wiki!
20
22
 
21
23
  This will run a collaboratively-editable wiki:
package/index.js CHANGED
@@ -1273,29 +1273,23 @@ function codePoints_to_index(str, codePoints) {
1273
1273
  }
1274
1274
 
1275
1275
  function encode_filename(filename) {
1276
- // Replace all '!' with '%21'
1277
- let encoded = filename.replace(/!/g, '%21');
1278
-
1279
- // Encode the filename using encodeURIComponent()
1280
- encoded = encodeURIComponent(encoded);
1281
-
1282
- // Replace all '%2F' (for '/') with '!'
1283
- encoded = encoded.replace(/%2F/g, '!');
1284
-
1285
- return encoded;
1276
+ // Swap all "!" and "/" characters
1277
+ let swapped = filename.replace(/[!/]/g, (match) => (match === "!" ? "/" : "!"))
1278
+
1279
+ // Encode the filename using encodeURIComponent()
1280
+ let encoded = encodeURIComponent(swapped)
1281
+
1282
+ return encoded
1286
1283
  }
1287
1284
 
1288
1285
  function decode_filename(encodedFilename) {
1289
- // Replace all '!' with '%2F'
1290
- let decoded = encodedFilename.replace(/!/g, '%2F');
1291
-
1292
- // Decode the filename using decodeURIComponent()
1293
- decoded = decodeURIComponent(decoded);
1294
-
1295
- // Replace all '%21' with '!'
1296
- decoded = decoded.replace(/%21/g, '!');
1297
-
1298
- return decoded;
1286
+ // Decode the filename using decodeURIComponent()
1287
+ let decoded = decodeURIComponent(encodedFilename)
1288
+
1289
+ // Swap all "/" and "!" characters
1290
+ decoded = decoded.replace(/[!/]/g, (match) => (match === "/" ? "!" : "/"))
1291
+
1292
+ return decoded
1299
1293
  }
1300
1294
 
1301
1295
  module.exports = braid_text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidjs",
package/server-demo.js CHANGED
@@ -11,6 +11,11 @@ var braid_text = require("./index.js")
11
11
  var server = require("http").createServer(async (req, res) => {
12
12
  console.log(`${req.method} ${req.url}`)
13
13
 
14
+ // Free the CORS
15
+ free_the_cors(req, res)
16
+ if (req.method === 'OPTIONS') return
17
+
18
+
14
19
  if (req.url.endsWith("?editor")) {
15
20
  res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache" })
16
21
  require("fs").createReadStream("./editor.html").pipe(res)
@@ -30,9 +35,6 @@ var server = require("http").createServer(async (req, res) => {
30
35
  // var pages = await braid_text.list()
31
36
  // res.writeHead(200, {
32
37
  // "Content-Type": "application/json",
33
- // "Access-Control-Allow-Origin": "*",
34
- // "Access-Control-Allow-Methods": "*",
35
- // "Access-Control-Allow-Headers": "*",
36
38
  // "Access-Control-Expose-Headers": "*"
37
39
  // })
38
40
  // res.end(JSON.stringify(pages))
@@ -73,3 +75,21 @@ var server = require("http").createServer(async (req, res) => {
73
75
  server.listen(port, () => {
74
76
  console.log(`server started on port ${port}`)
75
77
  })
78
+
79
+
80
+ // Free the CORS!
81
+ function free_the_cors (req, res) {
82
+ res.setHeader('Range-Request-Allow-Methods', 'PATCH, PUT')
83
+ res.setHeader('Range-Request-Allow-Units', 'json')
84
+ res.setHeader("Patches", "OK")
85
+ var free_the_cors = {
86
+ "Access-Control-Allow-Origin": "*",
87
+ "Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, UNSUBSCRIBE",
88
+ "Access-Control-Allow-Headers": "subscribe, client, version, parents, merge-type, content-type, content-range, patches, cache-control, peer"
89
+ }
90
+ Object.entries(free_the_cors).forEach(x => res.setHeader(x[0], x[1]))
91
+ if (req.method === 'OPTIONS') {
92
+ res.writeHead(200)
93
+ res.end()
94
+ }
95
+ }