This repository was archived by the owner on May 10, 2026. It is now read-only.
forked from martinkadlec0/Smart-RSS
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathworker.js
More file actions
85 lines (69 loc) · 2.18 KB
/
Copy pathworker.js
File metadata and controls
85 lines (69 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* globals onmessage: true, postMessage, indexedDB */
const request = indexedDB.open('backbone-indexeddb', 4);
let db;
let content;
request.addEventListener('error', function () {
throw 'Error code: ' + this.errorCode;
});
request.addEventListener('success', function () {
db = this.result;
if (content) {
startImport();
}
});
onmessage = function (e) {
if (e.data.action === 'file-content') {
content = e.data.value;
if (db) {
startImport();
}
}
};
let writes = 0;
function handleReq(req) {
writes++;
req.onsuccess = req.onerror = function () {
writes--;
if (writes <= 0) {
postMessage({action: 'finished'});
}
};
}
function startImport() {
const transaction = db.transaction(['folders-backbone', 'sources-backbone', 'items-backbone'], 'readwrite');
const folders = transaction.objectStore('folders-backbone');
const sources = transaction.objectStore('sources-backbone');
const items = transaction.objectStore('items-backbone');
const importedFolders = content.folders;
const importedSources = content.sources;
const importedItems = content.items;
if (importedFolders) {
for (let i = 0, j = importedFolders.length; i < j; i++) {
handleReq(folders.add(importedFolders[i]));
if (i % 10 === 0) {
postMessage({action: 'message', value: 'Folders: ' + i + '/' + j});
}
}
}
if (importedSources) {
for (let i = 0, j = importedSources.length; i < j; i++) {
handleReq(sources.add(importedSources[i]));
if (i % 10 === 0) {
postMessage({action: 'message', value: 'Feeds: ' + i + '/' + j});
}
}
}
if (importedItems) {
for (let i = 0, j = importedItems.length; i < j; i++) {
handleReq(items.add(importedItems[i]));
if (i % 10 === 0) {
postMessage({action: 'message', value: 'Articles: ' + i + '/' + j});
}
}
}
if (writes === 0) {
postMessage({action: 'finished'});
} else {
postMessage({action: 'message', value: 'Writing...'});
}
}