| 81 | |
| 82 | //var isNew = false; |
| 83 | var checkSession = function (oldKey, cb) { |
| 84 | var channel = Hash.hrefToHexChannelId(Hash.hashToHref(oldKey)); |
| 85 | var prefix = channel.slice(0,2); |
| 86 | var url = `/datastore/${prefix}/${channel}.ndjson`; |
| 87 | |
| 88 | var http = new XMLHttpRequest(); |
| 89 | http.open('HEAD', url); |
| 90 | http.onreadystatechange = function() { |
| 91 | if (this.readyState === this.DONE) { |
| 92 | if (devMode) { console.error(oldKey, this.status); } |
| 93 | if (this.status === 200) { |
| 94 | return cb({state: true}); |
| 95 | } |
| 96 | if (this.status === 404) { |
| 97 | return cb({state: false}); |
| 98 | } |
| 99 | cb({error: 'Internal server error'}); |
| 100 | } |
| 101 | }; |
| 102 | http.send(); |
| 103 | }; |
| 104 | let sanitizeKey = key => { |
| 105 | try { |
| 106 | Util.decodeBase64(key.replace(/-/g, '/')); |