Files
Claude a18d45714e media-preload: on-demand VPS cache warm-up API and agent
OpenAPI 3.0 contract (api/openapi.yaml) with oapi-codegen generated server,
client and models; preload-api (Jellyfin lookup, SQLite queue, bearer roles)
runs at home, preload-agent runs on the VPS and fills the rclone cache.
mise manages Go 1.27.3 and oapi-codegen 2.8.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUebqghNwNssAZuWTxUq1y
2026-11-04 17:49:06 -07:00

269 lines
9.8 KiB
YAML

openapi: 3.0.3
info:
title: media-preload
version: 1.0.0
description: |
Warm the VPS media cache (webdav.godemperordoge.org) before someone watches something.
A client (for example the Discord bot) searches the Jellyfin library and files a request
("I will watch Dark Matter season 2"). The API resolves it to media files and queues them.
The preload agent on the VPS claims queued files and reads them through the local rclone
cache, so they stream from the VPS instead of over the home uplink.
Only Movies (including Arabic Shows) and the two TV libraries are cacheable; other files are
reported as `not_cacheable`.
Auth: `Authorization: Bearer <token>`. Client tokens may use the search and request endpoints;
agent tokens may only use `/v1/agent/*`.
servers:
- url: http://127.0.0.1:8125
description: on yveltal
- url: http://10.77.0.2:8125
description: from the VPS, over the wg-home tunnel
security:
- bearerAuth: []
tags:
- name: library
- name: requests
- name: agent
paths:
/v1/health:
get:
operationId: getHealth
summary: Liveness and version
security: []
responses:
"200":
description: OK
content:
application/json:
schema: { $ref: "#/components/schemas/Health" }
/v1/search:
get:
operationId: searchLibrary
tags: [library]
summary: Search movies and series in Jellyfin
parameters:
- { name: q, in: query, required: true, schema: { type: string, minLength: 2 }, description: Title to search for }
- { name: type, in: query, required: false, schema: { $ref: "#/components/schemas/MediaType" } }
- { name: limit, in: query, required: false, schema: { type: integer, minimum: 1, maximum: 25, default: 10 } }
responses:
"200":
description: Matches, best first
content:
application/json:
schema:
type: array
items: { $ref: "#/components/schemas/MediaItem" }
"400": { $ref: "#/components/responses/Problem" }
"401": { $ref: "#/components/responses/Problem" }
/v1/requests:
post:
operationId: createRequest
tags: [requests]
summary: Ask for a movie or episodes to be cached
description: |
For a movie, `season`, `episodes` and `next` are ignored.
For a series, give exactly one of:
- `season` (whole season), optionally with `episodes` (those episode numbers of that season);
- `next` (the next N unwatched episodes for `jellyfinUser`).
With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/CreateRequest" }
responses:
"201":
description: Queued (files already cached are marked `cached` right away by the agent)
content:
application/json:
schema: { $ref: "#/components/schemas/PreloadRequest" }
"400": { $ref: "#/components/responses/Problem" }
"401": { $ref: "#/components/responses/Problem" }
"404": { $ref: "#/components/responses/Problem" }
get:
operationId: listRequests
tags: [requests]
summary: Recent requests, newest first
parameters:
- { name: status, in: query, required: false, schema: { $ref: "#/components/schemas/RequestStatus" } }
- { name: limit, in: query, required: false, schema: { type: integer, minimum: 1, maximum: 100, default: 20 } }
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items: { $ref: "#/components/schemas/PreloadRequest" }
"401": { $ref: "#/components/responses/Problem" }
/v1/requests/{id}:
parameters:
- { name: id, in: path, required: true, schema: { type: integer, format: int64 } }
get:
operationId: getRequest
tags: [requests]
summary: One request with per-file progress
responses:
"200":
description: OK
content:
application/json:
schema: { $ref: "#/components/schemas/PreloadRequest" }
"401": { $ref: "#/components/responses/Problem" }
"404": { $ref: "#/components/responses/Problem" }
delete:
operationId: cancelRequest
tags: [requests]
summary: Cancel the files of a request that are still queued
responses:
"200":
description: Canceled (files already fetched stay cached)
content:
application/json:
schema: { $ref: "#/components/schemas/PreloadRequest" }
"401": { $ref: "#/components/responses/Problem" }
"404": { $ref: "#/components/responses/Problem" }
/v1/agent/claim:
post:
operationId: claimFile
tags: [agent]
summary: Agent takes the next queued file
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/ClaimRequest" }
responses:
"200":
description: A file to fetch
content:
application/json:
schema: { $ref: "#/components/schemas/AgentJob" }
"204":
description: Nothing queued
"401": { $ref: "#/components/responses/Problem" }
"403": { $ref: "#/components/responses/Problem" }
/v1/agent/files/{fileId}:
parameters:
- { name: fileId, in: path, required: true, schema: { type: integer, format: int64 } }
post:
operationId: reportFile
tags: [agent]
summary: Agent reports the result for a claimed file
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/FileReport" }
responses:
"204": { description: Recorded }
"401": { $ref: "#/components/responses/Problem" }
"403": { $ref: "#/components/responses/Problem" }
"404": { $ref: "#/components/responses/Problem" }
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
responses:
Problem:
description: Error
content:
application/json:
schema: { $ref: "#/components/schemas/Problem" }
schemas:
Problem:
type: object
required: [error]
properties:
error: { type: string, example: "series requests need jellyfinUser when using next" }
Health:
type: object
required: [status, version]
properties:
status: { type: string, example: ok }
version: { type: string }
MediaType:
type: string
enum: [movie, series]
MediaItem:
type: object
required: [id, name, type, cacheable]
properties:
id: { type: string, description: Jellyfin item id }
name: { type: string }
type: { $ref: "#/components/schemas/MediaType" }
year: { type: integer }
library: { type: string, description: "Jellyfin library path prefix, e.g. /media2/Videos/tvshows" }
seasonCount: { type: integer }
cacheable: { type: boolean, description: False when the item lives outside the cached folders }
CreateRequest:
type: object
required: [itemId, requestedBy]
properties:
itemId: { type: string, description: Jellyfin item id from /v1/search }
season: { type: integer, minimum: 0 }
episodes:
type: array
items: { type: integer, minimum: 0 }
description: Episode numbers within `season`
next: { type: integer, minimum: 1, maximum: 20, description: Next N unwatched episodes for jellyfinUser }
jellyfinUser: { type: string, description: Jellyfin user name whose watch progress decides "next" }
requestedBy: { type: string, maxLength: 100, description: Who asked, e.g. a Discord user name }
note: { type: string, maxLength: 500 }
RequestStatus:
type: string
enum: [queued, fetching, done, partial, failed, canceled]
FileStatus:
type: string
enum: [queued, fetching, cached, failed, canceled, not_cacheable]
PreloadFile:
type: object
required: [id, path, title, status, sizeBytes]
properties:
id: { type: integer, format: int64 }
path: { type: string, description: "Path as seen by Jellyfin and webdav, e.g. /media2/Videos/tvshows/..." }
title: { type: string, description: "e.g. Dark Matter S02E08" }
status: { $ref: "#/components/schemas/FileStatus" }
sizeBytes: { type: integer, format: int64 }
fetchedBytes: { type: integer, format: int64 }
error: { type: string }
updatedAt: { type: string, format: date-time }
PreloadRequest:
type: object
required: [id, itemId, title, requestedBy, status, createdAt, files]
properties:
id: { type: integer, format: int64 }
itemId: { type: string }
title: { type: string }
requestedBy: { type: string }
note: { type: string }
status: { $ref: "#/components/schemas/RequestStatus" }
createdAt: { type: string, format: date-time }
files:
type: array
items: { $ref: "#/components/schemas/PreloadFile" }
ClaimRequest:
type: object
required: [agentId]
properties:
agentId: { type: string, example: vps-dcruit2r }
AgentJob:
type: object
required: [fileId, path, sizeBytes]
properties:
fileId: { type: integer, format: int64 }
path: { type: string }
sizeBytes: { type: integer, format: int64 }
FileReport:
type: object
required: [result]
properties:
result:
type: string
enum: [cached, already_cached, failed]
bytes: { type: integer, format: int64, description: Bytes read from home for this file }
error: { type: string }