From 28f9a084d173927ac01e2170d83db16a8329717e Mon Sep 17 00:00:00 2001 From: cdhigh Date: Tue, 30 Apr 2024 05:35:46 -0300 Subject: [PATCH] add next to login route --- application/base_handler.py | 5 +- application/lib/calibre/ptempfile.py | 6 +- application/lib/calibre/web/feeds/news.py | 8 ++- .../lib/calibre/web/feeds/templates.py | 3 +- application/lib/recipe_helper.py | 5 +- application/lib/urlopener.py | 2 + application/static/base.js | 5 +- application/templates/login.html | 1 + application/templates/my.html | 6 +- application/view/login.py | 10 +-- application/view/subscribe.py | 6 +- requirements.txt | 63 ++++++++++--------- 12 files changed, 72 insertions(+), 48 deletions(-) diff --git a/application/base_handler.py b/application/base_handler.py index 84524815..484d2bc9 100644 --- a/application/base_handler.py +++ b/application/base_handler.py @@ -16,10 +16,13 @@ def login_required(forAjax=False): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): + current_url = request.url if (session.get('login', '') == 1) and get_login_user(): return func(*args, **kwargs) + elif forAjax: + return redirect(url_for("bpLogin.NeedLoginAjax")) else: - return redirect(url_for("bpLogin.NeedLoginAjax") if forAjax else url_for("bpLogin.Login")) + return redirect(url_for("bpLogin.Login", next=current_url)) return wrapper return decorator diff --git a/application/lib/calibre/ptempfile.py b/application/lib/calibre/ptempfile.py index d46970f8..3fec0659 100644 --- a/application/lib/calibre/ptempfile.py +++ b/application/lib/calibre/ptempfile.py @@ -57,8 +57,10 @@ def app_prefix(prefix): return '%s_%s_%s'%(__appname__, __version__, prefix) def base_dir(): - return "" - + global _base_dir + if _base_dir is None: + _base_dir = os.environ.get('KE_TEMP_DIR', '') + return _base_dir def reset_base_dir(): pass diff --git a/application/lib/calibre/web/feeds/news.py b/application/lib/calibre/web/feeds/news.py index d1f75ecb..d09deb9d 100644 --- a/application/lib/calibre/web/feeds/news.py +++ b/application/lib/calibre/web/feeds/news.py @@ -1413,6 +1413,7 @@ def build_index(self): if feeds is None: feeds = self.parse_feeds() + default_log.warning(feeds) if not feeds: raise ValueError('No articles found, aborting') @@ -1868,7 +1869,7 @@ def parse_feeds(self): if not feeds: self.log.warning(f'There are no feeds in "{self.title}"') return [] - + parsed_feeds = [] br = self.browser for obj in feeds: @@ -1915,7 +1916,7 @@ def parse_feeds(self): remove = [fl for fl in parsed_feeds if len(fl) == 0 and self.remove_empty_feeds] for f in remove: parsed_feeds.remove(f) - + return parsed_feeds @classmethod @@ -2142,6 +2143,9 @@ class WebPageUrlNewsRecipe(BasicNewsRecipe): #返回一个Feed实例列表 def parse_feeds(self): + if not self.url_extract_rules: + return super().parse_feeds() + main_urls = self.get_feeds() if not main_urls: self.log.warning(f'There are no urls in "{self.title}"') diff --git a/application/lib/calibre/web/feeds/templates.py b/application/lib/calibre/web/feeds/templates.py index d8076ed1..478fd8d5 100644 --- a/application/lib/calibre/web/feeds/templates.py +++ b/application/lib/calibre/web/feeds/templates.py @@ -65,8 +65,7 @@ def render(self, *args, **kwargs): class EmbeddedContent(Template): def _generate(self, article, style=None, extra_css=None): - ac = article.content - content = ' '.join([e.value for e in ac]) if isinstance(ac, list) else (ac or '') + content = article.content if article.content else '' summary = article.summary if article.summary else '' text = content if len(content) > len(summary) else summary head = HEAD(META(charset="utf-8"), TITLE(article.title)) diff --git a/application/lib/recipe_helper.py b/application/lib/recipe_helper.py index dc0dca71..373f1c1e 100644 --- a/application/lib/recipe_helper.py +++ b/application/lib/recipe_helper.py @@ -31,10 +31,9 @@ def GenerateRecipeSource(title, feeds, user, isfulltext=False, language=None, ma desc = desc[:100] oldest_article = user.book_cfg('oldest_article') #至少到feedparser 6.0.11为止,其提取xml内的内容有bug,经常提取不到,在他修复之前,我们先暂停全文rss功能 - #全部都当非全文rss使用 isfulltext = False auto_cleanup = 'False' if isfulltext else 'True' - isfulltext = 'True' if isfulltext else 'None' + use_embedded_content = 'True' if isfulltext else 'None' language = language or user.book_cfg('language') timefmt = user.book_cfg('time_fmt') if timefmt and (user.book_cfg('title_fmt') == 'title_[time]'): @@ -50,7 +49,7 @@ class {className}({base}): language = '{language}' max_articles_per_feed = {max_articles} oldest_article = {oldest_article} - use_embedded_content = {isfulltext} + use_embedded_content = {use_embedded_content} auto_cleanup = {auto_cleanup} timefmt = '{timefmt}' cover_url = {cover_url} diff --git a/application/lib/urlopener.py b/application/lib/urlopener.py index 3c98dc1b..671463c9 100644 --- a/application/lib/urlopener.py +++ b/application/lib/urlopener.py @@ -118,6 +118,8 @@ def build_url(self, url, data, method): #读取本地文件 def open_local_file(self, url): url = url[7:] if url.startswith('file://') else url[5:] + if url.startswith('//'): + url = url[1:] plat = sys.platform.lower() if ('win32' in plat or 'win64' in plat) and url.startswith('/'): #windows平台 url = url[1:] diff --git a/application/static/base.js b/application/static/base.js index 34e37bda..293695b5 100644 --- a/application/static/base.js +++ b/application/static/base.js @@ -344,9 +344,10 @@ function SubscribeRecipe(id, separated) { //点击了退订内置或上传的Recipe function UnsubscribeRecipe(id, title) { - if (!confirm(i18n.areYouSureUnsubscribe.format(title))) { + if (!(event.ctrlKey || event.metaKey) && !confirm(i18n.areYouSureUnsubscribe.format(title))) { return; } + $.post("/recipe/unsubscribe", {id: id}, function (data) { if (data.status == "ok") { for (var idx = 0; idx < my_booked_recipes.length; idx++) { @@ -487,6 +488,8 @@ function ShowDeleteCustomRssDialog(event, rssid, title, url, isfulltext) { DeleteCustomRss(rssid, title, url, isfulltext, $('#chkReportInvalid').prop('checked')); }).catch(function(){}); } + } else { + DeleteCustomRss(rssid, title, url, isfulltext, false); } } diff --git a/application/templates/login.html b/application/templates/login.html index acb7009e..4eb51ff5 100644 --- a/application/templates/login.html +++ b/application/templates/login.html @@ -25,6 +25,7 @@ +
diff --git a/application/templates/my.html b/application/templates/my.html index e398e081..6010ff9c 100644 --- a/application/templates/my.html +++ b/application/templates/my.html @@ -19,8 +19,10 @@
- +
diff --git a/application/view/login.py b/application/view/login.py index 8ed94f1d..23ca5a40 100644 --- a/application/view/login.py +++ b/application/view/login.py @@ -22,15 +22,17 @@ def Login(): # 则增加一个管理员帐号 ADMIN_NAME,密码 ADMIN_NAME,后续可以修改密码 tips = '' adminName = app.config['ADMIN_NAME'] + next_url = request.args.get('next', '') if CreateAccountIfNotExist(adminName): tips = (_("Please use {}/{} to login at first time.").format(adminName, adminName)) - return render_template('login.html', tips=tips) + return render_template('login.html', tips=tips, next=next_url) @bpLogin.post("/login") def LoginPost(): name = request.form.get('username', '').strip() passwd = request.form.get('password', '') + next_url = request.form.get('next', '') tips = '' if not name: tips = _("Username is empty.") @@ -40,7 +42,7 @@ def LoginPost(): tips = _("The username includes unsafe chars.") if tips: - return render_template('login.html', tips=tips) + return render_template('login.html', tips=tips, next=next_url) adminName = app.config['ADMIN_NAME'] isFirstTime = CreateAccountIfNotExist(adminName) #确认管理员账号是否存在 @@ -75,7 +77,7 @@ def LoginPost(): elif not user.cfg('kindle_email'): url = url_for("bpSetting.Setting") else: - url = url_for("bpSubscribe.MySubscription") + url = next_url if next_url else url_for("bpSubscribe.MySubscription") default_log.info(f"Login event: {name}") return redirect(url) else: #账号或密码错 @@ -89,7 +91,7 @@ def LoginPost(): session.pop('login', None) session.pop('userName', None) session.pop('role', None) - return render_template('login.html', userName=name, tips=tips) + return render_template('login.html', userName=name, tips=tips, next=next_url) #判断账号是否存在 #如果账号不存在,创建一个,并返回True,否则返回False diff --git a/application/view/subscribe.py b/application/view/subscribe.py index d68d695b..17939f25 100644 --- a/application/view/subscribe.py +++ b/application/view/subscribe.py @@ -22,8 +22,10 @@ def MySubscription(tips=None): user = get_login_user() share_key = user.share_links.get('key', '') - title_to_add = request.args.get('title_to_add') #from Bookmarklet - url_to_add = request.args.get('url_to_add') + args = request.args + title_to_add = args.get('title_to_add') #from Bookmarklet/browser extension + url_to_add = args.get('url_to_add') + isfulltext = str_to_bool(args.get('isfulltext')) my_custom_rss = [item.to_dict(only=[Recipe.id, Recipe.title, Recipe.url, Recipe.isfulltext, Recipe.translator, Recipe.tts]) for item in user.all_custom_rss()] diff --git a/requirements.txt b/requirements.txt index e3f1e657..2736354b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,31 +1,36 @@ -requests>=2.31.0,<3.0.0 -chardet>=5.2.0,<6.0.0 -pillow>=10.2.0,<11.0.0 -lxml>=5.0.0,<6.0.0 -sendgrid>=6.11.0,<7.0.0 -mailjet_rest>=1.3.4,<2.0.0 -python-dateutil>=2.8.2,<3.0.0 -css_parser>=1.0.10,<=2.0.0 -beautifulsoup4>=4.12.2,<5.0.0 -html2text>=2020.1.16 -html5lib>=1.1,<2.0 +requests~=2.31.0 +chardet~=5.2.0 +pillow~=10.3.0 +lxml~=5.2.0 +lxml_html_clean~=0.1.1 +sendgrid~=6.11.0 +mailjet_rest~=1.3.4 +python-dateutil~=2.9.0 +css_parser~=1.0.10 +beautifulsoup4~=4.12.2 +html2text~=2024.2.26 +html5lib~=1.1 #html5-parser~=0.4.0 -gunicorn>=21.2.0,<22.0.0 -Flask>=3.0.0,<4.0.0 -flask-babel>=4.0.0,<5.0.0 -six>=1.16.0,<2.0.0 -feedparser>=6.0.11,<7.0.0 -peewee>=3.1.7,<4.0.0 -flask-apscheduler>=1.13.1,<2.0.0 +gunicorn~=22.0.0 +Flask~=3.0.3 +flask-babel~=4.0.0 +six~=1.16.0 +feedparser~=6.0.11 +qrcode~=7.4.2 +#gtts~=2.5.1 +peewee~=3.17.1 +flask-apscheduler~=1.13.1 +redis~=5.0.3 -#pymysql>=1.1.0,<2.0.0 -#psycopg2>=2.9.9,<3.0.0 -#weedata>=0.2.1,<1.0.0 -#google-cloud-datastore>=2.19.0,<3.0.0 -#pymongo>=3.7.2,<4.0.0 -#redis>=4.5.0,<6.0.0 -#google-cloud-tasks>=2.15.0,<3.0.0 -#celery>=5.3.6,<6.0.0 -#eventlet>=0.35.1,<1.0.0 -#flask-rq2>=18.3,<19.0 -#appengine-python-standard>=1.1.6,<2.0.0 +#pymysql~=1.1.0 +#psycopg2-binary~=2.9.9 +#weedata>=0.2.5,<1.0.0 +#google-cloud-datastore~=2.19.0 +#pymongo~=4.6.3 +#google-cloud-tasks~=2.16.3 +#celery~=5.3.6 +#eventlet~=0.36.1 +#flask-rq2~=18.3 +#appengine-python-standard~=1.1.6 +#google-cloud-texttospeech~=2.16.3 +#sqlalchemy~=2.0.29