openapi: 3.0.3
info:
  title: RVRB API
  version: 2.13.0
  description: |
    The HTTP routes of the RVRB server. Live channel traffic (joining, chat, votes, DJ commands, moderation) goes over the websocket instead (described in doc/asyncapi.yaml in the server's repository).

    **Rate limit.** A caller (its login or bot key, or its address when it has none) may make 600 requests a minute to the api. Over that, the answer is `429` with `Retry-After` (the seconds to wait). Every answer says where the caller is, in `x-ratelimit-limit`, `x-ratelimit-remaining` and `x-ratelimit-reset`. `/api/stream`, `/api/ping` and `/api/health` are not counted. The count is kept by each api process, so with several instances the limit is for each.

    **Following the state of the public channels without polling.** Listen to `/api/stream` for `track-finished` and `stats-changed`. The `/api/statistics/*` answers carry an `ETag`: ask again with `If-None-Match` and an answer that has not changed is a `304` with no body. `/api/statistics/batch` gives a board for up to 50 channels in one request.
servers:
  - url: /
tags:
  - name: Channels
  - name: Events
    description: A channel's events. Admins and owners make them, with days, a start and an end for each, and a slot length; anyone in the channel can sign up for a slot. An event has a url id of its own (a slug and a random suffix) to share.
  - name: Bot
    description: Routes a channel's external bot can call with its API key (`botApiKey`), for its own channel only. A bot is refused (403) in any other channel. The same routes can still be called by people with a JWT.
  - name: Music
  - name: Stacks
  - name: Users
  - name: Account
  - name: Notifications
  - name: Achievements
  - name: Admin
  - name: Statistics
  - name: System
  - name: 'Role: Public'
    description: Needs no credentials.
  - name: 'Role: User'
    description: Any signed-in user (a JWT). Some of these routes also limit the caller to their own data.
  - name: 'Role: Channel mod'
    description: A moderator or above in the channel named in the URL (role 3 or higher).
  - name: 'Role: Channel admin'
    description: An admin or above in the channel named in the URL (role 5 or higher).
  - name: 'Role: Channel creator'
    description: A creator of the channel named in the URL (role 10).
  - name: 'Role: Site admin'
    description: A user flagged as a site administrator.
  - name: 'Role: Bot only'
    description: An external bot, with its API key.
paths:
  /api/account:
    delete:
      tags:
        - Account
        - 'Role: User'
      summary: Delete your account
      description: Deletes custom images and anonymises the user in the background (userName and email replaced, settings removed, websocket connections closed). The reply does not wait for that.
      operationId: deleteAccount
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Accepted
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: object
                    description: The decoded JWT of the caller
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersError'
  /api/achievements/badges:
    get:
      tags:
        - Achievements
        - 'Role: User'
      summary: List badge holders
      operationId: listBadgeHolders
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Users that hold a badge
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    userId:
                      type: string
                    displayName:
                      type: string
                    badgeHeld:
                      type: string
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /api/achievements:
    get:
      tags:
        - Achievements
        - 'Role: User'
      summary: List every achievement and its levels
      operationId: listAchievements
      security:
        - bearerAuth: []
      responses:
        '200':
          description: The achievements, each with its levels in order of goal
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    name:
                      type: string
                    description:
                      type: string
                      description: What the achievement counts
                    levels:
                      type: array
                      items:
                        type: object
                        properties:
                          title:
                            type: string
                          description:
                            type: string
                          icon:
                            type: string
                          goal:
                            type: integer
                          tier:
                            type: integer
                            description: Which of the 4 badge images (1 to 4)
                    crown:
                      type: object
                      nullable: true
                      description: The 5th tier, worn by the one who has the most of it. Null when the achievement has none
                      properties:
                        title:
                          type: string
                        description:
                          type: string
                        tier:
                          type: integer
                          description: Always 5
                    holder:
                      type: object
                      nullable: true
                      description: Who wears the crown now, and the progress that won it. Null when no one has reached the last level
                      properties:
                        userId:
                          type: string
                        progress:
                          type: integer
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /api/admin:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Channel and user totals
      description: Site admin only. A non-admin (or unknown) caller gets 404 Not Found as plain text.
      operationId: adminOverview
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Counts from the in-memory channel state
          content:
            application/json:
              schema:
                type: object
                properties:
                  channels:
                    type: object
                    properties:
                      total:
                        type: integer
                      active:
                        type: integer
                        description: Channels with at least one user
                  users:
                    type: object
                    properties:
                      total:
                        type: integer
                      djs:
                        type: integer
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/channels:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: List active channels with connections
      description: Site admin only. Channels that have users, with their djs and users as websocket connection summaries.
      operationId: adminListChannels
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Active channels
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    _id:
                      type: string
                    channelName:
                      type: string
                    nextSong:
                      type: object
                      nullable: true
                      description: Next song in the channel state
                    djs:
                      type: array
                      items:
                        $ref: '#/components/schemas/UsersAdminConnection'
                    users:
                      type: array
                      items:
                        $ref: '#/components/schemas/UsersAdminConnection'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/channels/{channelId}:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Inspect one channel
      description: Site admin only. Reads the in-memory channel state; an unknown channelId makes the handler throw (500).
      operationId: adminGetChannel
      security:
        - bearerAuth: []
      parameters:
        - name: channelId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Channel state summary
          content:
            application/json:
              schema:
                type: object
                properties:
                  channelName:
                    type: string
                  nextSong:
                    type: object
                    nullable: true
                  djs:
                    type: array
                    items:
                      $ref: '#/components/schemas/UsersAdminConnection'
                  users:
                    type: array
                    items:
                      $ref: '#/components/schemas/UsersAdminConnection'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
        '500':
          $ref: '#/components/responses/UsersFastifyError'
  /api/admin/heapdump:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Write a heap snapshot
      description: Site admin only. Writes a V8 heap snapshot file to the server's working directory.
      operationId: adminHeapdump
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Snapshot started
          content:
            text/plain:
              schema:
                type: string
                example: OK...
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/logs/messages:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Chat log with sender profiles
      description: Site admin only. Every ChatLog document joined with a reduced userProfile.
      operationId: adminChatLog
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Chat log entries
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  additionalProperties: true
                  description: ChatLog document
                  properties:
                    userProfile:
                      type: object
                      properties:
                        _id:
                          type: string
                        userName:
                          type: string
                        displayName:
                          type: string
                        image:
                          type: string
                        lastTouched:
                          type: string
                          format: date-time
                        lastAuthenticated:
                          type: string
                          format: date-time
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/messages:
    post:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Broadcast an alert
      description: Site admin only. Sends the message as an alert chat message to every user in every channel. A missing or empty `message` answers 400 and sends nothing.
      operationId: adminBroadcastMessage
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - message
              properties:
                message:
                  type: string
      responses:
        '200':
          description: 'Summary string, "Sent to N users: message"'
          content:
            text/plain:
              schema:
                type: string
        '400':
          $ref: '#/components/responses/UsersFastifyError'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/signup:
    post:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: Generate a signup confirmation link
      description: Site admin only. Looks up the user by email and returns a /api/signup/confirm link containing a signed state token. An unknown email makes the handler throw (500).
      operationId: adminSignupLink
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - email
              properties:
                email:
                  type: string
      responses:
        '200':
          description: The confirmation URL
          content:
            text/plain:
              schema:
                type: string
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
        '500':
          $ref: '#/components/responses/UsersFastifyError'
  /api/admin/users:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: List all websocket connections
      description: Site admin only.
      operationId: adminListUsers
      security:
        - bearerAuth: []
      responses:
        '200':
          description: One entry per open websocket connection
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/UsersAdminConnection'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
  /api/admin/websockets/{userId}:
    get:
      tags:
        - Admin
        - 'Role: Site admin'
      summary: List a user's websocket connections
      description: Site admin only. Lists the open websocket connections of the user.
      operationId: adminUserWebsockets
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Connections of that user
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/UsersAdminConnection'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersAdminNotFound'
        '500':
          $ref: '#/components/responses/UsersFastifyError'
  /api/channel:
    post:
      tags:
        - Channels
        - 'Role: User'
      summary: Create a channel
      description: The caller becomes the channel's creator. Needs a string `title` or `slug`; the rest of the body is validated by validateChannel. The channel is added to the websocket server. Starred, boofstar and "this is" playlists are created when the matching write* settings are on.
      operationId: createChannel
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChannelCreateRequest'
      responses:
        '200':
          description: Channel created
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      channel:
                        $ref: '#/components/schemas/Channel'
        '400':
          description: Missing title, invalid channel settings or handle already taken
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '500':
          description: Failed to create the channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}:
    get:
      tags:
        - Channels
        - Bot
        - 'Role: User'
      summary: Get a channel
      description: Fails with 404 when the channel does not exist or the caller is banned from it. The `djs` array is filled from live channel state. Callers with role 5 or higher (channel admin or creator) also get `bannedUsers`. A bot sees what a user with no role sees.
      operationId: getChannel
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: The channel
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Channel'
                  - type: object
                    properties:
                      djs:
                        type: array
                        items:
                          type: string
                        description: User ids of the current DJs
                      bannedUsers:
                        type: array
                        description: Only sent to channel admins
                        items:
                          $ref: '#/components/schemas/User'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
    put:
      tags:
        - Channels
        - Bot
        - 'Role: Channel admin'
      summary: Edit a channel
      description: Channel admins (role 5 or higher) of that channel, or the channel's external bot. A bot is refused (403) when the body has any of `slug`, `visibility`, `password`, `banned`, `maxDjs`, `lastfm` or `discord`; nothing is changed. Validates the fields and the handle, updates the channel, its playlists and bot, removes surplus DJs when the DJ limit was lowered, and broadcasts `updateChannel` to the room. The channel has to be loaded (404 otherwise). The body is what the channel form sends, including a `bot` object (a body without one answers 500).
      operationId: editChannel
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChannelCreateRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    properties:
                      syncTime:
                        type: integer
                        description: Milliseconds since the epoch
                      channel:
                        $ref: '#/components/schemas/Channel'
                      bot:
                        $ref: '#/components/schemas/BotConfig'
        '400':
          description: Invalid fields, or the handle is taken
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '404':
          description: The channel is not loaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Channels
        - 'Role: Channel creator'
      summary: Delete a channel
      description: Needs role 10 (the creator) in that channel, checked on the channel in the URL. Makes the channel unjoinable and frees its handle, tells everyone in the room to leave, and unloads it after three seconds. A failure before that puts the channel back.
      operationId: deleteChannel
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: 'Not Authorized: the caller is not the creator of this channel'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The channel is not loaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: The channel could not be updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/bot:
    get:
      tags:
        - Channels
        - 'Role: User'
      summary: Get the channel bot configuration
      description: Only for users currently joined to the channel. Returns an empty object when the channel has no bot record.
      operationId: getChannelBot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: The bot record
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BotConfig'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
  /api/channel/{channelId}/lastfm/connect:
    post:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Start connecting the channel to Last.fm
      description: "Channel admins only. The first of two steps that connect the channel to the admin's Last.fm account by their approving the app on Last.fm, so the channel never holds their password. Asks Last.fm for a token, and answers it with the address to send the admin to. Once they have approved the app there, `POST /api/channel/{channelId}/lastfm/session` turns the token into the channel's login. Nothing is stored by this step. The key and secret are those in the body, or else those the channel has stored (the secret is never sent to a browser, so a form leaves it out unless it was typed again)."
      operationId: startChannelLastfmConnect
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                api_key:
                  type: string
                  description: The key of the Last.fm API application. Default is the one the channel has stored.
                api_secret:
                  type: string
                  description: Its secret. Default is the one the channel has stored.
      responses:
        '200':
          description: The token and where to approve it
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
                    description: Works once, for an hour.
                  url:
                    type: string
                    description: The Last.fm page where the admin approves the app.
        '400':
          description: There is no key and secret, or Last.fm refused them (the reason is in `error`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '502':
          description: Last.fm could not be reached
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/lastfm/session:
    post:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Finish connecting the channel to Last.fm
      description: "Channel admins only. The second step: the admin has approved the app on Last.fm, so the token from `POST /api/channel/{channelId}/lastfm/connect` is turned into a session for their account. That session is the channel's Last.fm login from then on, replacing any login with a password; the channel starts scrobbling as that user, and `updateChannel` is broadcast. The session key is never sent back to a browser."
      operationId: finishChannelLastfmConnect
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - token
              properties:
                token:
                  type: string
                api_key:
                  type: string
                  description: The same key the token was asked for with. Default is the one the channel has stored.
                api_secret:
                  type: string
                  description: Its secret. Default is the one the channel has stored.
      responses:
        '200':
          description: Connected
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      lastfm:
                        $ref: '#/components/schemas/ChannelLastfm'
        '400':
          description: There is no token, or Last.fm refused it, for example because the admin has not approved the app yet (the reason is in `error`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '502':
          description: Last.fm could not be reached
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/discord/link:
    post:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Start linking the channel to a Discord channel from Discord
      description: "Channel admins only. Answers a code that works once, for ten minutes. Someone who has the Manage Server permission in the Discord server runs `/rvrb-link code:<code>` in the Discord channel to link, and the channel's `discord` settings are set to that server and channel (keeping the mode, two way by default); `updateChannel` is broadcast. Unlike typing the ids into the settings, this proves the admin controls the Discord server. A new code for the channel replaces the last."
      operationId: startChannelDiscordLink
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: The code
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Six letters and digits.
                  expiresAt:
                    type: string
                    format: date-time
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '409':
          description: The channel is not running
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: The Discord bot is not running on this server (the reason is in `error`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/bot/aliases:
    get:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: List the aliases of the channel
      description: Channel admins only. The aliases belong to the bot, which keeps them and holds them to the rules the alias commands have, so the request is passed on over Redis and the bot is given 5 seconds. The same name can have several entries (one response is picked at random when it is used), so there is one item for each entry, sorted by name.
      operationId: listChannelAliases
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: The aliases
          content:
            application/json:
              schema:
                type: object
                properties:
                  aliases:
                    type: array
                    items:
                      $ref: '#/components/schemas/ChannelAlias'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '503':
          description: The bot did not answer within 5 seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Add an alias
      description: Channel admins only. The aliases belong to the bot, which keeps them and holds them to the rules the alias commands have, so the request is passed on over Redis and the bot is given 5 seconds. The name is kept in lower case without a leading `/` or `!`, and cannot have spaces or be the name of a command.
      operationId: createChannelAlias
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - value
              properties:
                name:
                  type: string
                  maxLength: 50
                value:
                  type: string
                  description: What the bot says when the alias is used (at most CHAT_MAX_LENGTH characters)
      responses:
        '200':
          description: The alias that was added
          content:
            application/json:
              schema:
                type: object
                properties:
                  alias:
                    $ref: '#/components/schemas/ChannelAlias'
        '400':
          description: The bot refused the request (for example the name is a command, has spaces, or the response is empty or too long)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The name already has that response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '503':
          description: The bot did not answer within 5 seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/bot/aliases/{aliasId}:
    put:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Change an alias
      description: Channel admins only. The aliases belong to the bot, which keeps them and holds them to the rules the alias commands have, so the request is passed on over Redis and the bot is given 5 seconds. Only what is sent changes. The same rules apply as when adding.
      operationId: updateChannelAlias
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - $ref: '#/components/parameters/AliasId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  maxLength: 50
                value:
                  type: string
      responses:
        '200':
          description: The alias as it is now
          content:
            application/json:
              schema:
                type: object
                properties:
                  alias:
                    $ref: '#/components/schemas/ChannelAlias'
        '400':
          description: The bot refused the request (for example the name is a command, has spaces, or the response is empty or too long)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The alias is not in this channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The name already has that response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '503':
          description: The bot did not answer within 5 seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Delete an alias
      description: Channel admins only. The aliases belong to the bot, which keeps them and holds them to the rules the alias commands have, so the request is passed on over Redis and the bot is given 5 seconds. Removes this entry only; other entries with the same name stay.
      operationId: deleteChannelAlias
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - $ref: '#/components/parameters/AliasId'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
        '404':
          description: The alias is not in this channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '503':
          description: The bot did not answer within 5 seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/bot/images:
    put:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Upload a bot image
      description: Channel admins only. Stores the image (max 10 MB; jpeg, png, gif or webp) as a 256 by 256 square webp, cut to the part named by the crop fields (the centre without them; a gif stays a moving image), and saves its path on the channel's bot record, deleting the previous file for that type.
      operationId: putChannelBotImage
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ChannelImageUpload'
      responses:
        '200':
          description: The stored image path, keyed by the image type
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChannelImageResult'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '500':
          $ref: '#/components/responses/ChannelServerError'
  /api/channel/{channelId}/promo-image:
    put:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Upload the banner of the channel
      description: Channel admins only. Stores the image (max 10 MB; jpeg, png, gif or webp) as a 900 by 600 webp, the ratio of 3 to 2, and sets it as the channel's `promoImageUrl`, which the room is told. The part of the picture to keep is given as `cropX`, `cropY`, `cropWidth` and `cropHeight` in the picture's own pixels, and the centre is kept without them. A gif stays a moving image. A banner that was uploaded before is deleted.
      operationId: putChannelPromoImage
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - image
              properties:
                image:
                  type: string
                  format: binary
                cropX:
                  type: number
                  description: Left edge of the part to keep
                cropY:
                  type: number
                  description: Top edge of the part to keep
                cropWidth:
                  type: number
                cropHeight:
                  type: number
      responses:
        '200':
          description: The banner is saved
          content:
            application/json:
              schema:
                type: object
                properties:
                  promoImageUrl:
                    type: string
                    description: The path of the stored image, such as /static/abc_1700000000000_promo.webp
        '400':
          description: There is no image, or it is not a type the app takes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '500':
          $ref: '#/components/responses/ChannelServerError'
  /api/channel/{channelId}/bot/options:
    get:
      tags:
        - Channels
        - 'Role: User'
      summary: List bot commands and personalities
      description: Core commands enabled for the channel, plus the external bot's commands when `enabled` is true. Commands are sorted by name. When the bot is enabled the reply says in `botAnswered` whether the bot process answered (it is asked over Redis and given 5 seconds). When it did not, only the core commands are listed, and `personalities` is empty.
      operationId: getChannelBotOptions
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: enabled
          in: query
          required: false
          description: Whether the bot is enabled (`true`, case-insensitive)
          schema:
            type: string
        - name: personality
          in: query
          required: false
          schema:
            type: string
      responses:
        '200':
          description: Bot options
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChannelBotOptions'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
  /api/channel/{channelId}/chat:
    get:
      tags:
        - Channels
        - Bot
        - 'Role: User'
      summary: Get recent chat messages
      description: Only for users currently joined to the channel (a bot need not have joined). Returns the latest messages (CHAT_BUFFER, default 100) of the current chat version, without deleted ones.
      operationId: getChannelChat
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Recent chat
          content:
            application/json:
              schema:
                type: object
                properties:
                  chat:
                    type: array
                    items:
                      $ref: '#/components/schemas/ChatMessage'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
    delete:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Clear the chat
      description: Moderators and above. Archives the live chat (it is kept under a timestamp version), tells the room to clear, and posts "Channel Chat Cleared" about 200 ms later.
      operationId: clearChat
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/chat/{version}:
    delete:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Mark a chat version as deleted
      description: Moderators and above, checked on the channel in the URL. Sets `deleted` on the matching ChannelChats document; the document is kept. (It used to check a role the token does not carry, so any logged-in user could do this.)
      operationId: deleteChannelChatVersion
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: version
          in: path
          required: true
          description: Chat document version
          schema:
            type: integer
      responses:
        '200':
          description: Marked as deleted (also sent when nothing matched)
          content:
            text/plain:
              schema:
                type: string
                example: OK
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
  /api/channel/{channelId}/chat/history:
    get:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Get all chat documents of a channel
      description: Moderators (role 3) and above of that channel only. Returns every ChannelChats document of the channel (all versions, including deleted ones).
      operationId: getChannelChatHistory
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Chat documents
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ChannelChatDocument'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator of the channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/external-bot:
    get:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: List external bots
      description: Channel admins only. Returns the bot users of the channel, including their apiKey, which the channel admin needs to connect the bot.
      operationId: listChannelExternalBots
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Bot users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ChannelExternalBot'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
    post:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Create an external bot
      description: Channel admins only. Creates a bot user with a generated API key. Fails with 400 when the channel already has `maxBots` bots.
      operationId: createChannelExternalBot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                displayName:
                  type: string
                  description: Name shown for the bot
      responses:
        '200':
          description: The created bot user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChannelExternalBot'
        '400':
          description: Max bots created (plain error message)
          content:
            text/plain:
              schema:
                type: string
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
        '500':
          description: Failed to create the bot (plain error message)
          content:
            text/plain:
              schema:
                type: string
  /api/channel/{channelId}/external-bot/{botId}:
    get:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Get an external bot
      description: Channel admins only (the bot user includes its apiKey, which they need to connect it). Returns an array holding the matching bot user (empty when none matches).
      operationId: getChannelExternalBot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - $ref: '#/components/parameters/ChannelBotId'
      responses:
        '200':
          description: Matching bot users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ChannelExternalBot'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
    delete:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Delete an external bot
      description: Channel admins only. Deletes the bot user from the channel.
      operationId: deleteChannelExternalBot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - $ref: '#/components/parameters/ChannelBotId'
      responses:
        '200':
          description: MongoDB delete result
          content:
            application/json:
              schema:
                type: object
                properties:
                  acknowledged:
                    type: boolean
                  deletedCount:
                    type: integer
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
  /api/channel/{channelId}/followers/me:
    put:
      tags:
        - Channels
        - 'Role: User'
      summary: Follow a channel
      description: Adds the channel to the caller's followed channels and the caller to the channel's followers.
      operationId: followChannel
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Followed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChannelEmptyResult'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: Channel not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/ChannelErrorBody'
    delete:
      tags:
        - Channels
        - 'Role: User'
      summary: Unfollow a channel
      operationId: unfollowChannel
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Unfollowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChannelEmptyResult'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '500':
          $ref: '#/components/responses/ChannelErrorBody'
  /api/channel/{channelId}/history:
    get:
      tags:
        - Channels
        - Bot
        - 'Role: User'
      summary: Get the track history of a channel
      description: Only for users currently joined to the channel (a bot need not have joined). Tracks played by users and by the bot, newest first.
      operationId: getChannelHistory
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Track history
          content:
            application/json:
              schema:
                type: object
                properties:
                  channelId:
                    type: string
                  history:
                    type: array
                    items:
                      $ref: '#/components/schemas/ChannelHistoryEntry'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          $ref: '#/components/responses/ChannelNotFound'
  /api/channel/{channelId}/events:
    get:
      tags:
        - Events
        - 'Role: User'
      summary: List a channel's events
      description: The events whose last day has not ended, soonest first, or with `past=true` the ones that are over, latest first (200 at most). Each carries how many slots it has and how many are taken. A series that is still to come is listed once, as its next event (with `seriesRemaining`); the events that are over are all listed. A channel that is gone, or that bans the caller, is 404.
      operationId: listChannelEvents
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: past
          in: query
          required: false
          description: '`true` for the events that are over.'
          schema:
            type: string
            enum:
              - 'true'
              - 'false'
      responses:
        '200':
          description: The events
          content:
            application/json:
              schema:
                type: object
                properties:
                  events:
                    type: array
                    items:
                      $ref: '#/components/schemas/EventListItem'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: The channel is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to load the events
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Create an event
      description: Channel admins and owners only. The event gets its own url id, a readable slug and a random suffix (`friday-night-k3f9x2`), which is the one to share. The slots are not stored; they are worked out from the days and `slotMinutes` (each day's window is filled with whole slots from its start, and what is left is not used). With `recurrence` (weekly, or monthly on a weekday of the month) the days, which have to be within one week of the first, are repeated to the end of the first day's year, as a series, with an event made for each time it happens, each with its own url, slots, signups and playlist, all with one `seriesId`. The answer is the first of them and how many there are. A series is all or nothing.
      operationId: createChannelEvent
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventCreateRequest'
      responses:
        '201':
          description: The event that was made (the first of a series)
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    $ref: '#/components/schemas/Event'
                  count:
                    type: integer
                    description: How many events were made (more than one for a series)
        '400':
          description: The event is not right (the message says what is wrong)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          $ref: '#/components/responses/ChannelNotAuthorized'
        '409':
          description: A day of the event, or of a date of the series, overlaps another event of the channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventOverlapError'
        '500':
          description: Unable to create the event
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events:
    get:
      tags:
        - Events
        - 'Role: User'
      summary: List the events of every channel
      description: For a person who is not in a channel. The events whose last day has not ended, soonest first, or with `past=true` the ones that are over, latest first (200 at most), from every channel the caller can see. Channels that are gone or that ban the caller are left out, and so are private channels the caller has no part in (as a creator, admin or moderator). Each event carries its channel's title and slug, how many slots it has, how many are taken and how many tracks were played in it, and `channel`, the channel as the list of channels has it (the people in it, what it is playing and its DJ) to be shown beside the event. A series that is still to come is listed once, as its next event (with `seriesRemaining`).
      operationId: listEvents
      security:
        - bearerAuth: []
      parameters:
        - name: past
          in: query
          required: false
          description: '`true` for the events that are over.'
          schema:
            type: string
            enum:
              - 'true'
              - 'false'
      responses:
        '200':
          description: The events
          content:
            application/json:
              schema:
                type: object
                properties:
                  events:
                    type: array
                    items:
                      $ref: '#/components/schemas/EventListItem'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '500':
          description: Unable to load the events
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/channels:
    get:
      tags:
        - Events
        - 'Role: User'
      summary: List the channels the caller can make an event in
      description: The channels the caller is an admin or an owner of, by title (500 at most), for the page of events to offer when someone makes an event. Channels that are gone or that ban the caller are left out. Moderators are not admins here, as the route that makes an event refuses them too.
      operationId: listEventChannels
      security:
        - bearerAuth: []
      responses:
        '200':
          description: The channels
          content:
            application/json:
              schema:
                type: object
                properties:
                  channels:
                    type: array
                    items:
                      type: object
                      properties:
                        _id:
                          type: string
                        slug:
                          type: string
                        title:
                          type: string
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '500':
          description: Unable to load the channels
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}:
    get:
      tags:
        - Events
        - 'Role: User'
      summary: Get an event
      description: The event, who has each of its slots, and what was played while it ran (`playlist`). The event is found by its slug (the url id) or its `_id`. An admin or owner of the channel also gets the tracks that were removed (`removedPlaylist`). An event in a series also gets `series`, with every date of the series and its url, and `renewableFrom`, the first moment an admin can renew it. An event that is gone, of a channel that is gone, or of one that bans the caller, is 404.
      operationId: getEvent
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
      responses:
        '200':
          description: The event and its signups
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    $ref: '#/components/schemas/Event'
                  signups:
                    type: array
                    items:
                      $ref: '#/components/schemas/EventSignup'
                  playlist:
                    type: array
                    items:
                      $ref: '#/components/schemas/EventPlaylistEntry'
                  removedPlaylist:
                    type: array
                    description: Only for admins and owners of the channel
                    items:
                      $ref: '#/components/schemas/EventPlaylistEntry'
                  series:
                    type: object
                    description: Only for an event in a series
                    properties:
                      occurrences:
                        type: array
                        description: Every event of the series, soonest first
                        items:
                          type: object
                          properties:
                            _id:
                              type: string
                            slug:
                              type: string
                            startsAt:
                              type: string
                              format: date-time
                            endsAt:
                              type: string
                              format: date-time
                      renewableFrom:
                        type: string
                        format: date-time
                        description: 1 December of the year of the last event of the series, on the clock of its time zone
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to load the event
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    put:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Change an event
      description: Channel admins and owners only. Changes the name, the description and how many slots each person can take. The days, the times and the slot length are fixed once the event is made, because the signups are for those slots; sending them is a 400, and so is changing how it repeats. With `scope` series the change is made to the events of the series that are still to come as well; the ones that are over are what happened.
      operationId: updateEvent
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventUpdateRequest'
      responses:
        '200':
          description: The event as it is now
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    $ref: '#/components/schemas/Event'
        '400':
          description: A field is not right, or one that cannot be changed was sent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not an admin of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to save the event
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Delete an event
      description: Channel admins and owners only. Deletes the event, its signups and its image (unless another event of its series has the same one). With `scope=series` it deletes the events of the series that are still to come as well; the ones that are over stay.
      operationId: deleteEvent
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - name: scope
          in: query
          required: false
          schema:
            type: string
            enum:
              - this
              - series
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      count:
                        type: integer
                        description: How many events were deleted
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not an admin of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to delete the event
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/renew:
    post:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Renew a recurring event for the next year
      description: Channel admins and owners only. A series runs to the end of a year and goes on only when it is renewed. From 1 December of the year of its last event, and after (a late renewal has no events for the dates that have gone by), this makes the events of the next year on the same weekdays and times, from the last event of the series, with its image and slot length. The body can give a new name, description or limit of slots each for the new events; the days and how it repeats cannot be changed. Answers with the first new event and how many were made. All or nothing.
      operationId: renewEvent
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventUpdateRequest'
      responses:
        '201':
          description: The events of the next year
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    $ref: '#/components/schemas/Event'
                  count:
                    type: integer
        '400':
          description: A field is not right, or one that cannot be changed was sent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not an admin of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The event does not repeat, it is before 1 December of the last year of the series, the next year has gone by, or a date of the next year overlaps another event of the channel (then the answer has `conflicts`)
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Error'
                  - $ref: '#/components/schemas/EventOverlapError'
        '500':
          description: Unable to renew the event
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/image:
    put:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Upload an event's promo image
      description: Channel admins and owners only. Stores the image (max 10 MB; jpeg, png, gif or webp) as a 960 by 540 webp, the ratio of 16 to 9, turned upright. The part of the picture to keep is given as `cropX`, `cropY`, `cropWidth` and `cropHeight` in the picture's own pixels, and the centre is kept without them. A gif stays a moving image. It saves its path on the event and deletes the previous file (unless another event has it). With `scope=series` the image is put on the events of the series that are still to come as well, which share the one file.
      operationId: putEventImage
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - name: scope
          in: query
          required: false
          schema:
            type: string
            enum:
              - this
              - series
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/EventImageUpload'
      responses:
        '200':
          description: The event with its new image
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    $ref: '#/components/schemas/Event'
        '400':
          description: No image was sent, or it is not a type the app takes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not an admin of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to save the image
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/playlist:
    get:
      tags:
        - Events
        - 'Role: User'
      summary: Get what was played in an event
      description: The tracks the channel played while the event ran, oldest first, for anyone in the channel's reach. The server writes them as each track ends (a track belongs to the event that was running when it began; one that began in a slot and ran past its end stays with it), and nobody else does. With `slot` only the tracks played in that slot are given. An admin or owner of the channel also gets the tracks that were removed.
      operationId: getEventPlaylist
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - name: slot
          in: query
          required: false
          description: The start of a slot (`2026-11-13T20:00:00.000Z`).
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: The playlist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventPlaylist'
        '400':
          description: The slot is not a time
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: The event is not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to load the playlist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/playlist/{index}:
    delete:
      tags:
        - Events
        - 'Role: Channel mod'
      summary: Remove a track from an event's playlist
      description: Moderators, admins and owners of the channel only. For a track that was played by accident. It is not deleted, but marked as removed (by whom, and when) and hidden from everyone, and an admin or owner can bring it back. It keeps its place in the list, so the other tracks keep their `index`.
      operationId: removeEventPlaylistTrack
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - $ref: '#/components/parameters/EventPlaylistIndex'
        - $ref: '#/components/parameters/EventPlaylistStartedAt'
      responses:
        '200':
          description: The playlist as the caller may see it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventPlaylist'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not a moderator of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found, or there is no track at that index
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The track is already removed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to remove the track
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/playlist/{index}/restore:
    put:
      tags:
        - Events
        - 'Role: Channel admin'
      summary: Bring back a removed track
      description: Admins and owners of the channel only.
      operationId: restoreEventPlaylistTrack
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - $ref: '#/components/parameters/EventPlaylistIndex'
        - $ref: '#/components/parameters/EventPlaylistStartedAt'
      responses:
        '200':
          description: The playlist, with the track back and the removed ones that are left
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventPlaylist'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: Not an admin of the event's channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found, or there is no track at that index
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The track is not removed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to bring the track back
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/events/{eventId}/slots/{startsAt}:
    put:
      tags:
        - Events
        - 'Role: User'
      summary: Sign up for a slot
      description: Gives the caller the slot that starts at `startsAt`, under their own name, with an optional description of their set (200 characters at most). The first to ask has the slot (409 for the second). A person can take as many slots as the event's `maxSlotsPerUser` says (409 over it). A slot that has started cannot be taken. An event with no reserved slots (`slotMinutes` null) has no slots to take, so the answer is 409. Answers with all of the event's signups.
      operationId: signUpForEventSlot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - $ref: '#/components/parameters/EventSlotStart'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventSignupRequest'
      responses:
        '200':
          description: The signups of the event, with the caller's
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventSignups'
        '400':
          description: The description is not right
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: The event is not found, or the time is not the start of one of its slots
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The slot was just taken, has started, or the caller is at the event's limit
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to sign up
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Events
        - 'Role: User'
      summary: Give up a slot
      description: The person who has the slot lets go of it, and an admin or owner of the channel may let go of anyone's. A slot that has started is not given up. Answers with all of the event's signups.
      operationId: cancelEventSlot
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/EventId'
        - $ref: '#/components/parameters/EventSlotStart'
      responses:
        '200':
          description: The signups of the event, without it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventSignups'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The slot is someone else's and the caller is not an admin of the channel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The event is not found, or nobody has that slot
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The slot has started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unable to cancel
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channels/{query}/{pageNumber}:
    get:
      tags:
        - Channels
        - 'Role: User'
      summary: List channels
      description: Channels the caller is not banned from, excluding deleted and no-join channels, sorted by number of users and DJs (most first). 16 channels per page. The optional `query` search string matches slug, genre and title (case-insensitive, whitespace matches any characters). Without a search, channels nobody has joined or played a track in for 6 months (3 months for private channels) are left out too.
      operationId: listChannels
      security:
        - bearerAuth: []
      parameters:
        - name: query
          in: path
          required: true
          description: '`popular` (public channels with at least one user), `my` (channels the caller created, administers or moderates), `followed` (channels the caller follows); any other value lists all channels.'
          schema:
            type: string
        - name: pageNumber
          in: path
          required: true
          description: Zero-based page number (non-numeric values are treated as 0).
          schema:
            type: integer
            minimum: 0
        - name: query
          in: query
          required: false
          description: Search text matched against slug, genre and title.
          schema:
            type: string
      responses:
        '200':
          description: A page of channels
          content:
            application/json:
              schema:
                type: object
                properties:
                  count:
                    type: integer
                    description: Total number of matching channels
                  channels:
                    type: array
                    items:
                      $ref: '#/components/schemas/Channel'
                  more:
                    type: boolean
                    description: True when there are further pages
                  liveEvents:
                    type: array
                    description: Only on page 0, and only when there are some. The channels of this list (the same search and tab) that have an event on now, one event per channel, the channel with the most people first and, of those with as many, the event that began first. A channel here is also in the pages of `channels`, and the client puts it first.
                    items:
                      type: object
                      properties:
                        event:
                          $ref: '#/components/schemas/EventListItem'
                        channel:
                          $ref: '#/components/schemas/Channel'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '404':
          description: The query failed; the body is the plain error message
          content:
            text/plain:
              schema:
                type: string
  /api/firsts:
    post:
      tags:
        - Music
        - 'Role: User'
      summary: Find ISRCs that have not been played before
      description: Returns the subset of the given ISRCs that have no recorded first play.
      operationId: postFirsts
      security:
        - bearerAuth: []
      parameters:
        - name: bypassCache
          in: query
          required: false
          schema:
            type: string
          description: Passed to the first-plays lookup to skip its cache.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - isrcs
              properties:
                isrcs:
                  type: array
                  items:
                    type: string
                  description: ISRC codes to check.
      responses:
        '200':
          description: The ISRCs from the request that were not found as first plays.
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
  /api/health:
    get:
      tags:
        - System
        - 'Role: Public'
      summary: Health check
      operationId: health
      security: []
      responses:
        '200':
          description: Server is up
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: OK
  /api/login:
    get:
      tags:
        - Account
        - 'Role: User'
      summary: Resume a session
      description: Validates the bearer token and returns the decoded token with the user document.
      operationId: resumeSession
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Session
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: object
                    description: Decoded JWT payload
                  user:
                    type: object
                    description: Mongo user document
                  chatMaxLength:
                    type: integer
                    description: The longest chat message the server accepts (CHAT_MAX_LENGTH, 2000 by default); the web app checks messages against it before sending.
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          description: User not found; the body is the plain message string
          content:
            text/plain:
              schema:
                type: string
  /api/login/providers:
    get:
      tags:
        - Account
        - 'Role: Public'
      summary: The services the login page offers
      description: The music services this server lets people log in with (`ENABLED_PROVIDERS`, Spotify alone when it is not set) and is set up for. The login page shows a button for each.
      operationId: loginProviders
      security: []
      responses:
        '200':
          description: The providers
          content:
            application/json:
              schema:
                type: object
                properties:
                  providers:
                    type: array
                    items:
                      type: string
                      enum: [spotify, apple, tidal]
  /api/login/spotify/callback:
    get:
      tags:
        - Account
        - 'Role: Public'
      summary: Spotify OAuth callback
      description: Called by Spotify after authorisation. Verifies the state JWT, exchanges the code (PKCE, verifier read from Redis) for tokens, finds or creates the user of the Spotify account that logged in (and its wallet), keeps the Spotify tokens on the server (encrypted, in the `spotifyAuths` collection; the server refreshes them, so a client that is asleep at the time loses nothing), then redirects to the web app with a new session JWT, which says who the user is and carries no Spotify token. The Spotify account decides who logs in. If the state JWT names an RVRB user who has no Spotify account yet, the account is linked to that user. If it names a user linked to a different Spotify account, that user is left as it was, the Spotify account gets its own user, and the redirect carries `switchedFrom`, the id of the user the login started as.
      operationId: spotifyLoginCallback
      security: []
      parameters:
        - name: code
          in: query
          required: true
          schema:
            type: string
          description: Spotify authorisation code
        - name: state
          in: query
          required: true
          schema:
            type: string
          description: Signed state JWT issued when the login started
      responses:
        '302':
          description: Redirect to /login/?session={jwt}&spotifyToken={spotifyUri}
          headers:
            Location:
              schema:
                type: string
        '400':
          description: Missing authorization code (plain string)
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: State invalid, PKCE verifier missing or expired, or the token exchange or user lookup failed (plain error message)
          content:
            text/plain:
              schema:
                type: string
  /api/logout:
    get:
      tags:
        - Account
        - 'Role: User'
      summary: Log out
      description: Makes the user leave their channel and closes all their websocket connections.
      operationId: logout
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Logged out
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: string
                    example: OK
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '500':
          $ref: '#/components/responses/UsersError'
  /api/login/tidal:
    get:
      tags:
        - Account
        - 'Role: Public'
      summary: Start a login with TIDAL
      description: Redirects to TIDAL to log in (OAuth 2 authorization code with PKCE; the verifier is kept in Redis for ten minutes). TIDAL sends the user back to `/api/login/tidal/callback`. Needs `TIDAL_CLIENT_ID`.
      operationId: tidalLogin
      security: []
      responses:
        '302':
          description: Redirect to TIDAL
        '500':
          description: TIDAL is not set up, or the verifier could not be kept
          content:
            text/plain:
              schema:
                type: string
  /api/login/tidal/callback:
    get:
      tags:
        - Account
        - 'Role: Public'
      summary: TIDAL OAuth callback
      description: Called by TIDAL after the user logged in. Verifies the state (signed by the server), trades the code for tokens (the PKCE verifier is used once), asks TIDAL who the user is, finds or creates the user of that TIDAL account, keeps the tokens on the server (encrypted; the server refreshes them), and redirects to the web app with `session` (and `provider=tidal`, and `switchedFrom` when the account is another user's than the one the login started as). With the state of `POST /api/users/{userId}/accounts/tidal/link` the account is added to that user instead, and the redirect is `/login/?linked=tidal`; an account that is another user's is refused (`/login/?linkError=account_in_use&provider=tidal`), as users are not merged by the app.
      operationId: tidalLoginCallback
      security: []
      parameters:
        - name: code
          in: query
          schema:
            type: string
        - name: state
          in: query
          schema:
            type: string
        - name: error
          in: query
          schema:
            type: string
      responses:
        '302':
          description: Redirect to the web app
        '400':
          description: No code or state
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: The login could not be finished
          content:
            text/plain:
              schema:
                type: string
  /api/login/apple:
    get:
      tags:
        - Account
        - 'Role: Public'
      security: []
      summary: What the page needs to log in with Apple Music
      description: >-
        Apple Music is logged in to by the page itself (see `POST /api/login/apple`), which needs the developer token to configure MusicKit
        JS with and the Services ID that Sign in with Apple is for. The developer token only works from the web app's origin. A server
        that is not set up for Apple Music answers 501.
      operationId: loginAppleConfig
      responses:
        '200':
          description: What to configure MusicKit JS and Sign in with Apple with
          content:
            application/json:
              schema:
                type: object
                required: [developerToken, clientId]
                properties:
                  developerToken:
                    type: string
                  clientId:
                    type: string
                    description: The Services ID of Sign in with Apple
        '500':
          description: The config could not be made
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '501':
          description: This server is not set up for Apple Music
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
        - Account
        - 'Role: Public'
      security: []
      summary: Finish a login with Apple Music
      description: >-
        The page signs in with Apple (who the user is: the `sub` of the ID token) and authorizes MusicKit JS (the music: the Music User
        Token), and sends both here. The ID token has to be Apple's, for this app, and for the nonce asked for; Apple has to accept the
        Music User Token. Answers a session like the Spotify login does. With the `state` of `POST /api/users/{userId}/accounts/apple/link`
        the account is added to that user and the session stays as it was. An account that is another user's is refused (409): users are
        not merged by the app. When the login would make a new user and the server offers more than one music service, no user is made:
        `newAccount` is an id for `/api/login/new-account/{id}`, where the person is asked whether they already use RVRB with another
        service (the Spotify and TIDAL callbacks send the page to `/login/?newAccount={id}&provider=…` for the same).
      operationId: loginApple
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [idToken, musicUserToken]
              properties:
                idToken:
                  type: string
                  description: The Sign in with Apple ID token
                nonce:
                  type: string
                  description: The nonce the page asked Sign in with Apple for, if it did
                musicUserToken:
                  type: string
                state:
                  type: string
                  description: The state from the link request, when adding the account to a signed-in user
      responses:
        '200':
          description: Logged in, or (with a state) the account was added
          content:
            application/json:
              schema:
                type: object
                properties:
                  session:
                    type: string
                    description: The session token (JWT), as for the Spotify login
                  switchedFrom:
                    type: string
                    description: The user the login started as, when the account is another one's
                  linked:
                    type: string
                    enum: [apple]
                  newAccount:
                    type: string
                    description: The id of a login that would make a new user, held until the person confirms it (see `/api/login/new-account/{id}`)
                  provider:
                    type: string
                    description: With `newAccount`, the service that was logged in with
        '400':
          description: The state is not good any more
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: The ID token or the Music User Token is no good
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: The login could not be finished
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The account is another user's (`account_in_use`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/login/new-account/{id}:
    parameters:
      - name: id
        in: path
        required: true
        description: The `newAccount` id a login that would make a new user gave
        schema:
          type: string
    get:
      tags:
        - Account
        - 'Role: Public'
      security: []
      summary: What a person is asked before a new user is made
      description: >-
        A login with a music service that has no RVRB user yet is held, and not made into one at once: someone who already uses RVRB with
        another service would get a second account with none of their history. The id is a secret given only to the person who logged
        in, valid for fifteen minutes. This says which service they logged in with and which others there are to log in with instead.
      operationId: getNewAccountPrompt
      responses:
        '200':
          description: The service logged in with, and the others
          content:
            application/json:
              schema:
                type: object
                required: [provider, others]
                properties:
                  provider:
                    type: string
                    enum: [spotify, apple, tidal]
                  others:
                    type: array
                    items:
                      type: string
                      enum: [spotify, apple, tidal]
        '404':
          description: There is no such login, or it has run out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      tags:
        - Account
        - 'Role: Public'
      security: []
      summary: Make the new user, or forget the login
      description: >-
        `confirm: true` makes the new user and answers its session, as the other logins do. Anything else forgets the login (the person is
        going to log in with the service they already use), and answers 204. The id is used up either way.
      operationId: answerNewAccountPrompt
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [confirm]
              properties:
                confirm:
                  type: boolean
      responses:
        '200':
          description: The new user was made
          content:
            application/json:
              schema:
                type: object
                properties:
                  session:
                    type: string
                    description: The session token (JWT), as for the Spotify login
                  provider:
                    type: string
                    enum: [spotify, apple, tidal]
        '204':
          description: The login was forgotten
        '403':
          description: The user could not be made
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: There is no such login, or it has run out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/devices:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: List playback devices
      description: 'Spotify devices for the user, with `is_preferred: true` on the one matching the saved preferred player name.'
      operationId: getMusicDevices
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: 'Spotify devices response, passed through (`devices` array), with `is_preferred` added to the preferred device.'
                properties:
                  devices:
                    type: array
                    items:
                      type: object
                      description: Spotify device object.
                      additionalProperties: true
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Request to Spotify failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/devices/preferred:
    put:
      tags:
        - Music
        - 'Role: User'
      summary: Set the preferred playback device
      description: Saves the device name as the user's preferred player.
      operationId: putPreferredDevice
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - device_name
              properties:
                device_name:
                  type: string
                  description: Name of the device (may be an empty string to clear).
      responses:
        '200':
          description: Saved.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    description: Always an empty object.
                required:
                  - result
        '400':
          description: '`device_name` missing.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/export:
    post:
      tags:
        - Music
        - 'Role: User'
      summary: Export tracks to a new Spotify playlist
      description: Creates a private playlist on the user's Spotify account and adds the tracks in batches of 100. Provide `uris` or `stackId` (`uris` wins). Logs the `exporter` achievement. Needs a Spotify login.
      operationId: exportToPlaylist
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Playlist name.
                description:
                  type: string
                  description: Playlist description; defaults to empty.
                uris:
                  type: array
                  items:
                    type: string
                  description: Spotify track URIs to add.
                stackId:
                  type: string
                  description: Id of one of the user's stacks whose tracks are exported.
      responses:
        '200':
          description: Playlist created and filled.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    description: Always an empty object.
                required:
                  - result
        '400':
          description: Neither `uris` nor `stackId` provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Spotify refused to create the playlist or add tracks.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/me:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get the decoded user token
      description: Returns the decoded JWT payload of the caller (after any Spotify token refresh). Needs a Spotify login.
      operationId: getMusicMe
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: Decoded JWT claims; user data is under `data`.
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
  /api/music/me/tracks:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get a page of the user's saved tracks
      description: Saved ("liked") tracks from Spotify. Needs a Spotify login.
      operationId: getMySavedTracks
      security:
        - bearerAuth: []
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            default: 0
          description: Zero-based page.
        - name: limit
          in: query
          schema:
            type: integer
            default: 50
          description: Page size.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: Page of tracks as built by getTracksPage; shape not fixed by the route.
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Spotify lookup failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/playlist/{id}:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get playlist details without tracks
      description: Simple playlist info. Needs a Spotify login.
      operationId: getPlaylist
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: Spotify playlist object (simplified), passed through.
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Spotify lookup failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/playlist/{id}/{page}:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get a page of a playlist's tracks
      description: Returns the playlist with one page of tracks. With `page` set to `all` every page is fetched and returned in one playlist. Needs a Spotify login.
      operationId: getPlaylistPage
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
        - name: page
          in: path
          required: true
          schema:
            type: string
          description: Zero-based page number (or `all`, see above).
        - name: bypassCache
          in: query
          schema:
            type: string
            enum:
              - 'true'
          description: Set to `true` to skip the cache.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  playlist:
                    type: object
                    description: Spotify playlist object with a `tracks` page, passed through.
                    additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Spotify lookup failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: '`page` was `all` (broken).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/playlist/{id}/tracks:
    post:
      tags:
        - Music
        - 'Role: User'
      summary: Add tracks to a Spotify playlist
      description: Add `uris`, or all tracks of another playlist via `fromPlaylistUri` (takes precedence; local and null tracks are skipped). Error bodies echo the request's `snapshot_id`. Needs a Spotify login.
      operationId: addTracksToPlaylist
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                uris:
                  type: array
                  items:
                    type: string
                  description: Spotify track URIs. Required unless `fromPlaylistUri` is set.
                fromPlaylistUri:
                  type: string
                  description: Add every track of this playlist instead.
                position:
                  type: integer
                  default: 0
                  description: Insert position.
                snapshot_id:
                  type: string
                  description: Playlist snapshot id the client last saw; echoed in errors.
      responses:
        '200':
          description: Tracks added.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      snapshot_id:
                        type: string
                        description: Spotify playlist snapshot id after the change.
                required:
                  - result
        '400':
          description: '`uris` missing or not an array.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Spotify error or no snapshot id returned; client should re-sync.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
    delete:
      tags:
        - Music
        - 'Role: User'
      summary: Remove tracks from a Spotify playlist by uri
      description: Removes every occurrence of the given track uris (in batches of 100), wherever they are in the playlist. The client uses it when it does not know a track's position; `DELETE .../tracks/{position}` removes one by its place. Optionally guarded by `snapshot_id`. Error bodies echo the request's `snapshot_id`. Needs a Spotify login.
      operationId: removeTracksFromPlaylistByUri
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
        - name: snapshot_id
          in: query
          schema:
            type: string
          description: Playlist snapshot id the client last saw.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - uris
              properties:
                uris:
                  type: array
                  minItems: 1
                  items:
                    type: string
                  description: Spotify track uris to remove.
      responses:
        '200':
          description: Tracks removed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      snapshot_id:
                        type: string
                        description: Spotify playlist snapshot id after the change (absent when Spotify did not give one).
        '400':
          description: No `uris`, or a uri that is not text.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
        '401':
          description: Missing or invalid token, or not logged in with Spotify. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
        '500':
          description: Spotify refused, or the request failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
    patch:
      tags:
        - Music
        - 'Role: User'
      summary: Move a track in a Spotify playlist
      description: Moves the track at `position` so that it ends up at `targetPosition`, as the DJ queue's tracks move. Optionally guarded by `snapshot_id`. Error bodies echo the request's `snapshot_id`. Needs a Spotify login, and a playlist the user can edit.
      operationId: moveTrackInPlaylist
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - position
                - targetPosition
              properties:
                position:
                  type: integer
                  minimum: 0
                  description: Zero-based position of the track to move.
                targetPosition:
                  type: integer
                  minimum: 0
                  description: Zero-based position the track ends up at.
                length:
                  type: integer
                  minimum: 1
                  default: 1
                  description: How many tracks to move, starting at `position`.
                snapshot_id:
                  type: string
                  description: Playlist snapshot id the client last saw.
      responses:
        '200':
          description: Track moved.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      snapshot_id:
                        type: string
                        description: Spotify playlist snapshot id after the change.
                required:
                  - result
        '400':
          description: '`position` or `targetPosition` is missing or not a position, or `length` is not a positive whole number.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
        '401':
          description: Missing or invalid token, or not logged in with Spotify. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '403':
          description: Spotify says the user cannot edit this playlist.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
        '500':
          description: Spotify error or no snapshot id returned; client should re-sync.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
  /api/music/playlist/{id}/tracks/{position}:
    delete:
      tags:
        - Music
        - 'Role: User'
      summary: Remove a track from a Spotify playlist by position
      description: Removes the track at `position` (optionally guarded by `snapshot_id`). Error bodies echo the request's `snapshot_id`. Needs a Spotify login.
      operationId: removeTrackFromPlaylist
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spotify playlist id or URI (the part after the last `:` is used).
        - name: position
          in: path
          required: true
          schema:
            type: integer
          description: Zero-based position of the track.
        - name: snapshot_id
          in: query
          schema:
            type: string
          description: Playlist snapshot id the client last saw.
      responses:
        '200':
          description: Track removed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      snapshot_id:
                        type: string
                        description: Spotify playlist snapshot id after the change.
                required:
                  - result
        '400':
          description: '`position` is not a number.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Spotify error or no snapshot id returned; client should re-sync.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MusicSnapshotError'
  /api/music/playlist/defaults:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get the user's default playlists
      description: The user's Playlists document (queue/starred defaults), or null when none exists. Needs a Spotify login.
      operationId: getDefaultPlaylists
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    nullable: true
                    description: Playlists document for the user.
                    additionalProperties: true
                required:
                  - result
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
    put:
      tags:
        - Music
        - 'Role: User'
      summary: Create the user's default playlists
      description: Initializes the default playlists on Spotify and returns the resulting Playlists document. Needs a Spotify login.
      operationId: initDefaultPlaylists
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    nullable: true
                    description: Playlists document for the user.
                    additionalProperties: true
                required:
                  - result
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Initialization failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/playlists/{page}:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Get a page of the user's playlists
      description: Spotify playlists the user owns or follows. Needs a Spotify login.
      operationId: getPlaylistsPage
      security:
        - bearerAuth: []
      parameters:
        - name: page
          in: path
          required: true
          schema:
            type: integer
          description: Zero-based page.
        - name: limit
          in: query
          schema:
            type: integer
          description: Page size (default decided by getPlaylistsPage).
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: Page of playlists as built by getPlaylistsPage; shape not fixed by the route.
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Spotify lookup failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/search:
    get:
      tags:
        - Music
        - 'Role: User'
      summary: Search Spotify
      description: Proxies Spotify's search endpoint. Needs a Spotify login.
      operationId: searchMusic
      security:
        - bearerAuth: []
      parameters:
        - name: q
          in: query
          required: true
          schema:
            type: string
          description: Search query.
        - name: type
          in: query
          required: true
          schema:
            type: string
          description: Comma-separated Spotify item types, e.g. `track,album`.
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                description: Spotify search response, passed through.
                additionalProperties: true
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Request to Spotify failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/stack:
    get:
      tags:
        - Stacks
        - 'Role: User'
      summary: List the user's stacks
      description: Every stack of the caller, whichever music service it was made at.
      operationId: listStacks
      security:
        - bearerAuth: []
      parameters:
        - name: deleted
          in: query
          schema:
            type: string
            enum:
              - 'true'
          description: Set to `true` to list deleted stacks instead of live ones.
        - name: channelId
          in: query
          schema:
            type: string
          description: List only the queue the caller made for this channel.
      responses:
        '200':
          description: The stacks.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: array
                    items:
                      $ref: '#/components/schemas/Stack'
                required:
                  - result
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: {}
                description: Error object from the database.
    post:
      tags:
        - Stacks
        - 'Role: User'
      summary: Create a stack
      description: Creates a stack of the caller's music service type (spotify).
      operationId: createStack
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                description:
                  type: string
                  default: ''
                activeQueue:
                  type: boolean
                  default: false
                  description: Makes this the caller's general queue, which plays where a channel has no queue of theirs; their previous general queue is no longer active. Not with `channelId`.
                channelId:
                  type: string
                  description: Makes this the caller's queue for that channel, which plays there in place of the general queue. One per user and channel.
                tracks:
                  type: array
                  items:
                    type: string
                  description: Initial track ids.
      responses:
        '200':
          description: The created stack.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '400':
          description: '`name` missing, `tracks` not an array, `channelId` not a string, or both `channelId` and `activeQueue: true`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: There is no such channel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The caller already has a queue for that channel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: {}
                description: Error object from the database.
  /api/music/stack/{id}:
    get:
      tags:
        - Stacks
        - 'Role: User'
      summary: Get a stack with a page of tracks
      description: "For Spotify stacks the track ids of the requested page are resolved to full track objects and `totalItems`, `more` and `next` are added; other stacks are returned as stored. Only the caller's own stacks: another user's stack id answers 404."
      operationId: getStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
        - name: page
          in: query
          schema:
            type: integer
            default: 0
          description: Zero-based page.
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
            maximum: 50
          description: Page size, capped at 50.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    allOf:
                      - $ref: '#/components/schemas/Stack'
                      - type: object
                        properties:
                          tracks:
                            type: array
                            items:
                              type: object
                              additionalProperties: true
                            description: Spotify track objects for the page (Spotify stacks).
                          totalItems:
                            type: integer
                          more:
                            type: boolean
                          next:
                            type: string
                            nullable: true
                            description: URL of the next page, or null.
                required:
                  - result
        '400':
          description: '`id` missing.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database or Spotify error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: {}
                description: Error object.
    put:
      tags:
        - Stacks
        - 'Role: User'
      summary: Update a stack
      description: Updates the caller's own stack. Only the fields sent (and truthy) are changed; `tracks` entries that are not valid Spotify base62 ids are dropped. Needs a Spotify login.
      operationId: updateStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                tracks:
                  type: array
                  items:
                    type: string
                  description: Replaces the stack's tracks.
                channelId:
                  type: string
                  nullable: true
                  description: Makes this the caller's queue for that channel (and not the general queue); `null` takes it off its channel.
                activeQueue:
                  type: boolean
                  description: "`true` makes this the caller's general queue, off any channel; their previous general queue is no longer active. `false` stops it being one. Not with a `channelId`."
      responses:
        '200':
          description: The updated stack.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '400':
          description: '`id` missing, `channelId` not a string, or both `channelId` and `activeQueue: true`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found for this user, or there is no such channel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The caller already has a queue for that channel.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: {}
                description: Error object from the database.
    delete:
      tags:
        - Stacks
        - 'Role: User'
      summary: Delete a stack
      description: "Soft delete: marks the caller's stack `deleted: true`. Needs a Spotify login."
      operationId: deleteStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      responses:
        '200':
          description: The stack, now marked deleted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '400':
          description: '`id` missing.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found for this user.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: {}
                description: Error object from the database.
  /api/music/stack/{id}/shuffle:
    post:
      tags:
        - Stacks
        - 'Role: User'
      summary: Shuffle a stack
      description: Randomizes the track order of the caller's stack. Needs a Spotify login.
      operationId: shuffleStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      responses:
        '200':
          description: The shuffled stack.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/stack/{id}/tracks:
    post:
      tags:
        - Stacks
        - 'Role: User'
      summary: Add tracks to a stack
      description: Inserts tracks at `position` (default 0), creating the stack document if it does not exist. Give `trackIds` (invalid ids are dropped) or `fromPlaylistUri` (takes precedence; local and null tracks are skipped). Needs a Spotify login.
      operationId: addTracksToStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                trackIds:
                  type: array
                  items:
                    type: string
                  description: Spotify track ids. Required unless `fromPlaylistUri` is set.
                fromPlaylistUri:
                  type: string
                  description: Add every track of this Spotify playlist.
                position:
                  type: integer
                  default: 0
      responses:
        '200':
          description: 'With `trackIds`: `result.tracks` holds the added tracks. With `fromPlaylistUri`: `result` is the updated stack.'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      result:
                        type: object
                        properties:
                          tracks:
                            type: array
                            items:
                              type: object
                              additionalProperties: true
                            description: Spotify track objects for the added ids.
                    required:
                      - result
                  - type: object
                    properties:
                      result:
                        $ref: '#/components/schemas/Stack'
                    required:
                      - result
        '400':
          description: '`trackIds` missing or not an array.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Database or Spotify error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    patch:
      tags:
        - Stacks
        - 'Role: User'
      summary: Move tracks within a stack
      description: Moves `length` tracks starting at `position` to `targetPosition`. Needs a Spotify login.
      operationId: reorderStackTracks
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - position
                - targetPosition
              properties:
                position:
                  type: integer
                  description: Index of the first track to move.
                targetPosition:
                  type: integer
                  description: Index to insert them at (after removal).
                length:
                  type: integer
                  default: 1
                  description: Number of tracks to move.
      responses:
        '200':
          description: The reordered stack.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '400':
          description: '`position` or `targetPosition` missing.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Stacks
        - 'Role: User'
      summary: Clear a stack's tracks
      description: Empties the track list (the stack document is created if it does not exist). Needs a Spotify login.
      operationId: clearStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
      responses:
        '200':
          description: The emptied stack.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: '#/components/schemas/Stack'
                required:
                  - result
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/stack/{id}/tracks/{position}:
    delete:
      tags:
        - Stacks
        - 'Role: User'
      summary: Remove one track from a stack
      description: Removes the track at `position` from the caller's stack. Needs a Spotify login.
      operationId: removeTrackFromStack
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Stack id.
        - name: position
          in: path
          required: true
          schema:
            type: integer
          description: Zero-based position of the track.
      responses:
        '200':
          description: Track removed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    description: Always an empty object.
                required:
                  - result
        '400':
          description: '`position` not a number or out of range.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid token. Body is the plain string `Forbidden`.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '404':
          description: Stack not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Database error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/notifications:
    get:
      tags:
        - Notifications
        - 'Role: User'
      summary: List your notifications
      description: Newest first. Empty array when the user has none.
      operationId: listNotifications
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Notifications
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Notification'
        '401':
          $ref: '#/components/responses/UsersForbidden'
    delete:
      tags:
        - Notifications
        - 'Role: User'
      summary: Clear all your notifications
      operationId: clearNotifications
      security:
        - bearerAuth: []
      responses:
        '200':
          description: Cleared
          content:
            application/json:
              schema:
                type: boolean
                example: true
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /api/notifications/{id}:
    delete:
      tags:
        - Notifications
        - 'Role: User'
      summary: Delete one notification
      operationId: deleteNotification
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Notification id
      responses:
        '200':
          description: Deleted (also true when the id did not exist)
          content:
            application/json:
              schema:
                type: boolean
                example: true
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /api/ping:
    get:
      tags:
        - System
        - 'Role: Public'
      summary: Ping
      operationId: ping
      security: []
      responses:
        '200':
          description: Plain text pong
          content:
            text/plain:
              schema:
                type: string
                example: pong
  /api/statistics/casino/leaderboard:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: Casino leaderboard
      description: "Per-user casino play counts and win rates (games: allin, coinflip, craps, rps, slots), sorted by wins. Data comes from the bot via an event request; if that fails the table is empty. With showMyPosition the caller's row is appended when outside the page (and not first). Responses are cached in Redis (when available) per period, records, channelId and, with showMyPosition, the caller; `bypassCache` skips the cached copy."
      operationId: getStatisticsCasinoLeaderboard
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsChannelId'
        - $ref: '#/components/parameters/StatisticsBypassCache'
        - $ref: '#/components/parameters/StatisticsShowMyPosition'
      responses:
        '200':
          description: Leaderboard rows, best first.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticsCasinoRow'
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Unhandled error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/statistics/djs/leaderboard:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: DJ leaderboard
      description: DJs ranked by score for the period. Returns an empty array when there are no statistics. With showMyPosition the caller's row is appended when outside the page. Responses are cached in Redis (when available) per period, records, channelId and, with showMyPosition, the caller; `bypassCache` skips the cached copy.
      operationId: getStatisticsDjsLeaderboard
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsChannelId'
        - $ref: '#/components/parameters/StatisticsBypassCache'
        - $ref: '#/components/parameters/StatisticsShowMyPosition'
      responses:
        '200':
          description: Leaderboard rows, best first.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticsDjRow'
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Unhandled error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/statistics/firsts/leaderboard:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: Firsts leaderboard
      description: Users ranked by number of first plays (first time a track was played in the channel) within the period. With showMyPosition the caller's row is appended when outside the page. Responses are cached in Redis (when available) per period, records, channelId and, with showMyPosition, the caller; `bypassCache` skips the cached copy.
      operationId: getStatisticsFirstsLeaderboard
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsChannelId'
        - $ref: '#/components/parameters/StatisticsBypassCache'
        - $ref: '#/components/parameters/StatisticsShowMyPosition'
      responses:
        '200':
          description: Leaderboard rows, best first.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticsFirstsRow'
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          description: Unhandled error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/statistics/spins/leaderboard:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: Most spun tracks
      description: Tracks ranked by number of spins in the period. Plays by the bot, user `0` and the old groupie user are excluded. Responses are cached in Redis (when available) per period, records, channelId; `bypassCache` skips the cached copy.
      operationId: getStatisticsSpinsLeaderboard
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsChannelId'
        - $ref: '#/components/parameters/StatisticsBypassCache'
      responses:
        '200':
          description: Leaderboard rows, best first.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticsSpinsRow'
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/statistics/batch:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: A leaderboard for several channels
      description: One request in place of one per channel. Each channel's rows are what the board's own route gives for it (the same cache), asked a few at a time. A channel that fails is named in `errors` and does not fail the others. Carries an `ETag` like the other statistics routes.
      operationId: getStatisticsBatch
      security:
        - bearerAuth: []
      parameters:
        - name: board
          in: query
          required: true
          schema:
            type: string
            enum: [djs, tracks, spins, firsts]
        - name: channelIds
          in: query
          required: true
          description: Comma separated, up to 50.
          schema:
            type: string
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsBypassCache'
      responses:
        '200':
          description: The rows of each channel, by channel id.
          content:
            application/json:
              schema:
                type: object
                properties:
                  board:
                    type: string
                  period:
                    type: string
                  results:
                    type: object
                    additionalProperties:
                      type: array
                      items:
                        type: object
                  errors:
                    type: object
                    additionalProperties:
                      type: object
                      properties:
                        status:
                          type: integer
                        message:
                          type: string
        '400':
          description: A board that is not known, no channelIds, or more than 50.
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/statistics/tracks/leaderboard:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: Top scored tracks
      description: Tracks ranked by score in the period. Plays by the bot, user `0` and the old groupie user are excluded. Responses are cached in Redis (when available) per period, records, channelId; `bypassCache` skips the cached copy.
      operationId: getStatisticsTracksLeaderboard
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/StatisticsPeriod'
        - $ref: '#/components/parameters/StatisticsRecords'
        - $ref: '#/components/parameters/StatisticsChannelId'
        - $ref: '#/components/parameters/StatisticsBypassCache'
      responses:
        '200':
          description: Leaderboard rows, best first.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticsTracksRow'
        '304':
          $ref: '#/components/responses/NotModified'
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '429':
          $ref: '#/components/responses/TooManyRequests'
  /api/stream:
    get:
      tags:
        - Statistics
        - 'Role: User'
      summary: Stream of what happens in the public channels
      description: |
        Server-Sent Events, for a site that shows RVRB's state and would otherwise poll for it. The response stays open. Each message is `id: <n>`, `event: <type>`, `data: <json>`, where the json is `{ id, type, at, data }`. A comment line (`: keep-alive`) is sent every 25 seconds. Only public channels are in it, and a vote is a count, never a person.

        Events:
        - `track-finished`: a track has been played and scored. `data` has `channelId`, `channelSlug`, `channelTitle`, `track` (title, artists, album, albumArt, isrc, lengthMs), `dj`, `votes` (dope, nope, star, boof), `score`, `listeners`, `playedAt`.
        - `stats-changed`: the statistics of a channel were updated (`channelId`, `channelSlug`). A leaderboard or a DJ's stats asked for now may say something new, so ask again with `If-None-Match`.

        Reconnect with the `Last-Event-ID` header (or `lastEventId`) set to the last id seen and what was missed is sent first, as far as the last 500 events kept by the server still have it. Events of the statistics routes carry an `ETag`; a request with `If-None-Match` that is still the answer is a 304 with no body.

        A person's JWT or any bot's api key may listen, up to 5 streams each at a time (429 with `Retry-After` after that). A bot key is a long lived credential: it does not expire as a login does.
      operationId: getStream
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - name: types
          in: query
          required: false
          description: Comma separated, of `track-finished` and `stats-changed`. All when not given.
          schema:
            type: string
        - name: channelId
          in: query
          required: false
          description: Comma separated channel ids or slugs. All public channels when not given.
          schema:
            type: string
        - name: lastEventId
          in: query
          required: false
          description: Like the `Last-Event-ID` header, for a client that cannot set one.
          schema:
            type: integer
      responses:
        '200':
          description: The stream.
          content:
            text/event-stream:
              schema:
                type: string
        '400':
          description: A type that is not known.
        '401':
          description: Missing or invalid token.
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '403':
          description: A bot api key no bot has.
        '429':
          description: Too many streams open for this login or bot (5), or too many requests. Wait for the seconds in `Retry-After`.
          headers:
            Retry-After:
              description: Seconds to wait before asking again.
              schema:
                type: integer
  /api/users:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Search users
      description: Case-insensitive regex match on userName or displayName; whitespace in the query matches any characters. Results are reduced (no email, settings, etc).
      operationId: searchUsers
      security:
        - bearerAuth: []
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
          description: Search text
        - name: nPerPage
          in: query
          schema:
            type: integer
            default: 16
        - name: page
          in: query
          schema:
            type: integer
            default: 0
          description: Zero-based page number
      responses:
        '200':
          description: One page of matching users
          content:
            application/json:
              schema:
                type: object
                properties:
                  count:
                    type: integer
                    description: Total matches
                  more:
                    type: boolean
                    description: True when there are further pages
                  users:
                    type: array
                    items:
                      $ref: '#/components/schemas/User'
        '400':
          $ref: '#/components/responses/UsersFastifyError'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Get your full user document
      description: Only the authenticated user may fetch their own document (403 otherwise).
      operationId: getUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: The complete user document (unreduced)
          content:
            application/json:
              schema:
                type: object
                description: Mongo user document
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
        '404':
          $ref: '#/components/responses/UsersFastifyError'
    patch:
      tags:
        - Users
        - 'Role: User'
      summary: Edit your account
      description: Only your own userId (403 otherwise). Updates the listed fields, applies `generalSettings` to every open connection of the user, pushes the new user to all of them (`updateUser` over the websocket) and refreshes the user list of each channel they are in. `displayName` is cut to 33 characters. Fields not listed are ignored; a body with none of them is a 400.
      operationId: editUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: Any of these fields
              properties:
                displayName:
                  type: string
                image:
                  type: string
                djImage:
                  type: string
                thumbsUpImage:
                  type: string
                thumbsDownImage:
                  type: string
                emailSettings:
                  type: object
                  additionalProperties: true
                queueSettings:
                  type: object
                  additionalProperties: true
                profileSettings:
                  type: object
                  additionalProperties: true
                chatSettings:
                  type: object
                  additionalProperties: true
                notificationSettings:
                  type: object
                  additionalProperties: true
                generalSettings:
                  type: object
                  additionalProperties: true
                links:
                  type: object
                  additionalProperties: true
                theme:
                  type: string
                bio:
                  type: string
                nativeNotifications:
                  type: object
                  additionalProperties: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: Nothing to update
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: userId is not the caller
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/users/{userId}/achievements:
    get:
      tags:
        - Achievements
        - 'Role: User'
      summary: List a user's earned achievements
      description: For each achievement the highest level whose goal is reached supplies title, description and icon; achievements with no level reached are omitted. A few are not counted as they happen, and their progress is worked out when asked for (the account age is the days since the account was made, and `updatedDate` is the day its level was reached).
      operationId: getUserAchievements
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Earned achievements
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    name:
                      type: string
                    updatedDate:
                      type: string
                      format: date-time
                    title:
                      type: string
                    description:
                      type: string
                    icon:
                      type: string
                    summary:
                      type: string
                      description: What the achievement counts
                    level:
                      type: integer
                      description: The level reached, from 1
                    tier:
                      type: integer
                      description: Which badge image to show, 1 to 4 by the level reached, and 5 (the crown) for the person who has the most of it and has reached the last level
                    crown:
                      type: boolean
                      description: Present and true when the person wears the crown (tier 5). The title and description are the crown's then
                    levels:
                      type: integer
                      description: How many levels the achievement has
                    progress:
                      type: integer
                      description: The count so far
                    next:
                      type: object
                      nullable: true
                      description: The next level to reach, or null at the top
                      properties:
                        title:
                          type: string
                        description:
                          type: string
                        goal:
                          type: integer
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/accounts:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: List the linked music service accounts
      description: The accounts at music services (Spotify, Apple Music, Tidal) that are linked to the caller, and which one this session was made with (`current`). Only for your own userId, else 403.
      operationId: getUserAccounts
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: The linked accounts
          content:
            application/json:
              schema:
                type: object
                properties:
                  available:
                    type: array
                    description: 'The music services this server is set up for (their keys are in its environment), which are the ones to offer'
                    items:
                      type: string
                      enum: [spotify, apple, tidal]
                  preview:
                    type: array
                    description: 'The music services that are on trial (`PREVIEW_PROVIDERS`) and set up: an account can be added at them, and they are shown as a beta. The login page offers them only to those who ask for them'
                    items:
                      type: string
                      enum: [spotify, apple, tidal]
                  accounts:
                    type: array
                    items:
                      type: object
                      properties:
                        provider:
                          type: string
                          enum: [spotify, apple, tidal]
                        externalId:
                          type: string
                          description: The account at the service (for Spotify, its uri; for Apple Music, the `sub` of Sign in with Apple). Only the user's own, which is all this route answers
                        displayName:
                          type: string
                        country:
                          type: string
                        linkedAt:
                          type: string
                          format: date-time
                        current:
                          type: boolean
                          description: True for the account this session was made with
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/users/{userId}/accounts/{provider}:
    delete:
      tags:
        - Users
        - 'Role: User'
      summary: Remove a linked music service account
      description: Takes the account away from the caller, with the login the server kept for it. The only account cannot be removed (409), nor the one this session was made with (409). Only for your own userId, else 403.
      operationId: deleteUserAccount
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - name: provider
          in: path
          required: true
          schema:
            type: string
            enum: [spotify, apple, tidal]
      responses:
        '204':
          description: Removed
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
        '404':
          description: User not found, or no account at that service is linked
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: It is the only account, or the one this session was made with
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/users/{userId}/accounts/{provider}/link:
    post:
      tags:
        - Users
        - 'Role: User'
      summary: Start adding a music service account
      description: Answers where to send the user to log in at the service and add that account to theirs, as `{ url }`; or, for a service whose login the page makes itself (Apple Music), what the page needs to do that (`mode`, `developerToken`, `clientId`, and the `state` to send with the result to `POST /api/login/apple`). The session stays as it is (to use the service, log out and log in with it). The login comes back to `/login/?linked=<provider>`, or to `/login/?linkError=account_in_use&provider=<provider>` when the account is another user's (users are not merged). Only for your own userId, else 403.
      operationId: linkUserAccount
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - name: provider
          in: path
          required: true
          schema:
            type: string
            enum: [spotify, apple, tidal]
      responses:
        '200':
          description: Where to send the user, or what the page needs
          content:
            application/json:
              schema:
                type: object
                properties:
                  url:
                    type: string
                    format: uri
                  mode:
                    type: string
                    enum: [musickit]
                    description: Present when the page makes the login itself
                  state:
                    type: string
                    description: A signed token for the login that is adding the account (valid ten minutes)
                  developerToken:
                    type: string
                    description: The Apple Music developer token to configure MusicKit JS with, for this origin
                  clientId:
                    type: string
                    description: The Services ID Sign in with Apple is set up with
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
        '404':
          description: There is no such music service
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '501':
          description: The server is not set up for that music service (see `available` in `GET /api/users/{userId}/accounts`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/users/{userId}/devices:
    post:
      tags:
        - Users
        - 'Role: User'
      summary: Register a native notification device
      description: Pushes the device onto the authenticated user's nativeNotifications.devices (the `userId` path value must be the caller's own id, else 403). The body is a JSON string that the server parses itself.
      operationId: addUserDevice
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      requestBody:
        required: true
        description: A JSON-encoded device object, sent as a string body (the shape is not validated)
        content:
          text/plain:
            schema:
              type: string
      responses:
        '200':
          description: The user document as it was before the update
          content:
            application/json:
              schema:
                type: object
                description: Mongo user document
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/following/{targetId}:
    put:
      tags:
        - Users
        - 'Role: User'
      summary: Follow a user
      description: Only for your own userId. Fails with 404 if the target does not exist or has blocked you, 400 if you target yourself. Awards achievements and notifies the target in the background.
      operationId: followUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          $ref: '#/components/responses/UsersFollowedResult'
        '400':
          $ref: '#/components/responses/UsersError'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersError'
        '404':
          $ref: '#/components/responses/UsersError'
        '500':
          $ref: '#/components/responses/UsersError'
    delete:
      tags:
        - Users
        - 'Role: User'
      summary: Unfollow a user
      description: Only for your own userId.
      operationId: unfollowUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          $ref: '#/components/responses/UsersFollowedResult'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersError'
        '500':
          $ref: '#/components/responses/UsersError'
  /api/users/{userId}/images:
    put:
      tags:
        - Users
        - 'Role: User'
      summary: Upload a user image
      description: Multipart upload (max 10 MB). Stores the picture as a 256 by 256 square webp (the part named by the crop fields, or the centre; a gif stays a moving image), sets the user field named by imageType to its /static/ path and deletes the previous file. Answers 403 when userId is not the caller's own id, before the upload is stored. It does not restrict imageType values (the client uses image, djImage, thumbsUpImage and thumbsDownImage).
      operationId: uploadUserImage
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - image
                - imageType
              properties:
                image:
                  type: string
                  format: binary
                imageType:
                  type: string
                  description: User field to set, e.g. image or djImage
                cropX:
                  type: number
                  description: Left edge of the part of the picture to keep, in its own pixels (the centre is kept without the four crop fields)
                cropY:
                  type: number
                cropWidth:
                  type: number
                cropHeight:
                  type: number
      responses:
        '200':
          description: An object with one key, named by imageType, holding the new /static/ path
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: string
                example:
                  image: /static/abc.png
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: The path userId is not the caller
          content:
            text/plain:
              schema:
                type: string
                example: Forbidden
        '500':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/profile:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Get your profile with social lists
      description: Upserts and returns the caller's ProfileSettings plus resolved followers, followed, blocked and muted users, which of them are online (with the channels they are in) and those channels. Only the caller's own id is allowed.
      operationId: getUserProfile
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Profile
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Profile'
                  - type: object
                    properties:
                      onlineFollowed:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                      onlineFollowers:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                      followers:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                        description: Offline followers
                      followedUsers:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                        description: Offline followed users
                      blockedUsers:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                      mutedUsers:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
                      muted:
                        type: array
                        items:
                          type: string
                        description: Muted user ids
                      channels:
                        type: array
                        items:
                          $ref: '#/components/schemas/Channel'
                        description: Channels online followed users are in (title, slug, djs, users only)
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
        '500':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/public:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Get a user's public profile
      description: Returns the reduced user. `self` is true when the caller requests their own id. When the user has `profileSettings.displayChannels` on, `channels` lists the channels they are a creator of, by title, leaving out deleted ones, ones that cannot be joined and ones the caller is banned from.
      operationId: getUserPublic
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Reduced user
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/User'
                  - type: object
                    properties:
                      self:
                        type: boolean
                      channels:
                        type: array
                        description: Only present when the user displays the channels they created.
                        items:
                          type: object
                          required:
                            - _id
                            - slug
                          properties:
                            _id:
                              type: string
                            slug:
                              type: string
                            title:
                              type: string
                            promoImageUrl:
                              type: string
                              description: The channel's banner (an image or YouTube address).
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '404':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/statistics:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Get play statistics
      description: Summed plays for today, this month, last month and all time, each with a computed score. Cached in Redis when available.
      operationId: getUserStatistics
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - name: bypassCache
          in: query
          schema:
            type: string
          description: Any value skips the Redis cache
      responses:
        '200':
          description: Statistics per period
          content:
            application/json:
              schema:
                type: object
                properties:
                  today:
                    $ref: '#/components/schemas/UsersStatisticsPeriod'
                  thismonth:
                    $ref: '#/components/schemas/UsersStatisticsPeriod'
                  lastmonth:
                    $ref: '#/components/schemas/UsersStatisticsPeriod'
                  alltime:
                    $ref: '#/components/schemas/UsersStatisticsPeriod'
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /api/users/{userId}/transactions:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: List your coin transactions
      description: Only your own id. Grouped transaction records with the type mapped to its name and, when another user is involved, their name.
      operationId: getUserTransactions
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Transactions
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  description: Grouped coinage transaction record (shape defined by the coinage database); type is the mapped name
                  properties:
                    type:
                      type: string
                    associatedUser:
                      type: string
                      nullable: true
                    userName:
                      type: string
                      description: Present when associatedUser is set
                  additionalProperties: true
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          $ref: '#/components/responses/UsersFastifyError'
  /api/users/{userId}/wallet:
    get:
      tags:
        - Users
        - 'Role: User'
      summary: Get a user's coin balance
      description: Any authenticated user can read any user's balance (profile pages show it); 0 when no wallet exists.
      operationId: getUserWallet
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
      responses:
        '200':
          description: Wallet
          content:
            application/json:
              schema:
                type: object
                properties:
                  coins:
                    type: number
        '401':
          $ref: '#/components/responses/UsersForbidden'
  /ws:
    get:
      tags:
        - System
        - 'Role: User'
      summary: Websocket upgrade for users
      description: Upgrades to a websocket carrying JSON-RPC 2.0 messages (see doc/rvrb-api.md). The user JWT goes in the `token` query parameter; an invalid token closes the socket right after the upgrade.
      operationId: websocketConnect
      security: []
      parameters:
        - name: token
          in: query
          required: true
          schema:
            type: string
          description: Session JWT
      responses:
        '101':
          description: Switching Protocols
  /ws-bot:
    get:
      tags:
        - System
        - 'Role: Bot only'
      summary: Websocket upgrade for bots
      description: Upgrades to a websocket carrying JSON-RPC 2.0 messages for bot users (see doc/rvrb-api.md). The bot's API key goes in the `apiKey` query parameter; an unknown key closes the socket right after the upgrade.
      operationId: websocketBotConnect
      security: []
      parameters:
        - name: apiKey
          in: query
          required: true
          schema:
            type: string
          description: Bot API key
      responses:
        '101':
          description: Switching Protocols
  /api/users/{userId}/blocked/{targetId}:
    put:
      tags:
        - Users
        - 'Role: User'
      summary: Block a user
      description: Only for your own userId. Adds the target to your blocked and muted lists, removes you from their followers, updates the blocked lists held on both users' open connections and refreshes the user list of the channels you are in. Send no body and no JSON content-type.
      operationId: blockUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: array
                    items:
                      type: string
                    description: The caller's blocked user ids after the change
        '400':
          description: You cannot block yourself
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: userId is not the caller
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The target user does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Users
        - 'Role: User'
      summary: Unblock a user
      description: Only for your own userId. Removes the target from your blocked list and updates the connections and channels as blocking does.
      operationId: unblockUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: array
                    items:
                      type: string
                    description: The caller's blocked user ids after the change
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: userId is not the caller
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/users/{userId}/muted/{targetId}:
    put:
      tags:
        - Users
        - 'Role: User'
      summary: Mute a user
      description: Only for your own userId. Adds the target to your muted chat list and pushes the updated user to all of your open connections. Send no body and no JSON content-type.
      operationId: muteUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: You cannot mute yourself
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: userId is not the caller
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The target user does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      tags:
        - Users
        - 'Role: User'
      summary: Unmute a user
      description: Only for your own userId. Removes the target from your muted chat list and pushes the updated user to all of your open connections.
      operationId: unmuteUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/UsersUserId'
        - $ref: '#/components/parameters/UsersTargetId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '403':
          description: userId is not the caller
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/devices/active:
    put:
      tags:
        - Music
        - 'Role: User'
      summary: Switch playback to a device
      description: Needs a Spotify login. Transfers playback to the device and starts it, then pushes `activePlayer` to every open connection of the user.
      operationId: selectPlayer
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - device_id
              properties:
                device_id:
                  type: string
                  description: Spotify device id
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '500':
          description: Spotify refused the switch, or the call failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/music/devices/volume:
    put:
      tags:
        - Music
        - 'Role: User'
      summary: Set the volume of a device
      description: Needs a Spotify login.
      operationId: setVolume
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - device_id
                - volume_percent
              properties:
                device_id:
                  type: string
                volume_percent:
                  type: integer
                  minimum: 0
                  maximum: 100
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/UsersForbidden'
        '500':
          description: Spotify refused the change, or the call failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/users/{userId}/role:
    put:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Change a user's role in the channel
      description: "Moderators and above. Roles: 0 guest, 3 mod, 5 admin, 10 creator. A caller cannot change a user whose role is above their own. Updates the channel's role lists and broadcasts `updateChannel` to the room. Does not remove the user from the room."
      operationId: changeUserRole
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The target user id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - role
              properties:
                role:
                  type: integer
                  enum:
                    - 0
                    - 3
                    - 5
                    - 10
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: Unknown role, or the user already has it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller lacks the role (plain text 'Not Authorized'), or the target's role is above theirs ('Unauthorized')
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
            text/plain:
              schema:
                type: string
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/users/{userId}:
    delete:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Kick a user out of the channel
      description: Moderators and above. The caller must outrank the target, or equal them when the channel has `sameRoleCanKick`. Removes every connection of the user from the room and sends them `leaveChannel`; they can rejoin.
      operationId: kickUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The target user id
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller lacks the role (plain text), or cannot kick that user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
            text/plain:
              schema:
                type: string
        '404':
          description: The channel is not loaded, or the user is not in it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/djs/{userId}:
    delete:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Take a user off the DJ list
      description: Moderators and above. The user stays in the room.
      operationId: kickDj
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The target user id
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
        '404':
          description: The channel is not loaded, or the user is not a DJ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/bans/{userId}:
    put:
      tags:
        - Channels
        - 'Role: Channel admin'
      summary: Ban a user from the channel
      description: Admins and above, and not above the caller's own role. Adds the user to the channel's banned list, removes their moderator roles, broadcasts `updateChannel` and removes them from the room. The ban is saved and answered as a success even when removing them from the room fails. Send no body and no JSON content-type.
      operationId: banUser
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The target user id
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: You cannot ban yourself
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller lacks the role (plain text), or cannot ban that user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
            text/plain:
              schema:
                type: string
        '404':
          description: The channel is not loaded, or the user is not in it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/chat/messages:
    delete:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Delete chat messages
      description: Moderators and above. Marks the messages with the given `syncTime`s (from the given user) as deleted, tells the room to remove them and posts an alert saying how many were deleted and by whom.
      operationId: deleteChatMessages
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - syncTime
              properties:
                syncTime:
                  oneOf:
                    - type: number
                    - type: array
                      items:
                        type: number
                  description: The syncTime of each message to delete
                userId:
                  type: string
                  description: The author of the messages
                userName:
                  type: string
                  description: Used in the alert when the author has no account
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: syncTime is missing or empty
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
        '404':
          description: The caller or the target user was not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/chat/archive:
    post:
      tags:
        - Channels
        - 'Role: Channel mod'
      summary: Save a copy of the chat
      description: Moderators and above. Keeps the live chat going and stores a copy under a timestamp version, then posts "Channel Chat Saved" about a second later. Send no body and no JSON content-type.
      operationId: archiveChat
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
        '404':
          description: The channel has no live chat
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/djs:
    put:
      tags:
        - Channels
        - Bot
        - 'Role: Channel mod'
      summary: Reorder the DJs
      description: Moderators and above, or the channel's external bot. Sorts the live DJ list by the order of the ids given and broadcasts the new list to the room. The channel has to be loaded (404 otherwise).
      operationId: updateDjs
      security:
        - bearerAuth: []
        - botApiKey: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - djs
              properties:
                djs:
                  type: array
                  items:
                    type: string
                  description: DJ user ids in the new order
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '400':
          description: djs is not an array
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is not a moderator (role 3 or higher) of this channel
          content:
            text/plain:
              schema:
                type: string
                example: Not Authorized
        '404':
          description: The channel is not loaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /api/channel/{channelId}/skip:
    post:
      tags:
        - Channels
        - 'Role: User'
      summary: Skip the track playing now
      description: "The current DJ, or a moderator or above. Starts the next DJ's next track; if that DJ does not answer in 2.5s they are removed from the queue and the skip still answers success. Counts as activity for the caller: their connections in this channel are marked as seen and not away, as the websocket call did. Send no body and no JSON content-type. The channel has to be loaded (404 otherwise)."
      operationId: skipChannelTrack
      security:
        - bearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ChannelId'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - result
                properties:
                  result:
                    type: object
                    description: Always empty
        '401':
          $ref: '#/components/responses/ChannelUnauthorized'
        '403':
          description: The caller is neither the current DJ nor a moderator (plain text "Not Authorized" if the channel does not exist)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: The channel is not loaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ChannelCreateRequest:
      type: object
      description: Channel settings. Either title or slug is required; other fields are checked by validateChannel.
      properties:
        title:
          type: string
        slug:
          type: string
      additionalProperties: true
    ChannelImageUpload:
      type: object
      required:
        - image
        - imageType
      properties:
        image:
          type: string
          format: binary
          description: Image file, at most 10 MB (image/jpeg, image/png, image/gif or image/webp)
        imageType:
          type: string
          enum:
            - image
            - djImage
            - thumbsUpImage
            - thumbsDownImage
          description: Which image to replace
        cropX:
          type: number
          description: Left edge of the part of the picture to keep, in its own pixels (the centre is kept without the four crop fields)
        cropY:
          type: number
        cropWidth:
          type: number
        cropHeight:
          type: number
    ChannelImageResult:
      type: object
      description: One property named after the uploaded imageType (image, djImage, thumbsUpImage or thumbsDownImage)
      additionalProperties:
        type: string
        description: Stored path, `/static/<file>`
      example:
        djImage: /static/abc_1700000000000_djImage.png
    ChannelEmptyResult:
      type: object
      properties:
        result:
          type: object
    ChannelBotOptions:
      type: object
      properties:
        commands:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              help:
                type: string
              options:
                description: Present on external bot commands
        personalities:
          type: array
          items: {}
        botAnswered:
          type: boolean
          description: Only when the bot is enabled. False when the bot process did not answer, so its commands are not in the list
    ChannelLastfm:
      type: object
      description: Last.fm settings. Only for role 5 or higher. The password, the session key and the API secret are never sent, only whether they are saved.
      properties:
        username:
          type: string
        api_key:
          type: string
        hasPassword:
          type: boolean
        hasSession:
          type: boolean
          description: The channel is connected by the user having approved the app on Last.fm
        hasApiSecret:
          type: boolean
    DiscordStatus:
      type: object
      description: Whether the channel's Discord link works, looked up when asked. Only for role 5 or higher. Also in the reply to an edit that sent `discord`, as `discordCheck`.
      properties:
        state:
          type: string
          enum:
            - off
            - connected
            - rejected
            - unavailable
          description: "`connected` is the bot being in the server and able to talk in the channel; `rejected` is a link that cannot work (`reason` says why); `unavailable` is the bot not running, which is for whoever runs the server to fix."
        reason:
          type: string
        serverName:
          type: string
          description: For connected.
        channelName:
          type: string
          description: For connected.
    ChannelAlias:
      type: object
      description: One response of an alias of a channel
      properties:
        id:
          type: string
        name:
          type: string
        value:
          type: string
    ChannelExternalBot:
      type: object
      description: A user document with type `bot`
      properties:
        _id:
          type: string
        userName:
          type: string
        displayName:
          type: string
        type:
          type: string
          enum:
            - bot
        channelId:
          type: string
        apiKey:
          type: string
        emailConfirmed:
          type: boolean
      additionalProperties: true
    ChannelChatDocument:
      type: object
      description: A ChannelChats document
      properties:
        channelId:
          type: string
        version:
          type: integer
        deleted:
          type: boolean
        chat:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
      additionalProperties: true
    ChannelHistoryEntry:
      type: object
      properties:
        track:
          type: object
          description: The track that was played
        voteSummary:
          type: object
          description: Votes the track received
        timestamp:
          type: number
        skipped:
          type: boolean
        playedBy:
          type: object
          description: Who played it (the bot's display name for bot plays)
          properties:
            userName:
              type: string
            displayName:
              type: string
    Event:
      type: object
      properties:
        _id:
          type: string
        slug:
          type: string
          description: The event's url id, `friday-night-k3f9x2`, which is the one to share (`/events/<slug>` in the web app)
        channelId:
          type: string
        channelSlug:
          type: string
        channelTitle:
          type: string
        channelArt:
          type: string
          description: The album art of the track the channel is playing, or played last, for an event that has no image of its own to show. An empty string when the channel has played nothing
        name:
          type: string
        description:
          type: string
        image:
          type: string
          description: '`/static/<file>`, or empty'
        timezone:
          type: string
          description: The zone the admin made it in. The times are instants; this is how they were meant
        slotMinutes:
          type: integer
          nullable: true
          minimum: 5
          maximum: 480
          description: How long a slot is, in whole minutes. null for an event with no reserved slots (open decks), which runs from a start to an end each day and anyone can play; it has no slots, no signups and no `maxSlotsPerUser`
        maxSlotsPerUser:
          type: integer
          nullable: true
          description: How many slots one person can take; null for no limit
        seriesId:
          type: string
          nullable: true
          description: The id the events of a series share, or null for an event that does not repeat
        recurrence:
          type: object
          nullable: true
          description: How the series repeats, or null
          properties:
            frequency:
              type: string
              enum:
                - weekly
                - monthly
            ordinal:
              type: integer
              description: For monthly, which weekday of the month it is on, 1 to 4, or -1 for the last
        days:
          type: array
          items:
            $ref: '#/components/schemas/EventDay'
        createdBy:
          type: string
        createdDate:
          type: string
          format: date-time
    EventListItem:
      allOf:
        - $ref: '#/components/schemas/Event'
        - type: object
          properties:
            slotCount:
              type: integer
              description: How many slots the days make
            signupCount:
              type: integer
              description: How many of them are taken
            trackCount:
              type: integer
              description: How many tracks were played in it, not counting the ones that were removed
            seriesRemaining:
              type: integer
              description: For the next event of a series that is listed once, how many of the series are still to come, this one included
    EventDay:
      type: object
      properties:
        startsAt:
          type: string
          format: date-time
        endsAt:
          type: string
          format: date-time
    EventSignup:
      type: object
      properties:
        startsAt:
          type: string
          format: date-time
          description: The start of the slot, which is how a slot is named
        userId:
          type: string
        username:
          type: string
          description: The name the person had when they signed up
        description:
          type: string
    EventPlaylistEntry:
      type: object
      properties:
        index:
          type: integer
          description: Its place in the stored list, which is how it is named to remove it or bring it back. Removed tracks keep their place
        startedAt:
          type: string
          format: date-time
        userId:
          type: string
          description: Who played it (`bot` for the channel's bot)
        username:
          type: string
        slotStartsAt:
          type: string
          format: date-time
          nullable: true
          description: The slot it began in, when the person who played it had that slot; null for what was played in any other slot, or outside the slots ("other plays")
        track:
          type: object
          description: A copy of the track, so one that the music service later drops still shows
          properties:
            id:
              type: string
            uri:
              type: string
            name:
              type: string
            artists:
              type: array
              items:
                type: string
            album:
              type: string
            image:
              type: string
            durationMs:
              type: integer
            provider:
              type: string
              description: The music service it is at (spotify, tidal, apple)
        votes:
          type: object
          description: The votes it ended with
          properties:
            up:
              type: integer
            down:
              type: integer
        skipped:
          type: boolean
        removedBy:
          type: string
          description: Only for a track that was removed
        removedAt:
          type: string
          format: date-time
          description: Only for a track that was removed
    EventPlaylist:
      type: object
      properties:
        playlist:
          type: array
          items:
            $ref: '#/components/schemas/EventPlaylistEntry'
        removedPlaylist:
          type: array
          description: Only for admins and owners of the channel
          items:
            $ref: '#/components/schemas/EventPlaylistEntry'
    EventSignups:
      type: object
      properties:
        signups:
          type: array
          items:
            $ref: '#/components/schemas/EventSignup'
    EventCreateRequest:
      type: object
      required:
        - name
        - slotMinutes
        - days
      properties:
        name:
          type: string
          maxLength: 80
        description:
          type: string
          maxLength: 2000
        timezone:
          type: string
          description: The zone the days were made in (default UTC). A series is worked out on the clock of this zone
        recurrence:
          type: string
          nullable: true
          enum:
            - weekly
            - monthly
            - null
          description: Repeats the days to the end of the first day's year, weekly or monthly on the first day's weekday of the month (see `ordinal`). The days of an event that repeats are within one week of the first, so none starts 7 or more dates after it, and none ends later than the time it starts a week on
        ordinal:
          type: integer
          nullable: true
          enum:
            - 1
            - 2
            - 3
            - 4
            - -1
            - null
          description: For monthly, which of its weekday in the month the first day is, 1 to 4 or -1 for the last; the first day has to be that one. Left out, it is worked out from the date (the last from the 29th on)
        slotMinutes:
          type: integer
          nullable: true
          minimum: 5
          maximum: 480
          description: Required. A whole number of minutes (the app offers 30, 45, 60, 90, 120 or any other in the range). null for an event with no reserved slots (open decks), which runs from a start to an end each day and anyone can play; `maxSlotsPerUser` is then ignored, and the playlist is kept by day
        maxSlotsPerUser:
          type: integer
          nullable: true
          minimum: 1
          default: 1
          description: One or more, or null for no limit
        days:
          type: array
          minItems: 1
          maxItems: 14
          description: Each has to end after it starts and in the future; they cannot overlap. At most 500 slots in all, and at least one
          items:
            $ref: '#/components/schemas/EventDay'
    EventUpdateRequest:
      type: object
      description: Only what can be changed. The days, times, slot length and how it repeats cannot
      properties:
        scope:
          type: string
          enum:
            - this
            - series
          default: this
          description: series changes the events of the series that are still to come as well
        name:
          type: string
          maxLength: 80
        description:
          type: string
          maxLength: 2000
        maxSlotsPerUser:
          type: integer
          nullable: true
          minimum: 1
    EventSignupRequest:
      type: object
      properties:
        description:
          type: string
          maxLength: 200
          description: What the person will play
    EventImageUpload:
      type: object
      required:
        - image
      properties:
        image:
          type: string
          format: binary
          description: Image file, at most 10 MB (image/jpeg, image/png, image/gif or image/webp)
        cropX:
          type: number
          description: Left edge of the part to keep
        cropY:
          type: number
          description: Top edge of the part to keep
        cropWidth:
          type: number
        cropHeight:
          type: number
    EventOverlapError:
      type: object
      description: The answer to making or renewing an event that overlaps another event of the channel. A channel has one event at a time, so it is refused and nothing is made. A date of a series that is in the way can be taken out alone with `DELETE /api/events/{eventId}` (the scope is that event only), and the request made again.
      properties:
        error:
          type: string
        conflictCount:
          type: integer
          description: How many events it overlaps in all
        conflicts:
          type: array
          description: The events it overlaps, soonest first, ten at most
          items:
            type: object
            properties:
              _id:
                type: string
              slug:
                type: string
              name:
                type: string
              startsAt:
                type: string
                format: date-time
                description: The start of the day of that event that is in the way
              endsAt:
                type: string
                format: date-time
              seriesId:
                type: string
                nullable: true
                description: Set when the event is a date of a series
              recurrence:
                type: object
                nullable: true
                properties:
                  frequency:
                    type: string
                    enum:
                      - weekly
                      - monthly
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human readable error message.
    Channel:
      type: object
      description: A channel as returned by reduceChannel. `password`, `lastfm` and `discord` are only present for callers with role 5 or higher.
      required:
        - _id
        - slug
      properties:
        _id:
          type: string
          description: Channel id.
        id:
          type: string
          description: Mongoose virtual id, same value as _id (present when virtuals are serialised).
        slug:
          type: string
          description: Unique channel handle.
        websocketEndpoint:
          type: string
        serverEndpoint:
          type: string
        genre:
          type: string
        title:
          type: string
        promoImageUrl:
          type: string
          description: A web address, or the path of a banner that was uploaded to this site (/static/...)
        promoImageHref:
          type: string
        infoLink:
          type: string
        writeStarredToPlaylist:
          type: boolean
          description: Write starred tracks to a playlist.
        starredPlaylist:
          type: string
          description: Playlist for starred tracks.
        writeBoofStarToPlaylist:
          type: boolean
        boofStarPlaylist:
          type: string
        writeThisIsPlaylist:
          type: boolean
        thisIsPlaylist:
          type: string
        greeting:
          type: string
          description: Greeting shown to users who join.
        channelCalendarLink:
          type: string
        deleted:
          type: boolean
        maxTurns:
          type: number
          description: Maximum consecutive turns a DJ may take.
        roles:
          type: object
          description: User ids by role.
          properties:
            mods:
              type: array
              items:
                type: string
            admins:
              type: array
              items:
                type: string
            creators:
              type: array
              items:
                type: string
        banned:
          type: array
          items:
            type: string
          description: Banned user ids.
        visibility:
          type: string
          description: Channel visibility, default `public`.
        nowPlaying:
          type: object
          additionalProperties: true
          description: Currently playing item (track details; available_markets removed).
        lastPlayed:
          type: object
          additionalProperties: true
          description: Previously played item (available_markets removed).
        limitDjs:
          type: boolean
        maxDjs:
          type: number
        maxBots:
          type: number
        users:
          type: array
          items: {}
          description: Users currently in the channel.
        djs:
          type: array
          items: {}
          description: Current DJ queue.
        djsTitle:
          type: string
        listenersTitle:
          type: string
        activeDjTitle:
          type: string
        chatPrompt:
          type: string
        chatFilter:
          description: Chat filter setting (untyped in the mongoose schema).
        password:
          type: string
          description: Channel password. Only for role 5 or higher.
        nojoin:
          type: boolean
        disableAutoReact:
          type: boolean
        disableAutoVote:
          type: boolean
        lastfm:
          $ref: '#/components/schemas/ChannelLastfm'
        lastfmStatus:
          type: object
          description: How the channel's own Last.fm login stands, as the last attempt to log in found (when the channel was loaded or its login changed). Only for role 5 or higher, and left out when the server does not know.
          properties:
            state:
              type: string
              enum:
                - off
                - checking
                - connected
                - rejected
                - unreachable
                - incomplete
              description: "`rejected` is Last.fm refusing the login (`reason` says why); `unreachable` is Last.fm not being asked, which says nothing about the login; `incomplete` is something missing, so Last.fm was not asked."
            reason:
              type: string
              description: What Last.fm said, or what is missing. For rejected, unreachable and incomplete.
            at:
              type: string
              format: date-time
        discord:
          type: object
          description: Discord integration. Only for role 5 or higher. The ids are the numbers Discord gives, both or neither; an edit with anything else is refused (400).
          properties:
            serverId:
              type: string
            channelId:
              type: string
            mode:
              type: string
              enum:
                - ''
                - 2way
                - commands
        discordStatus:
          $ref: '#/components/schemas/DiscordStatus'
        followers:
          type: array
          items:
            type: string
          description: Ids of users following the channel.
        sameRoleCanKick:
          type: boolean
        skipUnavailable:
          type: boolean
          default: false
          description: Skip a track, when it starts, that someone in the room cannot play (their music service has not got it, or a Spotify track is not available in their country), and tell the room why. After a few in a row the next track is played anyway, so a room that has nothing everyone can play is not skipped for ever. Off unless it is true.
        skipDownvoted:
          type: boolean
          default: false
          description: Skip the track playing when every person listening has given it a thumbs down (every user in the room who is not a bot and not the DJ whose track it is, and at least two of them; a thumbs down with a star does not count), and tell the room why. Bots need not vote, but the track is not skipped when a bot has given it a thumbs up or a star. Checked when a vote comes in and when someone leaves. Off unless it is true.
        announceModeration:
          type: boolean
          default: true
          description: Tell the staff (moderators and above) in the room, with an alert only they receive, when a user is promoted, demoted, kicked from the room or the decks, banned or unbanned. On unless it is false.
        cheerEffect:
          type: string
          enum:
            - none
            - confetti
            - fire
            - fireworks
            - embers
            - glow
            - emoji
          default: confetti
          description: What the player shows while about two thirds of the listeners have thumbed the track up. A channel with none saved is confetti.
        cheerEmoji:
          type: string
          default: "🎵"
          description: The emoji of the emoji cheer effect. One emoji, as a person sees it (a flag or a family is one).
        cheerDirection:
          type: string
          enum:
            - up
            - down
          default: up
          description: Which way the emoji of the emoji cheer effect goes, up from the bottom of the player or down from the top.
        jeerEffect:
          type: string
          enum:
            - none
            - confetti
            - fire
            - fireworks
            - embers
            - glow
            - emoji
          default: none
          description: What the player shows while about two thirds of the listeners have thumbed the track down (the votes down, less the votes up). A channel with none saved shows nothing.
        jeerEmoji:
          type: string
          default: "👎"
          description: The emoji of the emoji jeer effect. One emoji, as a person sees it.
        jeerDirection:
          type: string
          enum:
            - up
            - down
          default: down
          description: Which way the emoji of the emoji jeer effect goes, up from the bottom of the player or down from the top.
        createdDate:
          type: string
          format: date-time
        lastTouched:
          type: string
          format: date-time
    User:
      type: object
      description: A user as other users see it (output of reduceUser). Tokens, emails and private settings are never included.
      required:
        - _id
        - userName
      properties:
        _id:
          type: string
        id:
          type: string
          description: Mongoose virtual id, same value as _id.
        appleUserId:
          type: string
        image:
          type: string
          description: Avatar image URL.
        djImage:
          type: string
        thumbsUpImage:
          type: string
        thumbsDownImage:
          type: string
        country:
          type: string
          description: Only present when the user displays their country.
        deleted:
          type: boolean
        userName:
          type: string
        displayName:
          type: string
        lastAuthenticated:
          type: string
          format: date-time
        createdDate:
          type: string
          format: date-time
        lastTouched:
          type: string
          format: date-time
        accountCreated:
          type: string
          format: date-time
        profileSettings:
          type: object
          description: Only present when the user displays social sites.
          properties:
            displayCountry:
              type: boolean
            displaySocialSites:
              type: boolean
            displayChannels:
              type: boolean
            lastfm:
              type: string
            spotify:
              type: string
            instagram:
              type: string
            soundcloud:
              type: string
            twitter:
              type: string
        stats:
          type: object
          additionalProperties: true
        theme:
          type: string
          description: Default `dark`.
        bio:
          type: string
        nativeNotifications:
          type: object
          description: Registered devices are removed.
          properties:
            enabled:
              type: boolean
        siteAdmin:
          type: boolean
        logChats:
          type: boolean
        badge:
          type: string
        channelId:
          type: string
          description: For bot accounts, the channel the bot belongs to.
        type:
          type: string
          description: Account type, set for bot accounts.
    Profile:
      type: object
      description: A user's social profile settings (reduceProfile removes `__v`, `_id` and `blockedBy`).
      properties:
        userId:
          type: string
        displayLocation:
          type: boolean
        customLocation:
          type: string
        followed:
          type: array
          items:
            type: string
          description: Ids of users this user follows.
        followedBy:
          type: array
          items:
            type: string
        blocked:
          type: array
          items:
            type: string
        blockedBy:
          type: array
          items:
            type: string
          description: Removed by reduceProfile.
        followedChannels:
          type: array
          items:
            type: string
    Stack:
      type: object
      required:
        - _id
        - userId
        - name
        - activeQueue
        - type
      properties:
        _id:
          type: string
        userId:
          type: string
        name:
          type: string
        description:
          type: string
        tracks:
          type: array
          items:
            type: string
          description: Track identifiers.
        activeQueue:
          type: boolean
          description: Whether this is the user's general queue, which plays where a channel has no queue of theirs.
        channelId:
          type: string
          description: The channel this is the user's queue for, which plays there in place of the general queue. Absent for any other stack.
        deleted:
          type: boolean
        type:
          type: string
          description: Music service, e.g. spotify, apple, tidal.
        createdDate:
          type: string
          format: date-time
        modifiedDate:
          type: string
          format: date-time
    Notification:
      type: object
      required:
        - title
        - message
      properties:
        _id:
          type: string
        title:
          type: string
        message:
          type: string
        icon:
          type: string
        read:
          type: string
          format: date-time
          description: When the notification was read; absent if unread.
        relatedUser:
          type: object
          properties:
            id:
              type: string
            displayName:
              type: string
        relatedChannel:
          type: object
          properties:
            slug:
              type: string
            title:
              type: string
        type:
          type: string
        visualIndicator:
          type: string
        occurrences:
          type: integer
        createdDate:
          type: string
          format: date-time
    ChatMessage:
      type: object
      description: A chat message as stored in the channel chat log and returned by GET /api/channel/{channelId}/chat (inside `chat`, last CHAT_BUFFER messages, deleted ones filtered out).
      required:
        - deleted
        - userId
        - userName
        - type
        - syncTime
      properties:
        deleted:
          type: boolean
        userId:
          type: string
          description: Sender id; `server` or `bot` for system messages.
        userName:
          type: string
        type:
          type: string
          description: Message type, e.g. chat, whisper, botResponse, alert.
        payload:
          description: Message content (usually a string; tables and other types may be objects).
        expandable:
          type: boolean
        summary:
          type: string
        syncTime:
          type: integer
          format: int64
          description: Epoch milliseconds.
        fromUserId:
          type: string
        fromChannelId:
          type: string
        fromChannelName:
          type: string
        replyTo:
          type: string
    BotConfig:
      type: object
      properties:
        _id:
          type: string
        id:
          type: number
        channelId:
          type: string
        displayName:
          type: string
        image:
          type: string
        djImage:
          type: string
        thumbsUpImage:
          type: string
        thumbsDownImage:
          type: string
        enabled:
          type: boolean
        nowPlayingResponses:
          type: boolean
        keywordResponses:
          type: boolean
        announceUsers:
          type: boolean
        autoAnnounceFirsts:
          type: boolean
        personality:
          type: string
        commands:
          type: object
          additionalProperties: true
    MusicSnapshotError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        snapshot_id:
          type: string
          description: The `snapshot_id` sent in the request, echoed back (may be absent).
    StatisticsPosition:
      description: Icon name for the first ten places (`rvrb-crown`, `rvrb-two` ... `rvrb-ten`), otherwise the 1-based rank.
      oneOf:
        - type: string
        - type: integer
    StatisticsCasinoRow:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/StatisticsPosition'
        userId:
          type: string
        displayName:
          type: string
          description: Display name, user name, or `Unknown`.
        plays:
          type: integer
        allin:
          type: integer
        coinflip:
          type: integer
        craps:
          type: integer
        rps:
          type: integer
        slots:
          type: integer
        wins:
          type: integer
          description: Wins including big wins.
        win%:
          type: integer
        meh%:
          type: integer
        lose%:
          type: integer
    StatisticsDjRow:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/StatisticsPosition'
        userId:
          type: string
        displayName:
          type: string
          description: Display name, user name, or `Unknown`.
        spins:
          type: integer
        dopes:
          type: integer
        nopes:
          type: integer
        stars:
          type: integer
        boofStars:
          type: integer
        score:
          type: number
        ratio:
          type: string
          description: Score per spin, rounded to an integer, as a string.
        adjusted:
          type: number
    StatisticsFirstsRow:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/StatisticsPosition'
        userId:
          type: string
        displayName:
          type: string
          description: Display name, user name, or `Unknown`.
        count:
          type: integer
          description: Number of first plays in the period.
    StatisticsSpinsRow:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/StatisticsPosition'
        title:
          type: string
        artists:
          type: string
          description: Artist names joined with `, `.
        spins:
          type: integer
        score:
          type: number
        ratio:
          type: string
          description: Score per spin, rounded to an integer, as a string.
        adjusted:
          type: number
    StatisticsTracksRow:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/StatisticsPosition'
        title:
          type: string
        artists:
          type: string
          description: Artist names joined with `, `.
        spins:
          type: integer
        score:
          type: number
    UsersFastifyError:
      type: object
      description: Fastify's default error body for errors thrown with a status
      properties:
        statusCode:
          type: integer
        error:
          type: string
        message:
          type: string
    UsersStatisticsPeriod:
      type: object
      description: Summed plays for one period
      properties:
        dopes:
          type: number
        nopes:
          type: number
        stars:
          type: number
        boofs:
          type: number
        score:
          type: number
      additionalProperties: true
    UsersAdminConnection:
      type: object
      description: Summary of a websocket connection (mapWebsocketRef)
      properties:
        _id:
          type: string
          description: User id
        displayName:
          type: string
        ip:
          type: string
        created:
          type: number
        heartBeatsMissed:
          type: integer
        latency:
          type: integer
        joined:
          type: string
          description: Channel id the connection is in
        connId:
          type: string
        clientId:
          type: string
        closed:
          type: boolean
        mobile:
          type: boolean
        hidden:
          type: boolean
        sleeping:
          type: boolean
        lastPing:
          type: number
        lastSeen:
          type: number
        userAgent:
          type: string
        upgradeUserAgent:
          type: string
        webPlayerId:
          type: string
        timeUntilPingTimeout:
          type: number
        connections:
          type: integer
          description: Open connections for this user
        connKeys:
          type: array
          items:
            type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: The JWT is sent in the `authorization` header, with or without the `Bearer ` prefix.
    botApiKey:
      type: http
      scheme: bearer
      description: An external bot's API key (32 hex characters, returned when the bot is created), sent as ``authorization` header as `Bearer <key>`. It is accepted only for the channel the bot belongs to. A bot has the role the route asks for, whatever the channel's roles say; it is not checked against them.
  parameters:
    ChannelId:
      name: channelId
      in: path
      required: true
      schema:
        type: string
      description: Channel id. The channel's `_id` or its slug (handle) both work.
    EventId:
      name: eventId
      in: path
      required: true
      schema:
        type: string
      description: The event's slug (its url id) or its `_id`.
    EventPlaylistIndex:
      name: index
      in: path
      required: true
      schema:
        type: integer
        minimum: 0
      description: The `index` of the track in the event's playlist.
    EventPlaylistStartedAt:
      name: startedAt
      in: query
      required: false
      schema:
        type: string
        format: date-time
      description: The `startedAt` of the track, to name it by when it began instead of by `index`. When it is given it is used and `index` is ignored. The `index` of a track moves when the oldest tracks of a full playlist are dropped, so a client that loaded the playlist some time ago should send this.
    EventSlotStart:
      name: startsAt
      in: path
      required: true
      schema:
        type: string
        format: date-time
      description: The start of the slot, as in the event's days and slot length (`2026-11-13T20:00:00.000Z`, URL-encoded).
    AliasId:
      name: aliasId
      in: path
      required: true
      description: Id of the alias entry
      schema:
        type: string
    ChannelBotId:
      name: botId
      in: path
      required: true
      description: Id of the bot user
      schema:
        type: string
    StatisticsPeriod:
      name: period
      in: query
      description: Time window. Defaults to `thismonth`.
      schema:
        type: string
        enum:
          - today
          - thismonth
          - lastmonth
          - alltime
        default: thismonth
    StatisticsRecords:
      name: records
      in: query
      description: Number of rows to return (first N). Omitted or `all` returns every row.
      schema:
        type: string
        example: '10'
    StatisticsChannelId:
      name: channelId
      in: query
      description: Restrict the statistics to one channel.
      schema:
        type: string
    StatisticsBypassCache:
      name: bypassCache
      in: query
      description: Any non-empty value skips the Redis cached copy and rebuilds.
      schema:
        type: string
    StatisticsShowMyPosition:
      name: showMyPosition
      in: query
      description: Any non-empty value appends the caller's own row when they are not in the returned page (only if they rank below first place).
      schema:
        type: string
    UsersUserId:
      name: userId
      in: path
      required: true
      schema:
        type: string
      description: User id
    UsersTargetId:
      name: targetId
      in: path
      required: true
      schema:
        type: string
      description: Id of the user to (un)follow
  responses:
    TooManyRequests:
      description: The caller has made more requests than the rate limit allows (see the description of the api). Wait for the seconds in `Retry-After`.
      headers:
        Retry-After:
          description: Seconds to wait before asking again.
          schema:
            type: integer
        x-ratelimit-limit:
          description: Requests allowed in the time counted.
          schema:
            type: integer
        x-ratelimit-remaining:
          description: Requests left (0 here).
          schema:
            type: integer
        x-ratelimit-reset:
          description: Seconds until the count starts again.
          schema:
            type: integer
      content:
        application/json:
          schema:
            type: object
            properties:
              statusCode:
                type: integer
                example: 429
              error:
                type: string
                example: Too Many Requests
              message:
                type: string
    NotModified:
      description: The answer is the one the caller has (its `If-None-Match` is the `ETag` of what would be sent). No body.
    ChannelUnauthorized:
      description: Missing or invalid token
      content:
        text/plain:
          schema:
            type: string
            example: Forbidden
    ChannelNotAuthorized:
      description: Caller is not an admin of the channel
      content:
        text/plain:
          schema:
            type: string
            example: Not Authorized
    ChannelNotFound:
      description: Invalid channel id (or not allowed to see it); body is the plain error message
      content:
        text/plain:
          schema:
            type: string
    ChannelErrorBody:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ChannelServerError:
      description: Image rejected (unsupported type, unknown image type) or storing failed
      content:
        application/json:
          schema:
            type: object
            description: Error body produced by the app's error handler
    UsersForbidden:
      description: Missing or invalid bearer token (plain string "Forbidden")
      content:
        text/plain:
          schema:
            type: string
            example: Forbidden
    UsersAdminNotFound:
      description: Caller is not a site admin (plain string "Not Found")
      content:
        text/plain:
          schema:
            type: string
            example: Not Found
    UsersError:
      description: Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UsersFastifyError:
      description: Error thrown by the handler, serialised by fastify
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UsersFastifyError'
    UsersFollowedResult:
      description: The caller's updated list of followed user ids
      content:
        application/json:
          schema:
            type: object
            properties:
              result:
                type: array
                items:
                  type: string
