Commit 1c4eeebd authored by yPhil's avatar yPhil
Browse files

Now properly saving to db without cloning PBs

parent 869cd643
Pipeline #413418 passed with stage
in 46 seconds
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
PTL.db = {
getFeed: function(db, url) {
return new Promise((resolve, reject) => {
const txn = db.transaction(PTL.DbStore, 'readonly');
const store = txn.objectStore(PTL.DbStore);
let query = store.get(url);
query.onsuccess = (event) => {
if (!event.target.result) {
console.log(`Feed ${url} not found`);
resolve(null);
} else {
// console.table(event.target.result);
resolve(event.target.result);
}
};
query.onerror = (event) => {
console.log('Catched in db.read: [%s]', event.target.errorCode);
reject(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
});
},
delete: function(db, url) {
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = function (event) {
console.log(event);
};
query.onerror = function (event) {
console.log(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
},
insert: function(db, url, content) {
return new Promise((resolve, reject) => {
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
query.onsuccess = function (event) {
resolve();
console.log(event);
};
query.onerror = function (event) {
reject();
console.log(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
});
}
getFeed: function(db, url) {
return new Promise((resolve, reject) => {
const txn = db.transaction(PTL.DbStore, 'readonly');
const store = txn.objectStore(PTL.DbStore);
let query = store.get(url);
query.onsuccess = (event) => {
if (!event.target.result) {
console.log(`Feed ${url} not found`);
resolve(null);
} else {
// console.table(event.target.result);
resolve(event.target.result);
}
};
query.onerror = (event) => {
console.log('Catched in db.read: [%s]', event.target.errorCode);
reject(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
});
},
delete: function(db, url) {
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = function (event) {
console.log(event);
};
query.onerror = function (event) {
console.log(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
},
putFeed: function(url, content) {
console.log('content: %s (%s)', url, content);
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
query.onsuccess = event => {
resolve();
console.log(event);
};
query.onerror = event => {
reject();
console.log(event.target.errorCode);
};
txn.oncomplete = () => {
db.close();
};
};
});
}
};
This diff is collapsed.
......@@ -72,9 +72,9 @@ router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, req.query.lastItem, function (error, feedItems, feedTitle, feedLink, lastItem, thereArenewItems) {
feeder.getFeed(req.query.url, req.query.lastItem, function (error, feedItems, feedTitle, feedLink, lastItem, thereAreNewItems) {
console.error('### thereArenewItems: [%s]', thereArenewItems);
console.error('### thereAreNewItems: [%s]', thereAreNewItems);
if (feedItems && !res.headersSent) {
res.send({
......@@ -82,7 +82,7 @@ router.get('/feed', function(req, res) {
feedLink: feedLink,
feedTitle: feedTitle,
lastItem: lastItem,
thereArenewItems: thereArenewItems
thereAreNewItems: thereAreNewItems
});
} else if (error && !res.headersSent) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment