- commit
- b019e05dbe9f06e8310e220f1724a1ed8dd7d737
- parent
- 999c372e054a971af726711f0f54ab459a0c8965
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-10-15 09:21
rm storage code
Diffstat
M | static/pad.js | 31 | +------------------------------ |
M | static/utils.js | 1 | - |
M | static/via.js | 23 | +++-------------------- |
3 files changed, 4 insertions, 51 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -17,12 +17,6 @@ var stagedChanges = []; 17 17 18 18 document.title += ' - ' + location.hash.slice(1); 19 1920 -1 var backup = utils.throttled(function() {21 -1 if (!el.readonly) {22 -1 via.store(room, el.value, true);23 -1 }24 -1 }, 10000);25 -126 20 var sendChanges = utils.throttled(function() { 27 21 if (stagedChanges.length) { 28 22 setTimeout(sendChanges, 500); @@ -75,43 +69,20 @@ el.addEventListener('input', function() { 75 69 diff.pushChange(localChanges, change); 76 70 old = el.value; 77 71 sendChanges();78 -1 backup();79 72 }); 80 73 81 74 via.listen(room, function(msg) { 82 75 if (msg[1] === 'open') {83 -1 // request current document from peers84 -1 via.send(room, [id, 'request']);85 -186 -1 // fall back to last saved document after timeout87 -1 setTimeout(function() {88 -1 if (!el.value) {89 -1 via.restore(room).then(text => {90 -1 if (!el.value) {91 -1 el.value = text;92 -1 old = text;93 -1 }94 -1 }).finally(() => {95 -1 el.readOnly = false;96 -1 });97 -1 }98 -1 }, 1000);-1 76 el.readOnly = false; 99 77 } else if (msg[1] === 'changes' && !el.readOnly) { 100 78 if (msg[0] === id) { 101 79 stagedChanges = []; 102 80 } else { 103 81 applyChanges(msg[2]); 104 82 }105 -1 } else if (msg[1] === 'request' && msg[0] !== id) {106 -1 via.send(room, [id, 'text', el.value]);107 -1 } else if (msg[1] === 'text' && !el.value) {108 -1 el.value = msg[2];109 -1 old = msg[2];110 -1 el.readOnly = false;111 83 } 112 84 }); 113 85114 -1 window.addEventListener('beforeunload', backup.unthrottled);115 86 window.addEventListener('offline', function() { 116 87 el.readOnly = true; 117 88 });
diff --git a/static/utils.js b/static/utils.js
@@ -22,6 +22,5 @@ export var throttled = function(fn, timeout) { 22 22 } 23 23 }; 24 2425 -1 wrapper.unthrottled = fn;26 25 return wrapper; 27 26 };
diff --git a/static/via.js b/static/via.js
@@ -1,16 +1,9 @@ 1 1 var baseUrl = 'https://via.ce9e.org/'; 2 23 -1 var post = function(key, data, beacon) {-1 3 export var send = function(key, data) { -1 4 var url = baseUrl + 'msg/' + key; 4 5 var body = JSON.stringify(data);5 -1 if (beacon) {6 -1 return navigator.sendBeacon(baseUrl + key, body);7 -1 } else {8 -1 return fetch(baseUrl + key, {method: 'POST', body: body});9 -1 }10 -1 };11 -112 -1 export var send = function(key, data, beacon) {13 -1 return post('msg/' + key, data, beacon);-1 6 return fetch(url, {method: 'POST', body: body}); 14 7 }; 15 8 16 9 export var listen = function(key, fn) { @@ -18,13 +11,3 @@ export var listen = function(key, fn) { 18 11 evtSource.onmessage = msg => fn(JSON.parse(msg.data)); 19 12 evtSource.onopen = () => fn([null, 'open']); 20 13 };21 -122 -1 export var store = function(key, data, beacon) {23 -1 return post('store/' + key, data, beacon);24 -1 };25 -126 -1 export var restore = function(key) {27 -1 return fetch(baseUrl + 'store/' + key)28 -1 .then(r => r.text())29 -1 .then(s => JSON.parse(s));30 -1 };