more explict prompt to search links
This commit is contained in:
parent
14b02c93f6
commit
3de032367a
9 changed files with 35 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -77,7 +77,18 @@
|
|||
{% for item in items %}
|
||||
{% include '_list_item.html' with show_tags=1 %}
|
||||
{% empty %}
|
||||
<p class="empty">{% trans '无站内条目匹配' %}</p>
|
||||
<p>
|
||||
无站内条目匹配。
|
||||
{% if user.is_authenticated %}系统会尝试搜索其它网站的条目,点击标题可添加到本站。{% endif %}
|
||||
</p>
|
||||
<p>
|
||||
如果你在
|
||||
{% for site in sites %}
|
||||
{{ site }}
|
||||
{% if not forloop.last %}/{% endif %}
|
||||
{% endfor %}
|
||||
找到了相关条目,也可以把链接(如 <code>https://movie.douban.com/subject/1309046/</code> )输入到搜索栏中提交保存到本站。
|
||||
</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if dup_items %}
|
||||
|
@ -98,6 +109,8 @@
|
|||
<span><i class="fa-solid fa-compact-disc fa-spin loading"></i></span>
|
||||
{% trans '正在实时搜索站外条目' %}
|
||||
</p>
|
||||
{% else %}
|
||||
登录用户可看到来自其它网站的搜索结果。
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 <hr/><a href='{settings.APP_WEBSITE}'>Learn more</a>",
|
||||
description=f"{settings.SITE_INFO['site_name']} API <hr/><a href='{settings.SITE_INFO['site_url']}'>Learn more</a>",
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<input type="search"
|
||||
name="q"
|
||||
id="q"
|
||||
placeholder="搜索标题、创作者、ISBN、链接(如 https://movie.douban.com/subject/1297880/ )"
|
||||
placeholder="标题、创作者、ISBN、站外条目链接"
|
||||
class="search"
|
||||
value="{{ request.GET.q|default:'' }}" />
|
||||
<select name="c">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 "无效链接"
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue