funread-api 1.2.6__tar.gz → 1.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {funread_api-1.2.6 → funread_api-1.2.7}/PKG-INFO +3 -2
  2. {funread_api-1.2.6 → funread_api-1.2.7}/pyproject.toml +3 -2
  3. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/accounts.py +1 -3
  4. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/reader.py +19 -14
  5. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_reader_api.py +33 -2
  6. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_rss_api.py +1 -1
  7. {funread_api-1.2.6 → funread_api-1.2.7}/.github/workflows/ci.yml +0 -0
  8. {funread_api-1.2.6 → funread_api-1.2.7}/.gitignore +0 -0
  9. {funread_api-1.2.6 → funread_api-1.2.7}/LICENSE +0 -0
  10. {funread_api-1.2.6 → funread_api-1.2.7}/README.md +0 -0
  11. {funread_api-1.2.6 → funread_api-1.2.7}/scripts/build-binary.sh +0 -0
  12. {funread_api-1.2.6 → funread_api-1.2.7}/scripts/export_openapi.py +0 -0
  13. {funread_api-1.2.6 → funread_api-1.2.7}/scripts/setup.sh +0 -0
  14. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/__init__.py +0 -0
  15. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/app.py +0 -0
  16. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/cli.py +0 -0
  17. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/paths.py +0 -0
  18. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/security.py +0 -0
  19. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/__init__.py +0 -0
  20. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/auth.py +0 -0
  21. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/deps.py +0 -0
  22. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/pool.py +0 -0
  23. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/rss.py +0 -0
  24. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/shelf.py +0 -0
  25. {funread_api-1.2.6 → funread_api-1.2.7}/src/funread_api/v1/sources.py +0 -0
  26. {funread_api-1.2.6 → funread_api-1.2.7}/tests/accounts_support.py +0 -0
  27. {funread_api-1.2.6 → funread_api-1.2.7}/tests/conftest.py +0 -0
  28. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_accounts.py +0 -0
  29. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_api.py +0 -0
  30. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_auth.py +0 -0
  31. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_cli.py +0 -0
  32. {funread_api-1.2.6 → funread_api-1.2.7}/tests/test_paths.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: funread-api
3
- Version: 1.2.6
3
+ Version: 1.2.7
4
4
  Summary: funread 采集源管理后端服务
5
5
  Project-URL: Organization, https://github.com/farfarfun
6
6
  Project-URL: Repository, https://github.com/farfarfun/funread-api
@@ -12,9 +12,10 @@ License-File: LICENSE
12
12
  Requires-Python: >=3.12
13
13
  Requires-Dist: aiomysql>=0.2.0
14
14
  Requires-Dist: aiosqlite>=0.20.0
15
+ Requires-Dist: asyncpg>=0.30.0
15
16
  Requires-Dist: fastapi>=0.110.0
16
17
  Requires-Dist: funauth[fastapi]>=0.2.3
17
- Requires-Dist: funread[js,reader]>=1.2.5
18
+ Requires-Dist: funread[js,reader]>=1.2.6
18
19
  Requires-Dist: itsdangerous>=2.1.0
19
20
  Requires-Dist: pydantic>=2.0.0
20
21
  Requires-Dist: requests>=2.28.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "funread-api"
