Commit 8e911753 authored by yPhil's avatar yPhil
Browse files

Refactoring

- PTL.db.js
- PTL.feed.js must chain promises
parent 2f40c41a
Pipeline #413371 passed with stage
in 48 seconds
......@@ -614,21 +614,42 @@ PTL.feed = {
};
request.onsuccess = function(event) {
const getFeed = PTL.db.getFeed(event.target.result, feedUrl)
.then((res) => {
if (res) {
console.log('YAH!: %s (%s)', JSON.stringify(res));
}
}).then((res) => {
if (res) {
console.log('YAH!: %s (%s)', JSON.stringify(res));
}
}).catch((error) => {
console.log('SHIT!: %s (%s)', JSON.stringify(error));
});
var db = event.target.result;
let ReadTransaction = db.transaction(PTL.DbStore, "readonly");
let objectStore = ReadTransaction.objectStore(PTL.DbStore);
let ReadRequest = objectStore.get(feedUrl);
ReadRequest.onerror = function(event) {
let request = objectStore.get(feedUrl);
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
ReadRequest.onsuccess = function(event) {
request.onsuccess = function(event) {
if (event.target.result) {
console.log('yeah!: %s (%s)');
$feedBody.html(event.target.result.content);
PTL.feed.getFeed(feedUrl, feedLastItem, feedNbItems).then((data) => {
PTL.feed.getFeed(feedUrl, feedLastItem).then((data) => {
// console.log('Kayn: %s (%s)', JSON.stringify(data.thereArenewItems));
......@@ -694,7 +715,7 @@ PTL.feed = {
// console.log('Makayn\'sh: [%s] (%s)', feedLastItem, feedUrl);
PTL.feed.getFeed(feedUrl, 'noLastItem', feedNbItems).then(function(data) {
PTL.feed.getFeed(feedUrl, 'noLastItem').then(function(data) {
console.log('MaKaynash, but thereArenewItems: (%s)', JSON.stringify(data.thereArenewItems));
......@@ -730,11 +751,11 @@ PTL.feed = {
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + itemList[1] + ' new items)' )
.removeClass('spin');
let openRequest = indexedDB.open(PTL.DbName, PTL.DbVersion);
let request = indexedDB.open(PTL.DbName, PTL.DbVersion);
openRequest.onsuccess = function() {
request.onsuccess = (event) => {
let db = openRequest.result;
let db = event.target.result;
if (!db.objectStoreNames.contains(PTL.DbStore)) {
db.createObjectStore(PTL.DbStore, {keyPath: PTL.DbKey});
......
......@@ -34,7 +34,7 @@ function getParams(str) {
return params;
}
function getFeed (feedUrl, lastItem, nbItems, callback) {
function getFeed (feedUrl, lastItem, callback) {
// Get a response stream
fetch(feedUrl, {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
......@@ -71,39 +71,17 @@ function getFeed (feedUrl, lastItem, nbItems, callback) {
if (item !== null) {
i++;
if (typeof newLastItem === 'undefined') {
newLastItem = item.link;
}
if (typeof newLastItem === 'undefined') newLastItem = item.link;
if (item.link !== lastItem) {
console.error('item.link: %s (%s)', item.link);
// console.error('### PUSHING [%s] lastItem:[%s]', item.link, newLastItem);
feedItems.push(item);
} else {
console.error('### i:[%s], This item:[%s], lastItem:[%s], newLastItem:[%s]', i, item.link, lastItem, newLastItem);
console.error('### i:[%s], item:[%s], last:[%s], new:[%s]', i, item.link, lastItem, newLastItem);
this.resume();
}
}
}
// if (item !== null){
// i++;
// console.error('item.link: %s (%s)', item.link);
// if (typeof newLastItem == 'undefined') {
// newLastItem = item.link;
// }
// if (newLastItem == lastItem) {
// console.error('### Count reached i:%s, lastItem: [%s], newLastItem: %s', i, lastItem, newLastItem);
// feedparser.destroy();
// // return false;
// } else {
// feedItems.push(item);
// }
// }
}
catch (err) {
console.error('## feedParserCatchErr: %s (%s)', err, feedUrl);
......
......@@ -72,7 +72,7 @@ router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, req.query.lastItem, req.query.nbItems, 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);
......
......@@ -88,6 +88,7 @@
<script src="/bower/DOMPurify/dist/purify.min.js"></script>
<script src="/static/js/PTL.main.js"></script>
<script src="/static/js/PTL.db.js"></script>
<script src="/static/js/PTL.prefs.js"></script>
<script src="/static/js/PTL.i18n.js"></script>
......
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