configurable site name

This commit is contained in:
Your Name 2022-07-06 18:53:34 -04:00
parent e43a3ee5d2
commit 8444a44fa2
7 changed files with 23 additions and 21 deletions

View file

@ -200,7 +200,7 @@ AUTH_USER_MODEL = 'users.User'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
SITE_INFO = {'site_name': 'NeoDB', 'support_link': 'https://github.com/doubaniux/boofilsic/issues'}
SITE_INFO = {'site_name': 'NiceDB', 'support_link': 'https://github.com/doubaniux/boofilsic/issues'}
# Mastodon configs
CLIENT_NAME = 'NiceDB'

View file

@ -60,6 +60,8 @@ 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"
get = functools.partial(requests.get, timeout=settings.MASTODON_TIMEOUT)
post = functools.partial(requests.post, timeout=settings.MASTODON_TIMEOUT)
@ -69,7 +71,7 @@ def get_relationships(site, id_list, token): # no longer in use
url = 'https://' + site + API_GET_RELATIONSHIPS
payload = {'id[]': id_list}
headers = {
'User-Agent': 'NeoDB/1.0',
'User-Agent': USER_AGENT,
'Authorization': f'Bearer {token}'
}
response = get(url, headers=headers, params=payload)
@ -78,7 +80,7 @@ def get_relationships(site, id_list, token): # no longer in use
def post_toot(site, content, visibility, token, local_only=False):
headers = {
'User-Agent': 'NeoDB/1.0',
'User-Agent': USER_AGENT,
'Authorization': f'Bearer {token}',
'Idempotency-Key': random_string_generator(16)
}
@ -112,7 +114,7 @@ def get_instance_info(domain_name):
return TWITTER_DOMAIN, ''
try:
url = f'https://{domain_name}/api/v1/instance'
response = get(url, headers={'User-Agent': 'NeoDB/1.0'})
response = get(url, headers={'User-Agent': USER_AGENT})
j = response.json()
return j['uri'].lower().split('//')[-1].split('/')[0], j['version']
except Exception:
@ -143,7 +145,7 @@ def create_app(domain_name):
'website': settings.APP_WEBSITE
}
response = post(url, data=payload, headers={'User-Agent': 'NeoDB/1.0'})
response = post(url, data=payload, headers={'User-Agent': USER_AGENT})
return response
@ -155,7 +157,7 @@ def get_site_id(username, user_site, target_site, token):
'q': f"{username}@{user_site}"
}
headers = {
'User-Agent': 'NeoDB/1.0',
'User-Agent': USER_AGENT,
'Authorization': f'Bearer {token}'
}
response = get(url, params=payload, headers=headers)
@ -224,7 +226,7 @@ def verify_account(site, token):
if site == TWITTER_DOMAIN:
url = TWITTER_API_ME + '?user.fields=id,username,name,description,profile_image_url,created_at,protected'
try:
response = get(url, headers={'User-Agent': 'NeoDB/1.0', 'Authorization': f'Bearer {token}'})
response = get(url, headers={'User-Agent': USER_AGENT, 'Authorization': f'Bearer {token}'})
if response.status_code != 200:
logger.error(f"Error {url} {response.status_code}")
return response.status_code, None
@ -240,7 +242,7 @@ def verify_account(site, token):
return -1, None
url = 'https://' + site + API_VERIFY_ACCOUNT
try:
response = get(url, headers={'User-Agent': 'NeoDB/1.0', 'Authorization': f'Bearer {token}'})
response = get(url, headers={'User-Agent': USER_AGENT, 'Authorization': f'Bearer {token}'})
return response.status_code, (response.json() if response.status_code == 200 else None)
except Exception:
return -1, None
@ -252,7 +254,7 @@ def get_related_acct_list(site, token, api):
url = 'https://' + site + api
results = []
while url:
response = get(url, headers={'User-Agent': 'NeoDB/1.0', 'Authorization': f'Bearer {token}'})
response = get(url, headers={'User-Agent': USER_AGENT, 'Authorization': f'Bearer {token}'})
url = None
if response.status_code == 200:
results.extend(map(lambda u: (u['acct'] if u['acct'].find('@') != -1 else u['acct'] + '@' + site) if 'acct' in u else u, response.json()))
@ -322,7 +324,7 @@ def obtain_token(site, request, code):
'grant_type': 'authorization_code',
'code': code
}
headers = {'User-Agent': 'NeoDB/1.0'}
headers = {'User-Agent': USER_AGENT}
auth = None
if mast_app.is_proxy:
url = 'https://' + mast_app.proxy_to + API_OBTAIN_TOKEN
@ -356,7 +358,7 @@ def refresh_access_token(site, refresh_token):
'refresh_token': refresh_token,
'grant_type': 'refresh_token',
}
headers = {'User-Agent': 'NeoDB/1.0'}
headers = {'User-Agent': USER_AGENT}
auth = (mast_app.client_id, mast_app.client_secret)
response = post(url, data=payload, headers=headers, auth=auth)
if response.status_code != 200:
@ -379,7 +381,7 @@ def revoke_token(site, token):
url = 'https://' + mast_app.proxy_to + API_REVOKE_TOKEN
else:
url = 'https://' + site + API_REVOKE_TOKEN
post(url, data=payload, headers={'User-Agent': 'NeoDB/1.0'})
post(url, data=payload, headers={'User-Agent': USER_AGENT})
def share_mark(mark):