3
- version = "1.2.6"
3
+ version = "1.2.7"
4
4
  description = "funread 采集源管理后端服务"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -8,7 +8,7 @@ dependencies = [
8
8
  # [reader] pulls in lxml/cssselect/jsonpath-ng — the rule engine needs them,
9
9
  # the collection pipeline does not.
10
10
  # 阅读源规则入库与扫描接口从 1.2.5 开始提供。
11
- "funread[reader,js]>=1.2.5",
11
+ "funread[reader,js]>=1.2.6",
12
12
  "fastapi>=0.110.0",
13
13
  "uvicorn[standard]>=0.27.0",
14
14
  "pydantic>=2.0.0",
@@ -22,6 +22,7 @@ dependencies = [
22
22
  # async 引擎,阅读层继续走 funread 的同步引擎,同一个库两个连接。
23
23
  "aiosqlite>=0.20.0",
24
24
  "aiomysql>=0.2.0",
25
+ "asyncpg>=0.30.0",
25
26
  # Starlette 的 SessionMiddleware 签 cookie 用它,不是 starlette 的硬依赖。
26
27
  "itsdangerous>=2.1.0",
27
28
  # 命令行入口(src/funread_api/cli.py)用的框架。funread 那边也会间接带进来,
@@ -162,9 +162,7 @@ class ReaderUserOut(BaseModel):
162
162
  # --------------------------------------------------------------- 异步引擎
163
163
 
164
164
  #: 异步驱动映射。键是同步 URL 的 drivername,值是对应的异步 drivername。
165
- #: `asyncpg` 不是本服务的硬依赖(它要编译扩展,而本地开发只用 SQLite、线上是
166
- #: MySQL),所以 PostgreSQL 这条映射写在这里但驱动要自己装 —— 装之前 URL
167
- #: 翻译照样正确,只是建引擎时 SQLAlchemy 会抛「找不到 asyncpg」。
165
+ #: PostgreSQL 账号连接使用 asyncpg,安装包必须声明该驱动。
168
166
  _ASYNC_DRIVERS = {
169
167
  "sqlite": "sqlite+aiosqlite",
170
168
  "sqlite+pysqlite": "sqlite+aiosqlite",
@@ -398,28 +398,24 @@ def scan(
398
398
  session.execute(
399
399
  select(SourceListRecord).where(
400
400
  SourceListRecord.source_type == source_type,
401
- SourceListRecord.enabled.is_(True),
401
+ SourceListRecord.increment_start.is_(None),
402
+ SourceListRecord.increment_stop.is_(None),
402
403
  )
403
404
  )
404
405
  .scalars()
405
406
  .all()
406
407
  )
407
- if not records:
408
- records = [
409
- add_source_list_url(url=url, source_type=source_type)
410
- for url in DEFAULT_SOURCE_LISTS[source_type]
411
- ]
408
+ existing = {record.url: record for record in records}
409
+ registered = {url: record for url, record in existing.items() if record.enabled}
410
+ for url in DEFAULT_SOURCE_LISTS[source_type]:
411
+ if url not in existing:
412
+ registered[url] = add_source_list_url(url=url, source_type=source_type)
412
413
  errors = []
413
- for record in records:
414
+ fetched = []
415
+ for record in registered.values():
414
416
  try:
415
417
  payloads = fetch_source_list_data(record)
416
- registry.ingest(payloads)
417
- upsert_source_list_record(
418
- url=record.url,
419
- source_type=source_type,
420
- source_count=count_source_payloads(payloads),
421
- fetch_succeeded=True,
422
- )
418
+ fetched.append((record, payloads))
423
419
  except Exception as exc:
424
420
  logger.warning(f"Failed to import {record.url}: {exc}")
425
421
  errors.append(str(exc))
@@ -430,6 +426,15 @@ def scan(
430
426
  fetch_succeeded=False,
431
427
  error=str(exc),
432
428
  )
429
+ if fetched:
430
+ registry.ingest([payload for _, payloads in fetched for payload in payloads])
431
+ for record, payloads in fetched:
432
+ upsert_source_list_record(
433
+ url=record.url,
434
+ source_type=source_type,
435
+ source_count=count_source_payloads(payloads),
436
+ fetch_succeeded=True,
437
+ )
433
438
  report = registry.scan()
434
439
  if report["scanned"] == 0:
435
440
  raise HTTPException(
@@ -7,6 +7,7 @@ from fastapi.testclient import TestClient
7
7
 
8
8
  from funread.base import config
9
9
  from funread.legado.engine import StaticFetcher
10
+ from funread.legado.manage.source.storage import add_source_list_url
10
11
  from funread.legado.reader import get_cached_chapter, save_cached_chapter
11
12
  from funread_api.app import create_app
12
13
  from funread_api.v1.deps import get_reader_service, reset_reader_services
@@ -58,7 +59,7 @@ def client(tmp_path):
58
59
  with TestClient(create_app()) as test_client:
59
60
  service = get_reader_service()
60
61
  service.fetcher_factory = lambda timeout=None: StaticFetcher(PAGES)
61
- service.registry.scan()
62
+ service.registry.import_archive()
62
63
  test_client.service = service
63
64
  yield test_client
64
65
  reset_reader_services()
@@ -129,6 +130,36 @@ def test_scan_reports_list_download_failure(client, monkeypatch):
129
130
  assert "download failed" in response.json()["detail"]
130
131
 
131
132
 
133
+ def test_scan_skips_incremental_lists_when_bootstrapping(client, monkeypatch):
134
+ add_source_list_url(
135
+ url="https://example.com/rss/{id}.json",
136
+ source_type="rss",
137
+ increment_start=0,
138
+ increment_stop=1000,
139
+ )
140
+ fetched = []
141
+
142
+ def fetch(record):
143
+ fetched.append(record.url)
144
+ return [
145
+ [
146
+ {
147
+ "sourceUrl": "https://feed.example.com",
148
+ "sourceName": "测试订阅源",
149
+ "ruleArticles": "class.item",
150
+ "ruleTitle": "tag.h2@text",
151
+ }
152
+ ]
153
+ ]
154
+
155
+ monkeypatch.setattr("funread_api.v1.reader.fetch_source_list_data", fetch)
156
+ report = client.post("/api/v1/reader/scan", params={"source_type": "rss"}).json()
157
+
158
+ assert report["scanned"] == 1
159
+ assert fetched
160
+ assert all("{id}" not in url for url in fetched)
161
+
162
+
132
163
  def test_scan_rejects_an_unknown_source_type(client):
133
164
  assert client.post("/api/v1/reader/scan", params={"source_type": "video"}).status_code == 422
134
165
 
@@ -767,7 +798,7 @@ def explore_client(tmp_path):
767
798
  with TestClient(create_app()) as test_client:
768
799
  service = get_reader_service()
769
800
  service.fetcher_factory = lambda timeout=None: StaticFetcher(EXPLORE_PAGES)
770
- service.registry.scan()
801
+ service.registry.import_archive()
771
802
  yield test_client
772
803
  reset_reader_services()
773
804
 
@@ -76,7 +76,7 @@ def client(tmp_path):
76
76
  with TestClient(create_app()) as test_client:
77
77
  service = get_rss_service()
78
78
  service.fetcher_factory = lambda timeout=None: StaticFetcher(dict(PAGES))
79
- # The pool starts empty, same as a real install before the first scan.
79
+ service.registry.import_archive()
80
80
  test_client.post("/api/v1/reader/scan", params={"source_type": "rss"})
81
81
  yield test_client
82
82
  reset_reader_services()
File without changes
File without changes
File without changes