Merge branch 'master' into dashboard

* master:
  Stubbing in profile tests.
  Adding nginx.local.conf
  Adding original text and original story to API docs.
  Adding a smarter wakeup for real-time to handle cases where a laptop is re-opened but real-time is not immediately reestablished.
This commit is contained in:
Samuel Clay 2020-08-03 10:40:39 -04:00
commit d2251a7bd3
7 changed files with 265 additions and 5 deletions

26
apps/profile/tests.py Normal file
View file

@ -0,0 +1,26 @@
from utils import json_functions as json
from django.test.client import Client
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.conf import settings
from mongoengine.connection import connect, disconnect
class ProfiuleTest(TestCase):
fixtures = ['rss_feeds.json']
def setUp(self):
disconnect()
settings.MONGODB = connect('test_newsblur')
self.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
def tearDown(self):
settings.MONGODB.drop_database('test_newsblur')
def test_create_account(self):
response = self.client.post(reverse('welcome-signup'), {
'signup_username': 'test',
'signup_password': 'password',
'signup_email': 'test@newsblur.com',
})

View file

@ -38,6 +38,7 @@ javascripts:
- media/js/vendor/jquery.ajaxmanager.3.js
- media/js/vendor/jquery.simplemodal-1.4.js
- media/js/vendor/jquery.color.js
- media/js/vendor/jquery.wakeup.js
- media/js/vendor/jquery-ui-1.12.1.js
# - media/js/vendor/jquery.ui.autocomplete.js
# - media/js/vendor/jquery.ui.core.js

135
config/nginx.local.conf Normal file
View file

@ -0,0 +1,135 @@
upstream app_server {
server 127.0.0.1:8000 fail_timeout=10 max_fails=3 ;
}
upstream icon_server {
server 127.0.0.1:3030 fail_timeout=2 max_fails=3;
server 127.0.0.1:8000 backup;
}
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
ssl_certificate /srv/secrets-newsblur/certificates/newsblur.com.crt;
ssl_certificate_key /srv/secrets-newsblur/certificates/newsblur.com.key;
client_max_body_size 4M;
server_name *.nb.local.com nb.local.com;
add_header X-nginx-server nginx_none;
# if ($host = 'newsblur.com') {
# rewrite ^/(.*)$ https://www.newsblur.com/$1 permanent;
# }
if (-f /srv/newsblur/templates/maintenance_on.html) {
return 503;
}
error_page 502 @down;
location @down {
root /srv/newsblur/;
rewrite ^(.*)$ /templates/502.html break;
}
error_page 503 @maintenance;
location @maintenance {
if ($uri !~ ^/media/) {
root /srv/newsblur/;
rewrite ^(.*)$ /templates/maintenance_on.html break;
}
root /srv/newsblur;
}
error_page 504 @timeout;
location @timeout {
root /srv/newsblur/;
rewrite ^(.*)$ /templates/502.html break;
}
location /media/ {
expires max;
keepalive_timeout 1;
root /srv/newsblur;
}
location /static/ {
expires max;
keepalive_timeout 1;
root /srv/newsblur;
}
location /favicon.ico {
alias /srv/newsblur/media/img/favicon_32.png;
expires max;
access_log off;
}
location /maintenance {
alias /srv/newsblur/templates/maintenance_on.html;
expires max;
access_log off;
}
location ^~ /crossdomain.xml {
expires max;
alias /srv/newsblur/media/crossdomain.xml;
types {
text/x-cross-domain-policy xml;
}
}
location ^~ /robots.txt {
expires max;
alias /srv/newsblur/media/robots.txt;
}
location /munin/static/ {
alias /etc/munin/static/;
}
location /munin/ {
# alias /var/cache/munin/www/;
fastcgi_split_path_info ^(/munin)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fcgi-html.sock;
include fastcgi_params;
}
location ^~ /cgi-bin/munin-cgi-graph/ {
fastcgi_split_path_info ^(/cgi-bin/munin-cgi-graph)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fcgi-graph.sock;
include fastcgi_params;
}
location ^~ /rss_feeds/icon/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://icon_server;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
}

View file

@ -849,7 +849,6 @@ color: #a85b40;
/* Error text on bottom bar */
.NB-dark #story_taskbar .NB-river-progress .NB-river-progress-text,
.NB-dark #story_taskbar .NB-feed-error .NB-feed-error-text {
background-color: #191b1c;
color: #c0c0c0;
text-shadow: 0 1px 0 rgba(0,0,0,.8);
}
@ -1746,4 +1745,4 @@ a.mention, a.mention-group {
}
.NB-dark .NB-history-fetch.NB-errorcode {
color: #953524;
}
}

