From 3de032367aab0bb852924710f41fbdef95f43fa3 Mon Sep 17 00:00:00 2001
From: Your Name
Date: Mon, 10 Jul 2023 15:29:29 -0400
Subject: [PATCH] more explict prompt to search links
---
boofilsic/settings.py | 13 +++++--------
catalog/common/models.py | 4 ++--
catalog/templates/search_results.html | 15 ++++++++++++++-
common/api.py | 2 +-
common/templates/_header.html | 2 +-
doc/configuration.md | 11 +++++------
journal/feeds.py | 2 +-
journal/models.py | 2 +-
mastodon/api.py | 10 +++++-----
9 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/boofilsic/settings.py b/boofilsic/settings.py
index 862595c7..39f6e6fd 100644
--- a/boofilsic/settings.py
+++ b/boofilsic/settings.py
@@ -225,8 +225,8 @@ MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
SITE_INFO = {
- "site_name": "NiceDB",
- "site_url": "https://nicedb.org",
+ "site_name": os.environ.get("APP_NAME", "NiceDB"),
+ "site_url": os.environ.get("APP_URL", "https://nicedb.org"),
"support_link": "https://github.com/doubaniux/boofilsic/issues",
"social_link": "https://donotban.com/@testie",
"donation_link": "https://patreon.com/tertius",
@@ -235,12 +235,9 @@ SITE_INFO = {
"sentry_dsn": None,
}
-# Mastodon configs
-CLIENT_NAME = os.environ.get("APP_NAME", "NiceDB")
-SITE_INFO["site_name"] = os.environ.get("APP_NAME", "NiceDB")
-APP_WEBSITE = os.environ.get("APP_URL", "https://nicedb.org")
-REDIRECT_URIS = APP_WEBSITE + "/users/OAuth2_login/"
-SITE_INFO["site_url"] = APP_WEBSITE
+REDIRECT_URIS = SITE_INFO["site_url"] + "/users/OAuth2_login/"
+# if you are creating new site, use
+# REDIRECT_URIS = SITE_INFO["site_url"] + "/account/login/oauth"
# Path to save report related images, ends with slash
diff --git a/catalog/common/models.py b/catalog/common/models.py
index 73a43e61..8b8eb98d 100644
--- a/catalog/common/models.py
+++ b/catalog/common/models.py
@@ -392,7 +392,7 @@ class Item(SoftDeleteMixin, PolymorphicModel):
@property
def absolute_url(self):
- return f"{settings.APP_WEBSITE}{self.url}"
+ return f"{settings.SITE_INFO['site_url']}{self.url}"
@property
def api_url(self):
@@ -451,7 +451,7 @@ class Item(SoftDeleteMixin, PolymorphicModel):
@property
def cover_image_url(self):
return (
- f"{settings.APP_WEBSITE}{self.cover.url}"
+ f"{settings.SITE_INFO['site_url']}{self.cover.url}"
if self.cover and self.cover != DEFAULT_ITEM_COVER
else None
)
diff --git a/catalog/templates/search_results.html b/catalog/templates/search_results.html
index 3b3a8a0f..42621785 100644
--- a/catalog/templates/search_results.html
+++ b/catalog/templates/search_results.html
@@ -77,7 +77,18 @@
{% for item in items %}
{% include '_list_item.html' with show_tags=1 %}
{% empty %}
- {% trans '无站内条目匹配' %}
+
+ 无站内条目匹配。
+ {% if user.is_authenticated %}系统会尝试搜索其它网站的条目,点击标题可添加到本站。{% endif %}
+
+
+ 如果你在
+ {% for site in sites %}
+ {{ site }}
+ {% if not forloop.last %}/{% endif %}
+ {% endfor %}
+ 找到了相关条目,也可以把链接(如 https://movie.douban.com/subject/1309046/
)输入到搜索栏中提交保存到本站。
+
{% endfor %}
{% if dup_items %}
@@ -98,6 +109,8 @@
{% trans '正在实时搜索站外条目' %}
+ {% else %}
+ 登录用户可看到来自其它网站的搜索结果。
{% endif %}
diff --git a/common/api.py b/common/api.py
index 09b58b64..80bf5ced 100644
--- a/common/api.py
+++ b/common/api.py
@@ -70,5 +70,5 @@ api = NinjaAPI(
auth=OAuthAccessTokenAuth(),
title=settings.SITE_INFO["site_name"] + " API",
version="1.0.0",
- description=f"{settings.SITE_INFO['site_name']} API Learn more ",
+ description=f"{settings.SITE_INFO['site_name']} API Learn more ",
)
diff --git a/common/templates/_header.html b/common/templates/_header.html
index 7d4ed445..0ddaccbc 100644
--- a/common/templates/_header.html
+++ b/common/templates/_header.html
@@ -14,7 +14,7 @@
diff --git a/doc/configuration.md b/doc/configuration.md
index 59302814..6ab2cfc4 100644
--- a/doc/configuration.md
+++ b/doc/configuration.md
@@ -6,15 +6,14 @@ Settings you may want to change
-------------------------------
most settings resides in `settings.py`, a few notable ones:
- - `SECRET_KEY` back it up well somewhere
- - `SITE_INFO['site_name']` change by you need
- - `CLIENT_NAME` site name shown in Mastodon app page
- - `APP_WEBSITE` external root url for your side
- - `REDIRECT_URIS` this should be `APP_WEBSITE + "/account/login/oauth"` . It can be multiple urls separated by `\n` , but not all Fediverse software support it well. Also note changing this later may invalidate app token granted previously
+ - `SECRET_KEY` must use your own, back it up well somewhere
+ - `SITE_INFO` change by you need
+ - `REDIRECT_URIS` this should be `SITE_INFO["site_url"] + "/account/login/oauth"` . It used to be multiple urls separated by `\n` , but now it must be only one url, bc not all Fediverse software support >1 urls very well. Also note changing this later may invalidate app token granted previously
- `MASTODON_ALLOW_ANY_SITE` set to `True` so that user can login via any Mastodon API compatible sites (e.g. Mastodon/Pleroma)
- `MASTODON_CLIENT_SCOPE` change it later may invalidate app token granted previously
- `ADMIN_URL` admin page url, keep it private
- - `SEARCH_BACKEND` should be either `TYPESENSE` or `MEILISEARCH` so that search and index can function. `None` will use default database search, which is for development only and may gets deprecated soon.
+ - `SEARCH_BACKEND` should be ~~either~~ `TYPESENSE` ~~or `MEILISEARCH`~~ so that search and index can function. `None` will use default database search, which is for development only and may gets deprecated soon.
+ - `MEILISEARCH` support is removed due to lack of usage, feel free to PR if you want to
Settings for Scrapers
diff --git a/journal/feeds.py b/journal/feeds.py
index 0ee93c74..770bfb4c 100644
--- a/journal/feeds.py
+++ b/journal/feeds.py
@@ -15,7 +15,7 @@ class ReviewFeed(Feed):
return "%s的评论" % user.display_name if user else "无效链接"
def link(self, user):
- return user.url if user else settings.APP_WEBSITE
+ return user.url if user else settings.SITE_INFO["site_url"]
def description(self, user):
return "%s的评论合集 - NeoDB" % user.display_name if user else "无效链接"
diff --git a/journal/models.py b/journal/models.py
index 285eb4b8..7062dfa6 100644
--- a/journal/models.py
+++ b/journal/models.py
@@ -125,7 +125,7 @@ class Piece(PolymorphicModel, UserOwnedObjectMixin):
@property
def absolute_url(self):
- return (settings.APP_WEBSITE + self.url) if self.url_path else None
+ return (settings.SITE_INFO["site_url"] + self.url) if self.url_path else None
@property
def api_url(self):
diff --git a/mastodon/api.py b/mastodon/api.py
index 42622d17..021d018f 100644
--- a/mastodon/api.py
+++ b/mastodon/api.py
@@ -58,7 +58,7 @@ TWITTER_API_POST = "https://api.twitter.com/2/tweets"
TWITTER_API_TOKEN = "https://api.twitter.com/2/oauth2/token"
-USER_AGENT = f"{settings.CLIENT_NAME}/1.0"
+USER_AGENT = f"{settings.SITE_INFO['site_name']}/1.0"
get = functools.partial(requests.get, timeout=settings.MASTODON_TIMEOUT)
put = functools.partial(requests.put, timeout=settings.MASTODON_TIMEOUT)
@@ -138,10 +138,10 @@ def create_app(domain_name):
url = "http://" + domain_name + API_CREATE_APP
payload = {
- "client_name": settings.CLIENT_NAME,
+ "client_name": settings.SITE_INFO["site_name"],
"scopes": settings.MASTODON_CLIENT_SCOPE,
"redirect_uris": settings.REDIRECT_URIS,
- "website": settings.APP_WEBSITE,
+ "website": settings.SITE_INFO["site_url"],
}
response = post(url, data=payload, headers={"User-Agent": USER_AGENT})
@@ -300,7 +300,7 @@ def get_mastodon_application(login_domain):
def get_mastodon_login_url(app, login_domain, request):
- url = request.scheme + "://" + request.get_host() + "/users/OAuth2_login/"
+ url = settings.REDIRECT_URIS
if login_domain == TWITTER_DOMAIN:
return f"https://twitter.com/i/oauth2/authorize?response_type=code&client_id={app.client_id}&redirect_uri={quote(url)}&scope={quote(settings.TWITTER_CLIENT_SCOPE)}&state=state&code_challenge=challenge&code_challenge_method=plain"
version = app.server_version or ""
@@ -325,7 +325,7 @@ def get_mastodon_login_url(app, login_domain, request):
def obtain_token(site, request, code):
"""Returns token if success else None."""
mast_app = MastodonApplication.objects.get(domain_name=site)
- redirect_uri = request.scheme + "://" + request.get_host() + "/users/OAuth2_login/"
+ redirect_uri = settings.REDIRECT_URIS
payload = {
"client_id": mast_app.client_id,
"client_secret": mast_app.client_secret,