braid-blob 0.0.77 → 0.0.78

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/img-live.js +14 -5
  2. package/package.json +1 -1
package/img-live.js CHANGED
@@ -9,19 +9,28 @@ function sync(img) {
9
9
  var url = img.src
10
10
  if (!url) return
11
11
 
12
+ // Find an unused query parameter name for cache-busting
13
+ var param = 'img-live'
14
+ var u = new URL(url)
15
+ while (u.searchParams.has(param)) param = '-' + param
16
+ function cache_bust() {
17
+ u.searchParams.set(param, Math.random().toString(36).slice(2))
18
+ return u.toString()
19
+ }
20
+
12
21
  // Unsync first to handle attribute changes (e.g. droppable added/removed)
13
22
  unsync(img)
14
23
 
15
24
  var ac = new AbortController()
16
25
  var client_p = (async () => {
17
- var res = await braid_fetch(url, {
26
+ var res = await braid_fetch(cache_bust(), {
18
27
  method: 'HEAD',
19
28
  headers: { "Merge-Type": "aww" },
20
29
  subscribe: true,
21
30
  retry: () => true,
22
31
  signal: ac.signal
23
32
  })
24
- return braid_blob_client(url, {
33
+ return braid_blob_client(cache_bust(), {
25
34
  signal: ac.signal,
26
35
  parents: res.version,
27
36
  on_update: (body, content_type, version, from_local_update) => {
@@ -30,12 +39,12 @@ function sync(img) {
30
39
  img.src = URL.createObjectURL(blob)
31
40
  } else {
32
41
  img.src = ''
33
- img.src = url
42
+ img.src = cache_bust()
34
43
  }
35
44
  },
36
45
  on_delete: () => {
37
46
  img.src = ''
38
- img.src = url
47
+ img.src = cache_bust()
39
48
  },
40
49
  on_error: (error) => {
41
50
  console.error('Live image error for', url, error)
@@ -71,7 +80,7 @@ function sync(img) {
71
80
  var reader = new FileReader()
72
81
  reader.onload = async function() {
73
82
  await (await client_p).update(reader.result, file.type)
74
- img.src = url
83
+ img.src = cache_bust()
75
84
  }
76
85
  reader.readAsArrayBuffer(file)
77
86
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.77",
3
+ "version": "0.0.78",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",