@subiz/widget-v4 4.1.123 → 4.1.125
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/compiled_src/chatbox/Events.js +1 -1
- package/compiled_src/plugin.js +1 -0
- package/compiled_src/store/api.js +0 -1
- package/compiled_src/store/api_fake.js +0 -1
- package/compiled_src/store/chain.js +228 -0
- package/compiled_src/store/inmem_localstorage.js +33 -0
- package/compiled_src/store/kv.js +86 -0
- package/compiled_src/store/lsdb.js +68 -0
- package/compiled_src/store/store.js +25 -17
- package/dist/132.js +6433 -2574
- package/dist/178.js +406 -0
- package/dist/18a02a9c54e.132.js +1 -0
- package/dist/18a02a9c54e.178.js +1 -0
- package/dist/18a02a9c54e.213.js +1 -0
- package/dist/18a02a9c54e.335.js +1 -0
- package/dist/18a02a9c54e.362.js +1 -0
- package/dist/18a02a9c54e.441.js +1 -0
- package/dist/18a02a9c54e.605.js +1 -0
- package/dist/18a02a9c54e.678.js +1 -0
- package/dist/18a02a9c54e.782.js +1 -0
- package/dist/18a02a9c54e.app.js +1 -0
- package/dist/{1964db39388.index.html → 18a02a9c54e.index.html} +4 -28
- package/dist/{1964db39388.library.html → 18a02a9c54e.library.html} +4 -28
- package/dist/18a02a9c54e.library.js +1 -0
- package/dist/{1964db39388.preview.html → 18a02a9c54e.preview.html} +1 -1
- package/dist/18a02a9c54e.preview.js +1 -0
- package/dist/18a02a9c54e.screenshoot.js +1 -0
- package/dist/18a02a9c54e.webview.js +1 -0
- package/dist/213.js +2780 -0
- package/dist/{74.js → 335.js} +35 -35
- package/dist/362.js +107 -0
- package/dist/441.js +2855 -0
- package/dist/{490.js → 605.js} +82 -82
- package/dist/{997.js → 678.js} +6 -6
- package/dist/782.js +107 -0
- package/dist/HASH +1 -1
- package/dist/assets/img/{subiz-mono.8fbc067.svg → subiz-mono.877e9f5.svg} +1 -1
- package/dist/malicious-app.js +4 -6
- package/dist/screenshoot.html +1 -1
- package/dist/screenshoot.js +4857 -9606
- package/package.json +1 -2
- package/src/chatbox/Events.js +1 -1
- package/src/chatbox/main.js +1 -0
- package/src/plugin.js +2 -0
- package/src/store/api.js +0 -1
- package/src/store/api_fake.js +0 -1
- package/src/store/chain.js +255 -0
- package/src/store/inmem_localstorage.js +40 -0
- package/src/store/kv.js +103 -0
- package/src/store/lsdb.js +74 -0
- package/src/store/store.js +22 -18
- package/dist/127.js +0 -273
- package/dist/185.js +0 -1885
- package/dist/1964db39388.127.js +0 -1
- package/dist/1964db39388.132.js +0 -1
- package/dist/1964db39388.185.js +0 -1
- package/dist/1964db39388.27.js +0 -1
- package/dist/1964db39388.278.js +0 -1
- package/dist/1964db39388.459.js +0 -1
- package/dist/1964db39388.490.js +0 -1
- package/dist/1964db39388.74.js +0 -1
- package/dist/1964db39388.997.js +0 -1
- package/dist/1964db39388.app.js +0 -1
- package/dist/1964db39388.library.js +0 -1
- package/dist/1964db39388.preview.js +0 -1
- package/dist/1964db39388.webview.js +0 -1
- package/dist/27.js +0 -107
- package/dist/278.js +0 -406
- package/dist/459.js +0 -107
|
@@ -87,7 +87,7 @@ class Events extends _common.Com {
|
|
|
87
87
|
render() {
|
|
88
88
|
if (this.state.error) return this.renderError();
|
|
89
89
|
let events = _index.default.map(this.props.store.listEvents(this.props.cid));
|
|
90
|
-
if (!this.state.loading && _index.default.size(events) === 0) {
|
|
90
|
+
if (!this.state.loading && _index.default.size(events) === 0 && !this.props.cid) {
|
|
91
91
|
return (0, _preact.h)("div", {
|
|
92
92
|
ref: ref => this.refBody = ref,
|
|
93
93
|
class: "widget-body--events-container"
|
package/compiled_src/plugin.js
CHANGED
|
@@ -60,6 +60,7 @@ function Plugin(plugin, store, $container, lib) {
|
|
|
60
60
|
var _render = async () => {
|
|
61
61
|
if (_destroy) return;
|
|
62
62
|
if (!$div) return;
|
|
63
|
+
if (!this.t) return;
|
|
63
64
|
if (plugin.type === 'chatbox') {
|
|
64
65
|
(0, _preact.render)((0, _preact.h)(_main.default, {
|
|
65
66
|
destroy: _destroy,
|
|
@@ -100,7 +100,6 @@ class _default {
|
|
|
100
100
|
_defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
|
|
101
101
|
_defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
|
|
102
102
|
_defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
|
|
103
|
-
_defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
|
|
104
103
|
_defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
|
|
105
104
|
_defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
|
|
106
105
|
_defineProperty(this, "lookupOrder", key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`));
|
|
@@ -73,7 +73,6 @@ class _default {
|
|
|
73
73
|
}
|
|
74
74
|
}));
|
|
75
75
|
_defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
|
|
76
|
-
_defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
|
|
77
76
|
_defineProperty(this, "sendImpression", impression => OK200);
|
|
78
77
|
_defineProperty(this, "sendConversion", conversion => OK200);
|
|
79
78
|
this.FileURL = FileURL;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const ChainMaxSize = 50;
|
|
8
|
+
class Chain {
|
|
9
|
+
constructor(db, schema, inmem) {
|
|
10
|
+
this.schema = schema + '_chain';
|
|
11
|
+
this.dead = false;
|
|
12
|
+
this.db = db;
|
|
13
|
+
this.anchorCache = {};
|
|
14
|
+
this.cache = {};
|
|
15
|
+
this.init();
|
|
16
|
+
}
|
|
17
|
+
init() {
|
|
18
|
+
let inmemItemM = {};
|
|
19
|
+
let allitems = this.db.all('items');
|
|
20
|
+
allitems.map(item => {
|
|
21
|
+
inmemItemM[item.chain] = inmemItemM[item.chain] || {};
|
|
22
|
+
inmemItemM[item.chain][item.id] = {
|
|
23
|
+
id: item.id,
|
|
24
|
+
chain: item.chain,
|
|
25
|
+
full_id: item.full_id,
|
|
26
|
+
index: item.index,
|
|
27
|
+
value: item.value
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
map(inmemItemM, (itemM, chain) => {
|
|
31
|
+
if (size(itemM) < ChainMaxSize) return;
|
|
32
|
+
let items = orderBy(map(itemM), ['index'], 'desc');
|
|
33
|
+
let removekeys = [];
|
|
34
|
+
for (var i = ChainMaxSize; i < items.length; i++) {
|
|
35
|
+
removekeys.push(items[i].full_id);
|
|
36
|
+
delete itemM[items[i].id];
|
|
37
|
+
}
|
|
38
|
+
this.db.removes('items', removekeys);
|
|
39
|
+
inmemItemM[chain] = itemM;
|
|
40
|
+
});
|
|
41
|
+
this.cache = inmemItemM;
|
|
42
|
+
}
|
|
43
|
+
destroy() {
|
|
44
|
+
this.db.clear('items');
|
|
45
|
+
this.dead = true;
|
|
46
|
+
this.cache = {};
|
|
47
|
+
this.anchorCache = {};
|
|
48
|
+
this.db = undefined;
|
|
49
|
+
}
|
|
50
|
+
put(chain, id, node_index, value) {
|
|
51
|
+
if (this.dead) return;
|
|
52
|
+
let inmemItemM = this.cache[chain] || {};
|
|
53
|
+
let bottom = minIndex(inmemItemM) || {};
|
|
54
|
+
let bottomIndex = bottom.index || 'z';
|
|
55
|
+
if (size(inmemItemM) == 0) bottomIndex = '';
|
|
56
|
+
let item = {
|
|
57
|
+
id,
|
|
58
|
+
index: node_index,
|
|
59
|
+
value,
|
|
60
|
+
chain,
|
|
61
|
+
full_id: chain + ':' + id
|
|
62
|
+
};
|
|
63
|
+
delete inmemItemM[item.id];
|
|
64
|
+
if (bottomIndex > item.index + '') return;
|
|
65
|
+
inmemItemM[item.id] = item;
|
|
66
|
+
this.cache[chain] = inmemItemM;
|
|
67
|
+
this.db.put('items', item.full_id, item);
|
|
68
|
+
}
|
|
69
|
+
listM(chain) {
|
|
70
|
+
if (this.dead) return {};
|
|
71
|
+
let inmemItemM = this.cache[chain] || {};
|
|
72
|
+
let out = {};
|
|
73
|
+
map(inmemItemM, (item, id) => {
|
|
74
|
+
out[id] = item.value;
|
|
75
|
+
});
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
async fetchMore(chain, limit = 20, api) {
|
|
79
|
+
if (this.dead) return {
|
|
80
|
+
error: 'dead'
|
|
81
|
+
};
|
|
82
|
+
if (!api) return {
|
|
83
|
+
error: 'no api'
|
|
84
|
+
};
|
|
85
|
+
let anchor = this.anchorCache[chain] || '';
|
|
86
|
+
var [apiItems, newanchor, error] = await api(chain, anchor, limit);
|
|
87
|
+
if (error) return {
|
|
88
|
+
error
|
|
89
|
+
};
|
|
90
|
+
if (this.dead) return {
|
|
91
|
+
error: 'dead'
|
|
92
|
+
};
|
|
93
|
+
let inmemItemM = this.cache[chain] || {};
|
|
94
|
+
if (apiItems.length === 0) return {
|
|
95
|
+
end: true
|
|
96
|
+
};
|
|
97
|
+
apiItems.forEach(item => {
|
|
98
|
+
item.chain = chain;
|
|
99
|
+
item.full_id = chain + ':' + item.id;
|
|
100
|
+
inmemItemM[item.id] = item;
|
|
101
|
+
this.db.put('items', item.full_id, item);
|
|
102
|
+
});
|
|
103
|
+
this.anchorCache[chain] = newanchor;
|
|
104
|
+
this.cache[chain] = inmemItemM;
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
del(chain, id) {
|
|
108
|
+
if (this.dead) return;
|
|
109
|
+
let inmemItemM = this.cache[chain] || {};
|
|
110
|
+
let full_id = chain + ':' + id;
|
|
111
|
+
delete inmemItemM[id];
|
|
112
|
+
this.db.removes('items', [full_id]);
|
|
113
|
+
}
|
|
114
|
+
match(chain, id) {
|
|
115
|
+
return this.listM(chain)[id];
|
|
116
|
+
}
|
|
117
|
+
async reload(chain, api) {
|
|
118
|
+
if (this.dead) return;
|
|
119
|
+
let top = maxIndex(this.listM(chain)) || {};
|
|
120
|
+
let topindex = top.index;
|
|
121
|
+
if (!topindex) topindex = Date.now();
|
|
122
|
+
var lastanchor = '';
|
|
123
|
+
var fetchedItems = {};
|
|
124
|
+
for (;;) {
|
|
125
|
+
if (this.dead) return;
|
|
126
|
+
let [newItems, newanchor, error] = await api(chain, lastanchor, 50);
|
|
127
|
+
if (error) return;
|
|
128
|
+
if (this.dead) return;
|
|
129
|
+
newItems.map(item => {
|
|
130
|
+
fetchedItems[item.id] = Object.assign({}, item, {
|
|
131
|
+
chain,
|
|
132
|
+
full_id: chain + ':' + item.id
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
if (newItems.length === 0 || newanchor === lastanchor) break;
|
|
136
|
+
if (fetchedItems.length >= 200) {
|
|
137
|
+
let inmemItemM = this.cache[chain] || {};
|
|
138
|
+
let removeids = [];
|
|
139
|
+
map(inmemItemM, item => {
|
|
140
|
+
if (item.chain !== chain) return;
|
|
141
|
+
removeids.push(item.full_id);
|
|
142
|
+
});
|
|
143
|
+
this.db.removes('items', removeids);
|
|
144
|
+
this.cache[chain] = {};
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
let minindexitem = minIndex(fetchedItems) || {};
|
|
148
|
+
if (minindexitem.index <= topindex) {
|
|
149
|
+
lastanchor = this.anchorCache[chain] || newanchor;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
lastanchor = newanchor;
|
|
153
|
+
}
|
|
154
|
+
for (var i = 0; i < Object.keys(fetchedItems).length; i++) {
|
|
155
|
+
let item = fetchedItems[Object.keys(fetchedItems)[i]];
|
|
156
|
+
this.db.put('items', item.full_id, item);
|
|
157
|
+
this.cache[item.chain] = this.cache[item.chain] || {};
|
|
158
|
+
this.cache[item.chain][item.id] = item;
|
|
159
|
+
}
|
|
160
|
+
this.anchorCache[chain] = lastanchor;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.default = Chain;
|
|
164
|
+
function minIndex(obj) {
|
|
165
|
+
if (!obj) return;
|
|
166
|
+
let keys = Object.keys(obj);
|
|
167
|
+
if (!keys.length) return;
|
|
168
|
+
let min = Infinity;
|
|
169
|
+
let minKey = Object.keys(obj)[0];
|
|
170
|
+
for (var i = 0; i < keys.length; i++) {
|
|
171
|
+
let index = obj[keys[i]] && obj[keys[i]].index || Infinity;
|
|
172
|
+
if (index < min) {
|
|
173
|
+
min = index;
|
|
174
|
+
minKey = keys[i];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return obj[minKey];
|
|
178
|
+
}
|
|
179
|
+
function maxIndex(obj) {
|
|
180
|
+
if (!obj) return;
|
|
181
|
+
let keys = Object.keys(obj);
|
|
182
|
+
if (!keys.length) return;
|
|
183
|
+
let max = -Infinity;
|
|
184
|
+
let maxKey = Object.keys(obj)[0];
|
|
185
|
+
for (var i = 0; i < keys.length; i++) {
|
|
186
|
+
let index = obj[keys[i]] && obj[keys[i]].index || -Infinity;
|
|
187
|
+
if (index > max) {
|
|
188
|
+
max = index;
|
|
189
|
+
maxKey = keys[i];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return obj[keys[maxKey]];
|
|
193
|
+
}
|
|
194
|
+
function map(collection, predicate) {
|
|
195
|
+
if (!collection) return [];
|
|
196
|
+
if (!predicate) return collection;
|
|
197
|
+
var out = [];
|
|
198
|
+
if (Array.isArray(collection)) {
|
|
199
|
+
for (let i = 0; i < collection.length; i++) {
|
|
200
|
+
out.push(predicate(collection[i], i));
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
if (typeof collection === 'object') {
|
|
205
|
+
var keys = Object.keys(collection);
|
|
206
|
+
for (let i = 0; i < keys.length; i++) {
|
|
207
|
+
var k = keys[i];
|
|
208
|
+
out.push(predicate(collection[k], k));
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
function size(o) {
|
|
215
|
+
if (!o) return 0;
|
|
216
|
+
if (o.length !== undefined) return o.length;
|
|
217
|
+
return Object.keys(o).length;
|
|
218
|
+
}
|
|
219
|
+
function orderBy(a, k, d) {
|
|
220
|
+
var clone = [];
|
|
221
|
+
map(a, v => clone.push(v));
|
|
222
|
+
clone.sort((i, j) => {
|
|
223
|
+
if (i[k] === j[k]) return 0;
|
|
224
|
+
var r = i[k] < j[k] ? -1 : 1;
|
|
225
|
+
return d === 'desc' ? -r : r;
|
|
226
|
+
});
|
|
227
|
+
return clone;
|
|
228
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var localStorageMemory = {};
|
|
4
|
+
var cache = {};
|
|
5
|
+
localStorageMemory.length = 0;
|
|
6
|
+
localStorageMemory.getItem = function (key) {
|
|
7
|
+
if (key in cache) return cache[key];
|
|
8
|
+
return null;
|
|
9
|
+
};
|
|
10
|
+
localStorageMemory.setItem = function (key, value) {
|
|
11
|
+
if (typeof value === 'undefined') {
|
|
12
|
+
localStorageMemory.removeItem(key);
|
|
13
|
+
} else {
|
|
14
|
+
if (!Object.prototype.hasOwnProperty.call(cache, key)) {
|
|
15
|
+
localStorageMemory.length++;
|
|
16
|
+
}
|
|
17
|
+
cache[key] = value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
localStorageMemory.removeItem = function (key) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(cache, key)) {
|
|
22
|
+
delete cache[key];
|
|
23
|
+
localStorageMemory.length--;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
localStorageMemory.key = function (index) {
|
|
27
|
+
return Object.keys(cache)[index] || null;
|
|
28
|
+
};
|
|
29
|
+
localStorageMemory.clear = function () {
|
|
30
|
+
cache = {};
|
|
31
|
+
localStorageMemory.length = 0;
|
|
32
|
+
};
|
|
33
|
+
module.exports = localStorageMemory;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
let KvMaxSize = 500;
|
|
8
|
+
class _default {
|
|
9
|
+
constructor(db, schema) {
|
|
10
|
+
this.name = schema;
|
|
11
|
+
schema += '_kv';
|
|
12
|
+
this.dead = false;
|
|
13
|
+
this.db = db;
|
|
14
|
+
this.cache = {};
|
|
15
|
+
this.initialized = false;
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
refreshCache() {
|
|
19
|
+
if (this.dead) return;
|
|
20
|
+
let inmemItemM = {};
|
|
21
|
+
let allitems = this.db.all('items');
|
|
22
|
+
allitems.forEach(function (item) {
|
|
23
|
+
inmemItemM[item.key] = item.value;
|
|
24
|
+
});
|
|
25
|
+
this.cache = inmemItemM;
|
|
26
|
+
}
|
|
27
|
+
init() {
|
|
28
|
+
if (this.initialized) return;
|
|
29
|
+
let inmemItemM = {};
|
|
30
|
+
console.time('KV' + this.name);
|
|
31
|
+
let allitems = this.db.all('items');
|
|
32
|
+
allitems.forEach(function (item) {
|
|
33
|
+
inmemItemM[item.key] = item.value;
|
|
34
|
+
});
|
|
35
|
+
this.cache = inmemItemM;
|
|
36
|
+
let allkeys = Object.keys(this.cache);
|
|
37
|
+
if (allkeys.length > KvMaxSize) {
|
|
38
|
+
let liveChance = KvMaxSize / 2 / allkeys.lenth;
|
|
39
|
+
let removekeys = [];
|
|
40
|
+
for (var i = 0; i < KvMaxSize; i++) {
|
|
41
|
+
let live = Math.random() <= liveChance;
|
|
42
|
+
if (live) continue;
|
|
43
|
+
let key = allkeys[i];
|
|
44
|
+
delete this.cache[key];
|
|
45
|
+
removekeys.push(key);
|
|
46
|
+
}
|
|
47
|
+
this.db.removes('items', [removekeys]);
|
|
48
|
+
}
|
|
49
|
+
this.initialized = true;
|
|
50
|
+
console.timeEnd('KV' + this.name);
|
|
51
|
+
}
|
|
52
|
+
all() {
|
|
53
|
+
if (this.dead) return [];
|
|
54
|
+
if (!this.initialized) return [];
|
|
55
|
+
return this.cache;
|
|
56
|
+
}
|
|
57
|
+
match(key) {
|
|
58
|
+
if (this.dead || !this.initialized) return;
|
|
59
|
+
if (!key) return;
|
|
60
|
+
return this.cache[key];
|
|
61
|
+
}
|
|
62
|
+
put(key, value) {
|
|
63
|
+
if (!key) return;
|
|
64
|
+
if (this.dead) return [];
|
|
65
|
+
if (!this.initialized) throw new Error('uninitialized');
|
|
66
|
+
this.cache[key] = value;
|
|
67
|
+
this.db.put('items', key, {
|
|
68
|
+
key,
|
|
69
|
+
value
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
del(key) {
|
|
73
|
+
if (this.dead) return;
|
|
74
|
+
if (!this.initialized) throw new Error('uninitialized');
|
|
75
|
+
delete this.cache[key];
|
|
76
|
+
this.db.removes('items', [key]);
|
|
77
|
+
}
|
|
78
|
+
destroy() {
|
|
79
|
+
this.db.clear('items');
|
|
80
|
+
this.dead = true;
|
|
81
|
+
this.db = undefined;
|
|
82
|
+
this.cache = undefined;
|
|
83
|
+
this.initialized = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
let memlocalStorage = require('./inmem_localstorage.js');
|
|
10
|
+
let requestIdleCallback = typeof window !== 'undefined' ? window.requestIdleCallback : null;
|
|
11
|
+
if (!requestIdleCallback) requestIdleCallback = cb => cb();
|
|
12
|
+
const LIMIT = 80;
|
|
13
|
+
class _default {
|
|
14
|
+
constructor(schema, inmem) {
|
|
15
|
+
this.localStorage = memlocalStorage;
|
|
16
|
+
this.inmem = inmem;
|
|
17
|
+
this.allkeys = {};
|
|
18
|
+
if (!inmem) {
|
|
19
|
+
try {
|
|
20
|
+
window.localStorage.setItem('sbzstore1029', '?');
|
|
21
|
+
window.localStorage.removeItem('sbzstore1029');
|
|
22
|
+
this.localStorage = window.localStorage;
|
|
23
|
+
} catch (e) {}
|
|
24
|
+
}
|
|
25
|
+
this.schema = schema;
|
|
26
|
+
}
|
|
27
|
+
all(table) {
|
|
28
|
+
let items = [];
|
|
29
|
+
for (var i = 0; i < this.localStorage.length; i++) {
|
|
30
|
+
let key = this.localStorage.key(i);
|
|
31
|
+
if (!key.startsWith(this.schema + '#' + table + '#')) continue;
|
|
32
|
+
this.allkeys[key] = true;
|
|
33
|
+
if (this.inmem) items.push(this.localStorage.getItem(key));else items.push(_index.default.parseJSON(this.localStorage.getItem(key)));
|
|
34
|
+
}
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
removes(table, keys) {
|
|
38
|
+
for (var i = 0; i < keys.length; i++) {
|
|
39
|
+
delete this.allkeys[this.schema + '#' + table + '#' + keys[i]];
|
|
40
|
+
this.localStorage.removeItem(this.schema + '#' + table + '#' + keys[i]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
clear(table) {
|
|
44
|
+
for (var i = 0; i < this.localStorage.length; i++) {
|
|
45
|
+
let key = this.localStorage.key(i);
|
|
46
|
+
if (!key.startsWith(this.schema + '#' + table + '#')) continue;
|
|
47
|
+
this.localStorage.removeItem(key);
|
|
48
|
+
}
|
|
49
|
+
this.allkeys = {};
|
|
50
|
+
}
|
|
51
|
+
put(table, key, value) {
|
|
52
|
+
this.allkeys[this.schema + '#' + table + '#' + key] = true;
|
|
53
|
+
if (this.inmem) return this.localStorage.setItem(this.schema + '#' + table + '#' + key, value);
|
|
54
|
+
if (Object.keys(this.allkeys).length > LIMIT) this.clear(table);
|
|
55
|
+
requestIdleCallback(() => {
|
|
56
|
+
try {
|
|
57
|
+
this.localStorage.setItem(this.schema + '#' + table + '#' + key, toString(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
this.clear(table);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = _default;
|
|
65
|
+
function toString(obj) {
|
|
66
|
+
if (obj === undefined) return 'null';
|
|
67
|
+
return JSON.stringify(obj);
|
|
68
|
+
}
|
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
|
-
var _storage = _interopRequireDefault(require("@subiz/storage"));
|
|
9
8
|
var _api = _interopRequireDefault(require("./api.js"));
|
|
9
|
+
var _lsdb = _interopRequireDefault(require("./lsdb.js"));
|
|
10
|
+
var _chain = _interopRequireDefault(require("./chain.js"));
|
|
11
|
+
var _kv = _interopRequireDefault(require("./kv.js"));
|
|
10
12
|
var _api_fake = _interopRequireDefault(require("./api_fake.js"));
|
|
11
13
|
var _realtime_fake = _interopRequireDefault(require("./realtime_fake.js"));
|
|
12
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -205,9 +207,9 @@ class Store {
|
|
|
205
207
|
}
|
|
206
208
|
cleanLocalStorage();
|
|
207
209
|
this.pubsub = new _index.default.Pubsub();
|
|
208
|
-
this.kv = new
|
|
209
|
-
this.cache = new
|
|
210
|
-
this.chain = new
|
|
210
|
+
this.kv = new _kv.default(new _lsdb.default('sbz2023', this.inmem), 'kv');
|
|
211
|
+
this.cache = new _kv.default(new _lsdb.default('sbz2023', true), 'kv');
|
|
212
|
+
this.chain = new _chain.default(new _lsdb.default('cbz2023', true), 'ch');
|
|
211
213
|
this.getLocaleContent = this.api.getLocaleContent;
|
|
212
214
|
this.g_haveSentSeenM = {};
|
|
213
215
|
this.last_focused = _index.default.Date.now();
|
|
@@ -306,13 +308,11 @@ class Store {
|
|
|
306
308
|
async overrideAcc(acc) {
|
|
307
309
|
this.forceAcc = _index.default.cloneDeep(acc);
|
|
308
310
|
await this.readyGate.entry();
|
|
309
|
-
this.disconnect('account');
|
|
310
311
|
this.reconnect();
|
|
311
312
|
}
|
|
312
313
|
async overrideChatbox(chatbox) {
|
|
313
314
|
this.forceChatbox = chatbox;
|
|
314
315
|
await this.readyGate.entry();
|
|
315
|
-
this.disconnect('account');
|
|
316
316
|
await this.reconnect();
|
|
317
317
|
_index.default.setTimeout(this.pubsub.publish('resetCSS'), 10);
|
|
318
318
|
}
|
|
@@ -435,9 +435,14 @@ class Store {
|
|
|
435
435
|
user_mask: mask
|
|
436
436
|
}, xhrsend);
|
|
437
437
|
this.realtime.onEvent(this.onWs.bind(this));
|
|
438
|
-
this.realtime.onInterrupted(() =>
|
|
438
|
+
this.realtime.onInterrupted(async () => {
|
|
439
|
+
await this.reconnectWs(accid, user.id);
|
|
440
|
+
this.reconnect();
|
|
441
|
+
});
|
|
439
442
|
this.seenLoop();
|
|
440
|
-
await this.reconnect(
|
|
443
|
+
await this.reconnect({
|
|
444
|
+
user: user
|
|
445
|
+
});
|
|
441
446
|
this.readyGate.open();
|
|
442
447
|
this.reconnectWs(accid, user.id);
|
|
443
448
|
return user;
|
|
@@ -460,7 +465,10 @@ class Store {
|
|
|
460
465
|
getAccessToken: () => this.api.token_generator()
|
|
461
466
|
});
|
|
462
467
|
this.realtime.onEvent(this.onWs.bind(this));
|
|
463
|
-
this.realtime.onInterrupted(() =>
|
|
468
|
+
this.realtime.onInterrupted(async () => {
|
|
469
|
+
await this.reconnectWs(accid, user.id);
|
|
470
|
+
this.reconnect();
|
|
471
|
+
});
|
|
464
472
|
this.seenLoop();
|
|
465
473
|
await this.reconnect();
|
|
466
474
|
this.readyGate.open();
|
|
@@ -518,18 +526,18 @@ class Store {
|
|
|
518
526
|
async reconnectWs(accid, userid) {
|
|
519
527
|
await this.realtime.subscribe([`conversation_state_updated.account.${accid}.user.${userid}`, `conversation_joined.account.${accid}.user.${userid}`, `conversation_typing.account.${accid}.user.${userid}`, `message_sent.account.${accid}.user.${userid}`, `message_pong.account.${accid}.user.${userid}`, `conversation_rating_requested.account.${accid}.user.${userid}`, `conversation_rated.account.${accid}.user.${userid}`]);
|
|
520
528
|
await this.readyGate.entry();
|
|
521
|
-
this.disconnect('account');
|
|
522
|
-
return this.reconnect();
|
|
523
529
|
}
|
|
524
|
-
async reconnect() {
|
|
530
|
+
async reconnect(p) {
|
|
525
531
|
if (this._die) return;
|
|
526
532
|
await this.reconnectGate.entry(undefined, true);
|
|
527
|
-
if (this.isInsync('account')) return this.reconnectGate.open();
|
|
528
533
|
this.markSync('account');
|
|
529
|
-
let
|
|
534
|
+
let fetchuser = p && p.user ? Promise.resolve({
|
|
535
|
+
body: p.user
|
|
536
|
+
}) : this.api.getUser();
|
|
537
|
+
let outs = await Promise.all([fetchuser, this.api.getAccountSetting()]);
|
|
530
538
|
let error = _index.default.find(outs, out => out.error);
|
|
531
539
|
if (error) return console.error(error);
|
|
532
|
-
let set =
|
|
540
|
+
let set = outs[1].body;
|
|
533
541
|
set.user = outs[0].body;
|
|
534
542
|
await this._setSetting(set);
|
|
535
543
|
let convob = await this.api.listConversations();
|
|
@@ -1034,9 +1042,9 @@ class Store {
|
|
|
1034
1042
|
if ((k || '').startsWith('__sb')) this.cookie.remove(k);
|
|
1035
1043
|
});
|
|
1036
1044
|
this.kv.destroy();
|
|
1037
|
-
this.kv = new
|
|
1045
|
+
this.kv = new _kv.default(new _lsdb.default('sbz2023', this.inmem), 'kv');
|
|
1038
1046
|
this.chain.destroy();
|
|
1039
|
-
this.chain = new
|
|
1047
|
+
this.chain = new _chain.default(new _lsdb.default('cbz2023', true), 'ch');
|
|
1040
1048
|
}
|
|
1041
1049
|
destroy() {
|
|
1042
1050
|
this._die = true;
|