From d59f9b6eb4ad192b01a9b8bbf102160a6082cbc4 Mon Sep 17 00:00:00 2001 From: Rongrong Date: Tue, 17 Sep 2024 22:14:52 +0800 Subject: [PATCH] fix(db): canonical `DATABASE_URL` not recognized See also: - https://datatracker.ietf.org/doc/html/rfc1808#section-2.2 - https://datatracker.ietf.org/doc/html/rfc2396#section-3 - https://datatracker.ietf.org/doc/html/rfc3986#section-3 - https://datatracker.ietf.org/doc/html/rfc8089#appendix-B Fixes #528 Signed-off-by: Rongrong --- .env.sample | 2 +- docker-compose.yml.sample | 2 +- docs/CHANGELOG.md | 6 ++++++ docs/CHANGELOG.zh.md | 6 ++++++ docs/advanced-settings.md | 2 +- src/db/__init__.py | 2 +- src/env.py | 2 +- 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.env.sample b/.env.sample index 6b01cf7df8..9622d52b59 100644 --- a/.env.sample +++ b/.env.sample @@ -20,7 +20,7 @@ TELEGRAPH_TOKEN=" #ERROR_LOGGING_CHAT=-1001234567890 # default: the first MANAGER #MULTIUSER=0 # default: 1 #CRON_SECOND=30 # 0-59, default: 0 -#DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite://path/to/config/db.sqlite3 +#DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite:/path/to/config/db.sqlite3 #API_ID=1025907 # get it from https://core.telegram.org/api/obtaining_api_id #API_HASH=452b0359b988148995f22ff0f4229750 # get it from https://core.telegram.org/api/obtaining_api_id #IMG_RELAY_SERVER=https://wsrv.nl/?url= # default: https://rsstt-img-relay.rongrong.workers.dev/ diff --git a/docker-compose.yml.sample b/docker-compose.yml.sample index 3e67610546..e8a3dfff56 100644 --- a/docker-compose.yml.sample +++ b/docker-compose.yml.sample @@ -30,7 +30,7 @@ services: #- ERROR_LOGGING_CHAT=-1001234567890 # default: the first MANAGER #- MULTIUSER=0 # default: 1 #- CRON_SECOND=30 # 0-59, default: 0 - #- DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite://path/to/config/db.sqlite3 + #- DATABASE_URL=postgres://username:password@host:port/db_name # default: sqlite:/path/to/config/db.sqlite3 #- API_ID=1025907 # get it from https://core.telegram.org/api/obtaining_api_id #- API_HASH=452b0359b988148995f22ff0f4229750 # get it from https://core.telegram.org/api/obtaining_api_id #- IMG_RELAY_SERVER=https://wsrv.nl/?url= # default: https://rsstt-img-relay.rongrong.workers.dev/ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 74e5a58f5c..7fd476c6d6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Bug fixes + +- **Canonical `DATABASE_URL` not recognized**: Since v2.9.0, `DATABASE_URL` is canonicalized before connecting to the corresponding database. However, a canonical URL pointing to a local path cannot be recognized when checking the validity of the scheme (database type). Both canonical (`scheme:/path/to/file.db`) and traditional (`scheme:///path/to/file.db`) forms of such URLs are recognized correctly now. + ## v2.9.0: Telegraph-related revert, skip cert verification, and more ### BREAKING CHANGES diff --git a/docs/CHANGELOG.zh.md b/docs/CHANGELOG.zh.md index 9afaafd69b..61788bbec9 100644 --- a/docs/CHANGELOG.zh.md +++ b/docs/CHANGELOG.zh.md @@ -1,5 +1,11 @@ # 更新日志 +## 未发布 + +### Bug 修复 + +- **无法识别规范的 `DATABASE_URL`**: 自 v2.9.0 起, 在连接到相应的数据库之前,`DATABASE_URL` 被规范化。然而,在检查 scheme (数据库类型) 的合法性时,无法识别指向本地路径的规范 URL。现在,此类 URL 的规范 (`scheme:/path/to/file.db`) 和传统 (`scheme:///path/to/file.db`) 形式都被正确识别。 + ## v2.9.0: 与 Telegraph 相关的 revert、跳过证书校验和更多 ### 重大变更 diff --git a/docs/advanced-settings.md b/docs/advanced-settings.md index c419916402..63531223ef 100644 --- a/docs/advanced-settings.md +++ b/docs/advanced-settings.md @@ -51,7 +51,7 @@ | `CRON_SECOND` | Run the feed monitoring task at the n-th second of each minute? (0-59) | `30` | `0` | | `IMG_RELAY_SERVER` | Media relay server (https://github.com/Rongronggg9/rsstt-img-relay) URL | `https://wsrv.nl/?url=` | `https://rsstt-img-relay.rongrong.workers.dev/` | | `IMAGES_WESERV_NL` | https://github.com/weserv/images instance | `https://t0.nl/` | `https://wsrv.nl/` | -| `DATABASE_URL` | Database URL [^7] | `postgres://user:pass@example.com:5432/table` | `sqlite://path/to/config/db.sqlite3` | +| `DATABASE_URL` | Database URL [^7] | `postgres://user:pass@example.com:5432/table` | `sqlite:/path/to/config/db.sqlite3` | | `TABLE_TO_IMAGE` | Convert tables to image (causing higher CPU load) or just drop them? | `1` | `0` | | `MANAGER_PRIVILEGED` | Allow the bot manager to manipulate any users' subscriptions or not? [^8] | `1` | `0` | | `NO_UVLOOP` | Never enable `uvloop` (even if it is found) or not? | `1` | `0` | diff --git a/src/db/__init__.py b/src/db/__init__.py index af8068787e..254a55cf4d 100644 --- a/src/db/__init__.py +++ b/src/db/__init__.py @@ -88,7 +88,7 @@ async def __upgrade_migrations_in_db(): async def init(): global DB_TYPE try: - DB_TYPE = DBType(env.DATABASE_URL.partition('://')[0]) + DB_TYPE = DBType(env.DATABASE_URL.partition(':')[0]) except ValueError: logger.critical(f'INVALID DB SCHEME (EXPECTED: {", ".join(t.value for t in DBType)}): {env.DATABASE_URL}') exit(1) diff --git a/src/env.py b/src/env.py index cfb5c84942..257185b646 100644 --- a/src/env.py +++ b/src/env.py @@ -333,7 +333,7 @@ def __get_database_url() -> str: 'DATABASE_PUBLIC_URL', # Railway.app specific )))) if not urls: - return f'sqlite://{config_folder_path}/db.sqlite3' + return f'sqlite:{config_folder_path}/db.sqlite3' err: Optional[BaseException] = None for url in urls: try: