Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Go API checks
on:
push:
branches: [dev, companion-presence-api]
pull_request:
branches: [dev]
workflow_dispatch:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: typetype_test
ports: ['127.0.0.1:5432:5432']
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-timeout 5s --health-retries 10
redis:
image: redis:7-alpine
ports: ['127.0.0.1:6379:6379']
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s --health-timeout 5s --health-retries 10
env:
TEST_DATABASE_URL: postgres://postgres@127.0.0.1:5432/typetype_test?sslmode=disable
TEST_DRAGONFLY_URL: redis://127.0.0.1:6379
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.27.x'
cache: true
- name: Vet and race tests, including database migrations and permissions
run: |
go vet ./...
go test -race -count=1 ./...
- name: Static builds for amd64 and arm64
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /tmp/typetype-server-amd64 ./cmd/typetype-server
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /tmp/typetype-server-arm64 ./cmd/typetype-server
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ download execution in [TypeType-Downloader](https://github.com/TypeType-Video/Ty
The server answers the contract of [TypeType-Server](https://github.com/TypeType-Video/TypeType-Server); its OpenAPI
files are vendored under [`api/`](api/) and every route of the Kotlin server is in the router.

## Companion API

The Go `dev` branch includes read-only companion extensions for stable instance/account
identity, channel IDs/URLs, live status and playback speed. Saved watch history is
available only with an **explicit, separately revocable `history:read` grant**;
existing presence keys retain their original permissions. See
[authentication, migration, API examples and client follow-up](docs/companion-api.md).
The additions are documented in the vendored OpenAPI contract. Live playback must
still be reported by the player; reading a stream list is not proof of watching it.

## Development

Requirements:
Expand Down
5 changes: 5 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ paths:
/videos/titles: { $ref: ./openapi/paths/video-titles.yaml#/VideoTitles }
/presence/keys: { $ref: ./openapi/paths/presence.yaml#/PresenceKeys }
/presence/keys/{id}: { $ref: ./openapi/paths/presence.yaml#/PresenceKeyRoute }
/presence/identity: { $ref: ./openapi/paths/presence.yaml#/PresenceIdentity }
/presence/history: { $ref: ./openapi/paths/presence.yaml#/PresenceHistory }
/sessions/playback/start: { $ref: ./openapi/paths/session-playback.yaml#/PlaybackStart }
/sessions/playback/progress: { $ref: ./openapi/paths/session-playback.yaml#/PlaybackProgress }
/sessions/playback/stop: { $ref: ./openapi/paths/session-playback.yaml#/PlaybackStop }
/presence/now-playing: { $ref: ./openapi/paths/presence.yaml#/PresenceNowPlaying }
/backup/typetype: { $ref: ./openapi/paths/user-backup.yaml#/TypeTypeBackup }
/restore/typetype: { $ref: ./openapi/paths/user-backup.yaml#/TypeTypeRestore }
Expand Down
129 changes: 124 additions & 5 deletions api/openapi/paths/presence.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PresenceKeys:
post:
tags: [user-data]
summary: Create a presence-only access key
description: The returned token is displayed once and grants only the presence:read scope.
summary: Create a read-only companion access key
description: The token is displayed once. Omitted scopes grant only presence:read; history:read requires an explicit owner opt-in.
security: [{ bearerAuth: [] }]
requestBody:
required: true
Expand Down Expand Up @@ -35,6 +35,35 @@ PresenceKeys:
'403': { $ref: ../components/common.yaml#/JsonError }

PresenceKeyRoute:
put:
tags: [user-data]
summary: Explicitly grant or revoke history access for an owned key
description: Requires the owner's normal login token. A presence key cannot change its own grants. No new token is generated.
security: [{ bearerAuth: [] }]
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [scopes]
properties:
scopes: { $ref: '#/PresenceScopes' }
responses:
'200':
description: Updated key metadata, without token material.
content:
application/json:
schema: { $ref: '#/PresenceKey' }
'400': { $ref: ../components/common.yaml#/JsonError }
'401': { $ref: ../components/common.yaml#/JsonError }
'403': { $ref: ../components/common.yaml#/JsonError }
'404': { $ref: ../components/common.yaml#/JsonError }
delete:
tags: [user-data]
summary: Revoke a presence access key
Expand Down Expand Up @@ -69,6 +98,7 @@ PresenceKeyName:
required: [name]
properties:
name: { type: string, minLength: 1, maxLength: 50 }
scopes: { $ref: '#/PresenceScopes' }

PresenceKeyCreated:
type: object
Expand All @@ -79,12 +109,13 @@ PresenceKeyCreated:

PresenceKey:
type: object
required: [id, name, tokenPrefix, scope, createdAt]
required: [id, name, tokenPrefix, scope, scopes, createdAt]
properties:
id: { type: string, format: uuid }
name: { type: string }
tokenPrefix: { type: string }
scope: { type: string, enum: [presence:read] }
scope: { type: string, enum: [presence:read], description: Legacy base scope; use scopes for all grants. }
scopes: { $ref: '#/PresenceScopes' }
createdAt: { type: integer, format: int64 }
lastUsedAt: { type: integer, format: int64, nullable: true }

Expand All @@ -96,16 +127,104 @@ PresenceMedia:
title: { type: string }
thumbnail: { type: string, nullable: true }
channelName: { type: string, nullable: true }
channelUrl: { type: string, nullable: true, description: Canonical channel URL; queries and fragments are removed. }
channelId: { type: string, nullable: true, description: Provider-native ID when reported or obtainable from an unambiguous channel URL. Handles and Twitch logins are not treated as immutable IDs. }
isLive: { type: boolean, nullable: true, description: Client-reported live status; null means unknown. }
playbackSpeed: { type: number, nullable: true, minimum: 0, exclusiveMinimum: true, maximum: 16, description: Client-reported speed multiplier; null means unknown. }
positionMs: { type: integer, format: int64, minimum: 0 }
durationMs: { type: integer, format: int64, minimum: 0, nullable: true }
paused: { type: boolean }
updatedAt: { type: integer, format: int64 }

PresenceResponse:
type: object
required: [active, retryAfterMs, serverTimeMs]
required: [active, retryAfterMs, serverTimeMs, instanceId, accountId]
properties:
active: { type: boolean }
nowPlaying: { $ref: '#/PresenceMedia' }
retryAfterMs: { type: integer, format: int64, minimum: 0 }
serverTimeMs: { type: integer, format: int64 }
instanceId: { type: string, format: uuid, description: Persistent database identity, independent of hostnames and key rotation. }
accountId: { type: string, description: Exact user/profile ID owning the key. Compare together with instanceId. }

PresenceScopes:
type: array
minItems: 1
default: [presence:read]
description: Must contain presence:read; history:read is optional and grants access to all saved watch history for this account/profile.
items: { type: string, enum: ['presence:read', 'history:read'] }

PresenceIdentity:
get:
tags: [user-data]
summary: Identify the instance and account/profile owning a presence key
description: Requires presence:read. Does not expose names, email addresses or login credentials. All responses are no-store.
security: [{ bearerAuth: [] }]
responses:
'200':
description: Stable identity and the key's current grants.
content:
application/json:
schema:
type: object
required: [instanceId, accountId, scopes]
properties:
instanceId: { type: string, format: uuid }
accountId: { type: string }
scopes: { $ref: '#/PresenceScopes' }
'401': { $ref: ../components/common.yaml#/JsonError }

PresenceHistory:
get:
tags: [user-data]
summary: Read the saved watch history with an explicitly authorized presence key
description: >-
Requires history:read. Existing keys do not receive it automatically. Follow nextCursor
until null to read every stored record. Pages use watchedAt/id keyset ordering and keep
the first page's upper timestamp bound. Concurrent deletion and backdated imports are
not an immutable snapshot. The endpoint never fetches provider data or writes history.
All responses are no-store. History duration/progress are seconds; watchedAt is Unix milliseconds.
security: [{ bearerAuth: [] }]
parameters:
- name: limit
in: query
schema: { type: integer, minimum: 1, maximum: 1000, default: 100 }
- name: cursor
in: query
description: Opaque cursor from the preceding response, bound to this account/profile.
schema: { type: string, maxLength: 4096 }
responses:
'200':
description: A bounded page; empty history has items [] and nextCursor null.
content:
application/json:
schema:
type: object
required: [items, nextCursor, snapshotAt, instanceId, accountId]
properties:
items:
type: array
items: { $ref: '#/PresenceHistoryItem' }
nextCursor: { type: string, nullable: true }
snapshotAt: { type: integer, format: int64 }
instanceId: { type: string, format: uuid }
accountId: { type: string }
'400': { $ref: ../components/common.yaml#/JsonError }
'401': { $ref: ../components/common.yaml#/JsonError }
'403': { $ref: ../components/common.yaml#/JsonError }

PresenceHistoryItem:
type: object
required: [id, url, title, thumbnail, channelName, channelUrl, duration, progress, watchedAt]
properties:
id: { type: string }
url: { type: string }
title: { type: string }
thumbnail: { type: string }
channelName: { type: string }
channelUrl: { type: string }
channelId: { type: string, nullable: true }
channelAvatar: { type: string }
duration: { type: integer, format: int64, description: Seconds. }
progress: { type: integer, format: int64, description: Seconds; includes the greater saved progress position. }
watchedAt: { type: integer, format: int64, description: Unix milliseconds; not proof of completed viewing. }
85 changes: 85 additions & 0 deletions api/openapi/paths/session-playback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
PlaybackStart:
post:
tags: [playback]
summary: Report actual playback, including live content
description: >-
Uses the player's normal login token, never a presence key. Report actual
playback rather than stream extraction or browsing. This request alone does
not create a watch-history record. Presence requires an owned presence key;
admin session tracking can remain disabled. New metadata fields are optional.
security: [{ bearerAuth: [] }]
requestBody:
required: true
content:
application/json:
schema:
allOf:
- { $ref: '#/PlaybackRequest' }
- type: object
required: [videoUrl, title]
responses:
'204': { description: Playback accepted. }
'400': { $ref: ../components/common.yaml#/JsonError }
'401': { $ref: ../components/common.yaml#/JsonError }

PlaybackProgress:
post:
tags: [playback]
summary: Refresh the playing position, pause status and optional metadata
description: >-
Send at least every 15 to 30 seconds with the same clientName/deviceId.
Omitted channel, live and speed metadata is retained only for the same
device and video within the two-minute presence TTL. A different video
resets metadata. Omitted isLive/playbackSpeed starts as null (unknown),
not false/1. Playback positions and durations are milliseconds.
security: [{ bearerAuth: [] }]
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/PlaybackRequest' }
responses:
'204': { description: Playback accepted. }
'400': { $ref: ../components/common.yaml#/JsonError }
'401': { $ref: ../components/common.yaml#/JsonError }

PlaybackStop:
post:
tags: [playback]
summary: Clear the reporting device's playback
description: A stop from another device does not clear the current device's presence.
security: [{ bearerAuth: [] }]
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/DeviceRequest' }
responses:
'204': { description: Stop accepted. }
'401': { $ref: ../components/common.yaml#/JsonError }

DeviceRequest:
type: object
properties:
clientName: { type: string, nullable: true }
clientVersion: { type: string, nullable: true }
deviceId: { type: string, nullable: true }
deviceName: { type: string, nullable: true }
deviceType: { type: string, nullable: true }

PlaybackRequest:
allOf:
- { $ref: '#/DeviceRequest' }
- type: object
properties:
videoUrl: { type: string }
title: { type: string }
thumbnail: { type: string, nullable: true }
channelName: { type: string, nullable: true }
channelUrl: { type: string, nullable: true, maxLength: 2000, description: Absolute HTTP(S) URL without userinfo; query and fragment are discarded. }
channelId: { type: string, nullable: true, maxLength: 200, description: Provider-native ID if known; never substitute a display name. }
isLive: { type: boolean, nullable: true }
playbackSpeed: { type: number, nullable: true, minimum: 0, exclusiveMinimum: true, maximum: 16 }
positionMs: { type: integer, format: int64, minimum: 0, default: 0 }
durationMs: { type: integer, format: int64, nullable: true, minimum: 0 }
paused: { type: boolean, default: false }
Loading