View file

@ -165,6 +165,7 @@
this.load_intelligence_slider();
this.handle_mouse_indicator_hover();
this.handle_login_and_signup_forms();
this.handle_wakeup();
this.apply_story_styling();
this.load_recommended_feeds();
this.setup_dashboard_graphs();
@ -5124,7 +5125,7 @@
// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating every 60 sec'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites every ' + this.flags.refresh_interval + ' seconds...').addClass('NB-error').removeClass('NB-active');
this.apply_tipsy_titles();
_.delay(_.bind(this.setup_socket_realtime_unread_counts, this), 60*1000);
_.delay(_.bind(this.setup_socket_realtime_unread_counts, this), Math.random()*60*1000);
}, this));
this.socket.on('reconnect_failed', _.bind(function() {
console.log(["Socket.io reconnect failed"]);
@ -5146,7 +5147,7 @@
window.addEventListener('online', _.bind(this.setup_socket_realtime_unread_counts, this));
window.addEventListener('offline', _.bind(this.setup_socket_realtime_unread_counts, this));
},
send_socket_active_feeds: function() {
if (!this.socket) return;
@ -5162,6 +5163,14 @@
return active_feeds;
},
handle_wakeup: function() {
$.dreamOn();
$.wakeUp(_.bind(function() {
console.log(["Wakeup, reconnecting to real-time socket.io...", new Date()]);
this.setup_socket_realtime_unread_counts();
}, this), {}, 1 * 1000);
},
setup_feed_refresh: function(new_feeds) {
var self = this;
var refresh_interval = this.constants.FEED_REFRESH_INTERVAL;

69
media/js/vendor/jquery.wakeup.js vendored Normal file
View file

@ -0,0 +1,69 @@
/*!
* jQuery WakeUp plugin
*
* A JQuery plugin that will help detecting waking up from sleep and/or
* hibernation and executing assigned functions.
*
* Based on code provided by Andrew Mu:
* http://stackoverflow.com/questions/4079115
*
* Copyright (c) 2013, Paul Okopny <paul.okopny@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
(function ($, document, undefined) {
var default_wakeup_interval = 1000;
var wake_up_ids = new Array();
// returns intervalId, which can be used to cancel future waking
$.wakeUp = function (on_wakeup, params, interval) {
if ((!interval) || typeof(interval) !== 'number' ){
interval = default_wakeup_interval;
};
// on_wakeup should be a function
if (typeof(on_wakeup) !== "function") {
return null;
}
var lastTime = (new Date()).getTime();
var intervalId = setInterval(function() {
var currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) { //
var sleepTime = currentTime - lastTime;
lastTime = currentTime;
if (params) {
on_wakeup(sleepTime, params);} else {on_wakeup(sleepTime); }
} else {lastTime = currentTime;}
}, interval);
//add interval id to wake_up_ids array
wake_up_ids.push(intervalId);
return intervalId;
};
$.ignoreBell = function(interval_id) {
if (interval_id) {
// delete only one wakeUp call
wake_up_ids.splice($.inArray(interval_id, wake_up_ids),1);
clearInterval(interval_id);
};
};
$.dreamOn = function() {
// delete all current wake Up calls
$.each(wake_up_ids, function(index_of, interval_id) {
clearInterval(interval_id)
});
wake_up_ids = new Array();
};
})(jQuery, document);

View file

@ -220,7 +220,28 @@
</ul>
- >
If you aren't including hidden stories and a user has many stories that are hidden (which happens quite often as they might thumbs down the publisher but thumbs up a title or tag), then make sure to keep paging if the <code>hidden_stories_count</code> is non-zero. Don't rely on the <code>stories</code> list being empty to assume that's when to stop paging.
- url: /rss_feeds/original_text
method: GET
short_desc: "Original text from a story."
long_desc:
- "Retrieve the extracted full text for a story."
params:
- key: story_hash
desc: "A story hash to fetch."
required: true
example: >
story_hash=123:a1d62b
- url: /rss_feeds/original_story
method: GET
short_desc: "Proxied story from website."
long_desc:
- "Retrieve the original website for a story."
params:
- key: story_hash
desc: "A story hash to fetch."
required: true
example: >
story_hash=123:a1d62b
- url: /reader/starred_stories
method: GET
short_desc: "User's starred stories."