Skip to content

Commit 27e3e7b

Browse files
committed
add option display_title_format
1 parent 4ed4e24 commit 27e3e7b

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

comiclib/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pydantic_settings import BaseSettings
2-
from typing import Union
2+
from typing import Union, Optional
33
import re
44
import logging
55

@@ -15,7 +15,8 @@ class Settings(BaseSettings):
1515
password: Union[str, None] = None
1616
skip_exits: bool = True
1717
watch: bool = True
18-
display_subtitle: bool = True
18+
display_title_format: Optional[str] = None
19+
display_subtitle: Optional[bool] = None
1920
UA_convert_jxl: str = 'Android'
2021
UA_convert_all: str = r'\b\B' # default: match nothing
2122

@@ -31,6 +32,9 @@ class Settings(BaseSettings):
3132
level=numeric_level)
3233
logger.debug(settings)
3334

35+
if settings.display_subtitle is not None:
36+
logger.warning('The environment variable display_subtitle is deprecated and will be removed in the future. Please use display_title_format instead.')
37+
3438
settings.UA_convert_jxl = re.compile(settings.UA_convert_jxl)
3539
settings.UA_convert_all = re.compile(settings.UA_convert_all)
3640
if settings.thumb is None:

comiclib/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ async def verify_token(request: Request):
7676
authorization = [Depends(verify_token)]
7777

7878
def display_title(a: Archive) -> str:
79-
return a.subtitle if settings.display_subtitle and not a.subtitle is None else a.title
79+
if settings.display_title_format is None:
80+
return a.title
81+
else:
82+
return settings.display_title_format.replace('{title}', a.title).replace('{subtitle}', '' if a.subtitle is None else a.subtitle).replace('{path}', a.path).replace(r'\n', '\n')
8083

8184
# https://sugoi.gitbook.io/lanraragi/v/dev/api-documentation/getting-started
8285

@@ -198,7 +201,7 @@ def get_archive_metadata(id: str, db: Session = Depends(get_db)):
198201

199202
@app.put("/api/archives/{id}/metadata", dependencies=authorization)
200203
def update_archive_metadata(id: str, title: Annotated[str, Form()], tags: Annotated[str, Form()], db: Session = Depends(get_db)):
201-
if settings.display_subtitle:
204+
if settings.display_title_format is not None:
202205
a = db.get(Archive, id)
203206
if not (a.title == title or a.subtitle == title):
204207
return {"operation": "update_metadata", "error": "You are using a non-standard title display mode, and there is ambiguity in modifying the title.", "success": 0}

docs/en/docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ For more settings, please refer to [Gunicorn's documentation](https://docs.gunic
125125

126126
In the end your command might look like this (my personal use case):
127127
``` bash
128-
CONTENT=../mycomics/ thumb=/tmp/thumb/ gunicorn comiclib.main:app --worker-class uvicorn.workers.UvicornWorker --bind unix:/tmp/comiclib.sock --preload --workers 4
128+
CONTENT=../mycomics/ thumb=/tmp/thumb/ display_title_format='{subtitle}\n{title}\n{path}' gunicorn comiclib.main:app --worker-class uvicorn.workers.UvicornWorker --bind unix:/tmp/comiclib.sock --preload --workers 4
129129
```
130130
or
131131
``` bash
132-
importEHdb_matchtorrent=False importEHdb_matchtitle=False CONTENT=../mycomics/ thumb=/tmp/thumb/ uvicorn comiclib.main:app --uds /tmp/comiclib.sock --reload --log-level trace
132+
importEHdb_matchtorrent=False importEHdb_matchtitle=False CONTENT=../mycomics/ thumb=/tmp/thumb/ display_title_format='{subtitle}\n{title}\n{path}' uvicorn comiclib.main:app --uds /tmp/comiclib.sock --reload --log-level trace
133133
```
134134
for debugging.
135135
Then use Nginx to reverse proxy to HTTPS connection.

docs/en/docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The following is a list of available settings:
3535
| `password` | Admin password (also used as API Key currently) [^1]. If it is `None`, any visitor will have editing permissions. This feature is designed to protect against gentlemen but not villains. If you need security protection, please use e.g. the HTTP basic authentication of the reverse proxy, Cloudflare Access or TLS client certificate, etc. | `None`|
3636
| `skip_exists`| Skip comics that have been scanned into the metadata database during scanning? (`True`/`False`) | `True` |
3737
| `watch` | Monitor comic folders and automatically scan (`True`/`False`) | `True` |
38-
| `display_subtitle` | Display subtitles instead of main titles if available. The title cannot be edited in this mode. | `True` |
38+
| `display_title_format` | This string specifies the format of the display title. `{title}`, `{subtitle}`, `{path}` can be used as a placeholder. `\n` will be escaped as a newline. Title cannot be edited while this is set. | `None` (original title) |
3939
| `UA_convert_jxl` | For requests with matched user-agent, convert JPEG XL files to other popular formats on the server side. The value is a regular expression. | `Android` |
4040
| `UA_convert_all` | For requests with matched user-agent, convert all files to other popular formats on the server side. The value is a regular expression. | `\b\B` (will not match anything) |
4141

docs/zh/docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ gunicorn comiclib.main:app --worker-class uvicorn.workers.UvicornWorker --bind 0
125125

126126
最后你的命令可能会像这样(我的个人用例):
127127
``` bash
128-
CONTENT=../mycomics/ thumb=/tmp/thumb/ gunicorn comiclib.main:app --worker-class uvicorn.workers.UvicornWorker --bind unix:/tmp/comiclib.sock --preload --workers 4
128+
CONTENT=../mycomics/ thumb=/tmp/thumb/ display_title_format='{subtitle}\n{title}\n{path}' gunicorn comiclib.main:app --worker-class uvicorn.workers.UvicornWorker --bind unix:/tmp/comiclib.sock --preload --workers 4
129129
```
130130
或者
131131
``` bash
132-
importEHdb_matchtorrent=False importEHdb_matchtitle=False CONTENT=../mycomics/ thumb=/tmp/thumb/ uvicorn comiclib.main:app --uds /tmp/comiclib.sock --reload --log-level trace
132+
importEHdb_matchtorrent=False importEHdb_matchtitle=False CONTENT=../mycomics/ thumb=/tmp/thumb/ display_title_format='{subtitle}\n{title}\n{path}' uvicorn comiclib.main:app --uds /tmp/comiclib.sock --reload --log-level trace
133133
```
134134
用于调试。
135135
然后通过 Nginx 反代为 HTTPS 连接。

docs/zh/docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
| `password` | 管理密码(目前也用作 API 密钥)[^1],若为`None`则任何访客皆可编辑。此功能防君子不防小人,若需安全保护请借助反向代理的 HTTP 基本验证、Cloudflare Access 或 TLS 客户端证书等。| `None`|
3636
| `skip_exists`| 扫描时是否跳过曾扫入元数据库的漫画?(`True`/`False`| `True` |
3737
| `watch` | 监视漫画文件夹,自动扫描 (`True`/`False`| `True` |
38-
| `display_subtitle` | 展现子标题(如果有)而不是主标题。该模式下无法编辑标题。 | `True` |
38+
| `display_title_format` | 该字符串指定展示标题的格式。可以使用 `{title}`, `{subtitle}`, `{path}` 作为占位符,`\n` 会被转义为换行。设定此项时无法编辑标题。 | `None`(原标题) |
3939
| `UA_convert_jxl` | 对于哪些 user-agent 的请求在服务端将 JPEG XL 文件转为其他流行格式,该值是一个用于匹配的正则表达式 | `Android` |
4040
| `UA_convert_all` | 对于哪些 user-agent 的请求在服务端将所有文件转为其他流行格式,该值是一个用于匹配的正则表达式 | `\b\B`(不匹配任何东西)|
4141

0 commit comments

Comments
 (0)