View file

@ -40,7 +40,7 @@
<link rel="stylesheet" href="{% static 'lib/css/rating-star.css' %}">
<link rel="stylesheet" href="{% static 'css/boofilsic.min.css' %}">
<link rel="stylesheet" href="{% static 'lib/css/neo.css' %}">
<link rel="search"type="application/opensearchdescription+xml" title="NeoDB" href="{% static 'opensearch.xml' %}">
<link rel="search"type="application/opensearchdescription+xml" title="{{ site_name }}" href="{% static 'opensearch.xml' %}">
</head>
<body>

View file

@ -204,9 +204,9 @@
<input type="submit" class="import-panel__button" value="{% trans '导入' %}" id="uploadBtn" />
</div>
<div>
Goodreads用户主页链接形如 https://www.goodreads.com/user/show/12345-janedoe 将自动导入到NeoDB用户的想读、在读、已读列表每本书的评论导入为NeoDB短评;
Goodreads用户主页链接形如 https://www.goodreads.com/user/show/12345-janedoe 将自动导入到当前用户的想读、在读、已读列表,每本书的评论导入为本站短评;
<br />
Goodreads书单链接形如 https://www.goodreads.com/review/list/12345-janedoe?shelf=name 或 https://www.goodreads.com/list/show/155086.Popular_Highlights 将自动导入成为NeoDB收藏单,每本书的评论导入为NeoDB收藏单条目备注。
Goodreads书单链接形如 https://www.goodreads.com/review/list/12345-janedoe?shelf=name 或 https://www.goodreads.com/list/show/155086.Popular_Highlights 将自动导入成为收藏单,每本书的评论导入为收藏单条目备注。
<br />
欲导入的Goodreads用户需将Who Can View My Profile设置为anyone导入后可改回原设置。
</div>
@ -273,7 +273,7 @@
{% csrf_token %}
<input type="submit" class="import-panel__button" value="{% trans '同步' %}" id="uploadBtn" /> 上次更新时间 {{ user.mastodon_last_refresh }}
<div>
为了正确高效的展示短评和评论,NeoDB会缓存你在联邦网络的关注、屏蔽和静音列表。如果你刚刚更新过帐户的上锁状态、增减过关注、静音或屏蔽,希望立即生效,可以点击这里立刻更新;这类信息也会每天自动同步。
为了正确高效的展示短评和评论,{{ site_name }}会缓存你在联邦网络的关注、屏蔽和静音列表。如果你刚刚更新过帐户的上锁状态、增减过关注、静音或屏蔽,希望立即生效,可以点击这里立刻更新;这类信息也会每天自动同步。
</div>
</form>
</div>
@ -293,7 +293,7 @@
<input type="submit" class="import-panel__button" value="{% trans '登录新账号' %}" id="uploadBtn" />
</div>
<div>
替换后可使用新的联邦网络身份来登录NeoDB和控制数据可见性,已有的标记评论收藏单等数据不受影响。
替换后可使用新的联邦网络身份来登录{{ site_name }}和控制数据可见性,已有的标记评论收藏单等数据不受影响。
</div>
</form>
</div>

View file

@ -20,7 +20,7 @@
<script src="{% static 'js/mastodon.js' %}"></script>
<script src="{% static 'js/home.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/boofilsic.min.css' %}">
<link rel="search"type="application/opensearchdescription+xml" title="NeoDB" href="{% static 'opensearch.xml' %}">
<link rel="search"type="application/opensearchdescription+xml" title="{{ site_name }}" href="{% static 'opensearch.xml' %}">
</head>
<body>

View file

@ -6,7 +6,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="{{ site_name }} - 联邦宇宙书影音游戏标注平台">
<meta name="description" property="og:description" content="NeoDB致力于为联邦宇宙居民提供一个自由、开放、互联的书籍、电影、音乐和游戏收藏评论空间">
<meta name="description" property="og:description" content="{{ site_name }}致力于为联邦宇宙居民提供一个自由、开放、互联的书籍、电影、音乐和游戏收藏评论空间">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ request.build_absolute_uri }}">
<meta property="og:image" content="{{ request.scheme }}://{{ request.get_host }}{% static 'img/logo_square.jpg' %}">
@ -17,7 +17,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js"></script>
<script> $(document).ready( function() { $('.delayed').remove(); } ); </script>
<title>{{ site_name }} - {% trans '登录' %}</title>
<link rel="search"type="application/opensearchdescription+xml" title="NeoDB" href="{% static 'opensearch.xml' %}">
<link rel="search"type="application/opensearchdescription+xml" title="{{ site_name }}" href="{% static 'opensearch.xml' %}">
<style type="text/css">
.delayed {
animation: 10s fadeIn;

View file

@ -30,7 +30,7 @@
<form action="{% url 'users:preferences' %}" method="POST">
<div class="tools-section-wrapper">
<div class="import-panel">
<h5 class="import-panel__label">{% trans 'NeoDB使用偏好设置' %}</h5>
<h5 class="import-panel__label">{% trans '使用偏好设置' %}</h5>
<div class="import-panel__body">
{% csrf_token %}
<span>{% trans '新标记默认可见性:' %}</span>