Added 2 parameters to limit the download size, and how many articles are downloaded by request to the server.
Alerts to detect size download anytime you connect to the server. This patch catch any exception in case data is not able to be stored in localStorage
This commit is contained in:
parent
bc1c99354f
commit
cfad4d4f4d
4 changed files with 66 additions and 18 deletions
59
js/App.js
59
js/App.js
|
@ -7,6 +7,13 @@ function App() {
|
|||
if(!color) color = "red";
|
||||
this.setColor(color);
|
||||
this.fontChange();
|
||||
|
||||
var numArticles = localStorage.numArticles;
|
||||
if(!numArticles) numArticles = 50;
|
||||
this.numArticles(numArticles);
|
||||
var maxDownload = localStorage.maxDownload;
|
||||
if(!maxDownload) maxDownload = 500000;
|
||||
this.maxDownload(maxDownload);
|
||||
};
|
||||
|
||||
App.prototype.authenticate = function() {
|
||||
|
@ -99,6 +106,14 @@ App.prototype.after_login = function(backend) {
|
|||
} else {
|
||||
this.backend = new TinyTinyRSS(this, localStorage.server_url, localStorage.session_id);
|
||||
}
|
||||
|
||||
var numArticles = localStorage.numArticles;
|
||||
if(!numArticles) numArticles = 50;
|
||||
this.numArticles(numArticles);
|
||||
var maxDownload = localStorage.maxDownload;
|
||||
if(!maxDownload) maxDownload = 500000;
|
||||
this.maxDownload(maxDownload);
|
||||
|
||||
this.reload();
|
||||
};
|
||||
|
||||
|
@ -137,7 +152,8 @@ App.prototype.setColor = function(color) {
|
|||
App.prototype.reload = function() {
|
||||
this.unread_articles = [];
|
||||
$("#all-read").innerHTML = "❌";
|
||||
this.backend.reload(this.gotUnreadFeeds.bind(this));
|
||||
var number=parseInt(localStorage.numArticles);
|
||||
this.backend.reload(this.gotUnreadFeeds.bind(this),number);
|
||||
};
|
||||
|
||||
App.prototype.gotUnreadFeeds = function(new_articles) {
|
||||
|
@ -155,11 +171,25 @@ App.prototype.gotUnreadFeeds = function(new_articles) {
|
|||
this.unread_articles = this.unread_articles.concat(new_articles);
|
||||
|
||||
if(new_articles.length > 0) {
|
||||
this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles);
|
||||
} else {
|
||||
localStorage.unread_articles = JSON.stringify(this.unread_articles);
|
||||
try {
|
||||
//To check if when it fails it is the same
|
||||
localStorage.unread_articles = JSON.stringify(this.unread_articles);
|
||||
//alert("Size probando:"+probando.length)
|
||||
var size = parseInt(localStorage.maxDownload);
|
||||
if(localStorage.unread_articles.length < size) {
|
||||
var num = parseInt(localStorage.numArticles);
|
||||
this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num);
|
||||
} else {
|
||||
alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes");
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
alert("Reached maximum memory by app" + e.name + " " +e.message +". We will keep working in anycase with:" + localStorage.unread_articles.length);
|
||||
}
|
||||
this.populateList();
|
||||
}
|
||||
} else {
|
||||
alert("Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length + " bytes");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -445,5 +475,22 @@ App.prototype.fontChange = function(size) {
|
|||
document.body.addClass("f" + i);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
App.prototype.numArticles= function(askfor) {
|
||||
if(askfor < 200 && askfor > 0) {
|
||||
localStorage.numArticles=askfor;
|
||||
}
|
||||
else {
|
||||
localStorage.numArticles=100;
|
||||
}
|
||||
};
|
||||
|
||||
App.prototype.maxDownload= function(maxdata) {
|
||||
if(maxdata < 5000000 && maxdata > 100000) {
|
||||
localStorage.maxDownload=maxdata;
|
||||
}
|
||||
else {
|
||||
localStorage.maxDownload=500000;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -65,18 +65,18 @@ OwnCloud.prototype.doOperation = function(method, operation, new_options, callba
|
|||
xhr.send(body);
|
||||
}
|
||||
|
||||
OwnCloud.prototype.reload = function(callback) {
|
||||
OwnCloud.prototype.reload = function(callback,limit) {
|
||||
var _this = this;
|
||||
this.getFeeds(function() { _this.getUnreadFeeds(callback); });
|
||||
this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); });
|
||||
};
|
||||
|
||||
OwnCloud.prototype.getUnreadFeeds = function(callback, skip) {
|
||||
OwnCloud.prototype.getUnreadFeeds = function(callback, skip, limit) {
|
||||
if(skip) {
|
||||
skip = skip[skip.length - 1].id;
|
||||
}
|
||||
|
||||
var options = {
|
||||
batchSize: 700,
|
||||
batchSize: limit || 700,
|
||||
offset: skip || 0,
|
||||
type: 3,
|
||||
id: 0,
|
||||
|
|
10
js/Pond.js
10
js/Pond.js
|
@ -69,15 +69,15 @@ Pond.prototype.doOperation = function(method, operation, new_options, callback)
|
|||
};
|
||||
|
||||
|
||||
Pond.prototype.reload = function(callback) {
|
||||
Pond.prototype.reload = function(callback,limit) {
|
||||
var _this = this;
|
||||
this.getFeeds(function() { _this.getUnreadFeeds(callback); });
|
||||
this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); });
|
||||
};
|
||||
|
||||
Pond.prototype.getUnreadFeeds = function(callback, skip) {
|
||||
Pond.prototype.getUnreadFeeds = function(callback, skip, limit) {
|
||||
var options = {
|
||||
status: "unread",
|
||||
limit: 100
|
||||
limit: limit || 100
|
||||
};
|
||||
|
||||
if(skip && skip.length > 0) {
|
||||
|
@ -222,4 +222,4 @@ Pond.login = function(server_url, user, password, callback) {
|
|||
xhr.setRequestHeader("Content-Length", options.length);
|
||||
xhr.setRequestHeader("Connection", "close");
|
||||
xhr.send(options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,17 +54,18 @@ TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) {
|
|||
xhr.send(JSON.stringify(options));
|
||||
}
|
||||
|
||||
TinyTinyRSS.prototype.reload = function(callback) {
|
||||
this.getUnreadFeeds(callback, []);
|
||||
TinyTinyRSS.prototype.reload = function(callback,limit) {
|
||||
this.getUnreadFeeds(callback, 0, limit);
|
||||
};
|
||||
|
||||
TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip) {
|
||||
TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit) {
|
||||
skip = skip.length;
|
||||
var options = {
|
||||
show_excerpt: false,
|
||||
view_mode: "unread",
|
||||
show_content: true,
|
||||
feed_id: -4,
|
||||
limit: limit || 0,
|
||||
skip: skip || 0
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue