Skip to content

Commit 3bf769d

Browse files
committed
add option display_subtitle
1 parent 979b3cf commit 3bf769d

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

comiclib/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Settings(BaseSettings):
1515
password: Union[str, None] = None
1616
skip_exits: bool = True
1717
watch: bool = True
18+
display_subtitle: bool = True
1819
UA_convert_jxl: str = 'Android'
1920
UA_convert_all: str = r'\b\B' # default: match nothing
2021

comiclib/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ async def verify_token(request: Request):
7272
else:
7373
authorization = [Depends(verify_token)]
7474

75+
def display_title(a: Archive) -> str:
76+
return a.subtitle if settings.display_subtitle and not a.subtitle is None else a.title
77+
7578
# https://sugoi.gitbook.io/lanraragi/v/dev/api-documentation/getting-started
7679

7780
# Search API
@@ -122,7 +125,7 @@ def do_search(db: Session, category: str, filters: str, order: Union[OrderingDir
122125
stmt = stmt.offset(start)
123126
return [
124127
{"arcid": a.id, "isnew": "none", "extension": Path(
125-
a.path).suffix, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": a.title}
128+
a.path).suffix, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": display_title(a)}
126129
for a in db.scalars(stmt)
127130
], recordsFiltered, recordsTotal
128131

@@ -171,7 +174,7 @@ def handle_datatables(request: Request, draw: int, start: int, length: int, filt
171174
def get_all_archives(db: Session = Depends(get_db)):
172175
data = [
173176
{"arcid": a.id, "isnew": "none", "extension": Path(
174-
a.path).suffix, "pagecount": a.pagecount, "progress": 0, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": a.title}
177+
a.path).suffix, "pagecount": a.pagecount, "progress": 0, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": display_title(a)}
175178
for a in db.scalars(select(Archive))
176179
]
177180
return {"data": data}
@@ -187,12 +190,17 @@ def get_archive_metadata(id: str, db: Session = Depends(get_db)):
187190
a = db.get(Archive, id)
188191
if a is None:
189192
return JSONResponse({"operation": "metadata", "error": "This ID doesn't exist on the server.", "success": 0}, status.HTTP_400_BAD_REQUEST)
190-
return {"arcid": a.id, "isnew": "false", "pagecount": a.pagecount, "progress": 1, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": a.title}
193+
return {"arcid": a.id, "isnew": "false", "pagecount": a.pagecount, "progress": 1, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": display_title(a)}
191194

192195

193196
@app.put("/api/archives/{id}/metadata", dependencies=authorization)
194197
def update_archive_metadata(id: str, title: Annotated[str, Form()], tags: Annotated[str, Form()], db: Session = Depends(get_db)):
195-
db.execute(update(Archive).where(Archive.id == id).values(title=title))
198+
if settings.display_subtitle:
199+
a = db.get(Archive, id)
200+
if not (a.title == title or a.subtitle == title):
201+
return {"operation": "update_metadata", "error": "You are using a non-standard title display mode, and there is ambiguity in modifying the title.", "success": 0}
202+
else:
203+
db.execute(update(Archive).where(Archive.id == id).values(title=title))
196204
db.execute(delete(Tag).where(Tag.archive_id == id))
197205
db.add_all(map(lambda t: Tag(archive_id=id, tag=t.strip()), tags.split(',')))
198206
db.commit()

docs/en/docs/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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` |
3839
| `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` |
3940
| `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) |
4041

docs/zh/docs/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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` |
3839
| `UA_convert_jxl` | 对于哪些 user-agent 的请求在服务端将 JPEG XL 文件转为其他流行格式,该值是一个用于匹配的正则表达式 | `Android` |
3940
| `UA_convert_all` | 对于哪些 user-agent 的请求在服务端将所有文件转为其他流行格式,该值是一个用于匹配的正则表达式 | `\b\B`(不匹配任何东西)|
4041

0 commit comments

Comments
 (0)