docs(api): real progress endpoint contract; remove nonexistent-endpoint docs

The progress documentation described GET/POST /api/progress/:id —
endpoints that do not exist in the router — while the endpoint every
client actually uses (GET/PUT/DELETE /api/media-items/:id/progress) had
no field-level docs at all.

New:
- progress/position-contract.md: the canonical position model — server
  as position authority, the three-tier submission (percentage /
  context_text / epubcfi), ingest verification and healing, the restore
  handles, the OPF spine numbering hazard (canonical CFI spine steps
  include linear="no" items; clients resolve documents by anchor_href
  and land by css_selector + char_offset, never by spine step), the
  offset currencies (UTF-16 at the wire, runes internal), and
  context_text rules.
- progress/get_media_progress.md and update_media_progress.md: the real
  endpoints with full field tables, conditionality of the restore
  handles, the first-page anti-clobber guard, and healed-response
  semantics.
- progress/delete_media_progress.md: the real DELETE route.
- koreader/sync_progress.md and koreader/get_metadata.md rewritten to
  the actual payloads: the plugin sends a single-book array whose
  "epubcfi" field is a CRE xpointer; the metadata response navigates
  via koreader_xpointer (canonical CFI converted back to CRE), with
  page as the canonical locator for fixed-layout books.

Removed: the five files documenting the nonexistent /api/progress/:id
GET/POST/DELETE endpoints. Kept get_progress_history.md (that route
exists). The legacy developer/api-reference.md and the indexed
api/api-reference.md progress sections now match the wire and link the
new docs; the duplicate "Universal Progress" section points at Reading
Progress.
This commit is contained in:
John O'Keefe
2026-09-26 21:27:44 -04:00
parent 8c3273a0fc
commit b10bf3e8c7
13 changed files with 506 additions and 432 deletions
+40 -108
View File
@@ -394,6 +394,11 @@ Authorization: Bearer <token>
## Reading Progress
Full field reference: [api/progress/](api/progress/) — and read the
[Position Contract](api/progress/position-contract.md) (verification,
healing, the OPF spine numbering hazard, offset currencies) before
writing a client.
### Get Reading Progress
```http
@@ -405,57 +410,56 @@ Authorization: Bearer <token>
```json
{
"id": "uuid",
"media_item_id": "uuid",
"user_id": "uuid",
"current_page": 45,
"total_pages": 200,
"percentage": 0.225,
"character_offset": 15432,
"epubcfi": "epubcfi(/6/4/2:15)",
"chapter": 3,
"chapter_progress": 0.5,
"last_read_at": "2026-01-31T10:00:00Z",
"percentage": 0.045,
"epubcfi": "epubcfi(/6/4!/4/8[_idContainer003]/58/1:598)",
"context_text": "from day to day, but there was none in which ...",
"character_offset": 16375,
"current_page": null,
"total_pages": null,
"chapter": null,
"chapter_progress": null,
"format_group": "reflowable",
"viewport_y": 0.12,
"zoom_level": 1.0
"total_characters": 592216,
"chapter_count": 1,
"last_read_at": "2026-09-26T14:52:34Z",
"last_sync_source": "koreader",
"css_selector": "body>div:nth-child(4)>p:nth-child(29)",
"anchor_href": "1984.xhtml",
"char_offset": 598
}
```
`css_selector`, `anchor_href` and `char_offset` are server-derived
restore handles, served for convertible reflowable books with a
resolvable anchor. `char_offset` is UTF-16 code units within the anchor
block's text; `character_offset` is a book-wide rune count. Resolve the
document by `anchor_href`, never by the CFI's spine step (OPF numbering
includes `linear="no"` items).
### Update Reading Progress
```http
PUT /api/media-items/{media_id}/progress
Authorization: Bearer <token>
Content-Type: application/json
{
"source": "web",
"location": {
"percentage": 0.45678,
"epubcfi": "epubcfi(/6/4/2:15)",
"character": 15432,
"chapter": 3,
"page": 89,
"total_pages": 200
},
"device_metadata": {
"device_type": "web",
"user_agent": "Mozilla/5.0..."
}
}
```
**Response** (200):
```json
{
"sync_status": "success",
"progress_updated": true,
"devices_notified": ["device-1", "device-2"],
"broadcast": true
"percentage": 0.0415,
"context_text": "was at war with one of these Powers it was generally a",
"epubcfi": "epubcfi(/6/4!/4/8[_idContainer003]/62/1:456)"
}
```
All fields are optional. The server verifies the submission against the
book and heals it on mismatch; the response is the stored row after
verification. A `percentage` below 0.005 is ignored while stored
progress exceeds 0.01 (first-page anti-clobber).
### Delete Reading Progress
```http
@@ -1297,82 +1301,10 @@ Authorization: Bearer <device_token>
## Universal Progress
### Get Universal Progress
```http
GET /api/progress/{book_uuid}
Authorization: Bearer <token>
```
**Response** (200):
```json
{
"book_id": "book-uuid",
"format_group": "reflowable",
"universal_progress": 0.45678,
"location_references": {
"percentage": 0.45678,
"epubcfi": "epubcfi(/6/4/2:15)",
"character": 15432,
"chapter": 3,
"chapter_progress": 0.234,
"viewport_y": 0.12
},
"device_progress": {
"koreader": {
"percentage": 0.45678,
"last_sync": "2026-01-30T20:00:00Z"
},
"kobo": {
"percentage": 45.6,
"last_sync": "2026-01-30T19:55:00Z"
},
"web": {
"display_page": 89,
"total_pages": 200,
"last_sync": "2026-01-30T20:05:00Z"
}
},
"annotations": {
"highlights": [...],
"notes": [...],
"bookmarks": [...]
},
"conflicts": [
{
"id": "conflict-uuid",
"type": "progress",
"resolved": false,
"sources": ["koreader", "kobo"]
}
]
}
```
### Update Universal Progress
```http
POST /api/progress/{book_uuid}
Authorization: Bearer <token>
Content-Type: application/json
{
"source": "web|koreader|kobo|mobile",
"location": {
"percentage": 0.45678,
"epubcfi": "epubcfi(/6/4/2:15)",
"character": 15432,
"chapter": 3,
"page": 89,
"total_pages": 200
},
"device_metadata": {
"device_type": "web",
"user_agent": "..."
}
}
```
Universal progress is the media-item progress — one row per (user,
media item) shared by every device. See [Reading Progress](#reading-progress)
and the [Position Contract](api/progress/position-contract.md). There
are no separate `/api/progress/:id` GET/POST endpoints.
## Conflicts