openapi: 3.0.3
info:
  title: Storage node API
  description: Storage node API
  contact:
    email: info@joystream.org
  license:
    name: GPL-3.0-only
    url: https://opensource.org/licenses/GPL-3.0
  version: 0.1.0
externalDocs:
  description: Storage node API
  url: https://github.com/Joystream/joystream/issues/2224
servers:
  - url: http://localhost:3333/api/v1/

tags:
  - name: files
    description: Storage node Files API
  - name: state
    description: Storage node State API

paths:
  /files/{id}:
    get:
      operationId: publicApi.getFile
      description: Returns a media file.
      tags:
        - files
      parameters:
        - name: id
          required: true
          in: path
          description: Data object ID
          schema:
            type: string
      responses:
        200:
          description: Ok
          content:
            video/*:
              schema:
                type: string
                format: binary
            audio/*:
              schema:
                type: string
                format: binary
            image/*:
              schema:
                type: string
                format: binary
            application/octet-stream:
              schema:
                type: string
                format: binary
        400:
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        401:
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        404:
          description: File not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        500:
          description: Unknown server error
    head:
      operationId: publicApi.getFileHeaders
      description: Returns a media file headers.
      tags:
        - files
      parameters:
        - name: id
          required: true
          in: path
          description: Data object ID
          schema:
            type: string
      responses:
        200:
          description: Ok
        400:
          description: Bad request
        404:
          description: File not found
        500:
          description: Unknown server error
  /files:
    post:
      security:
        - UploadAuth: []
      description: Upload data
      operationId: publicApi.uploadFile
      tags:
        - files
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - dataObjectId
                - storageBucketId
                - bagId
              properties:
                file:
                  description: Data file
                  type: string
                  format: binary
                dataObjectId:
                  description: Data object runtime ID
                  type: string
                  pattern: '^\d+$' #integer
                storageBucketId:
                  description: Storage bucket ID
                  type: string
                  pattern: '^\d+$' #integer
                bagId:
                  description: Bag ID
                  type: string
        required: true
      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
        400:
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        401:
          description: Unauthorized

  /authToken:
    post:
      description: Get auth token from a server.
      operationId: publicApi.authTokenForUploading
      tags:
        - files
      requestBody:
        description: Token request parameters,
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenRequest'
      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
        400:
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        401:
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

  /state/data-objects:
    get:
      operationId: stateApi.getAllLocalDataObjects
      description: Returns all local data objects.
      tags:
        - state
      responses:
        200:
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataObjectResponse'

  /state/bags/{bagId}/data-objects:
    get:
      operationId: stateApi.getLocalDataObjectsByBagId
      description: Returns local data objects for the bag.
      tags:
        - state
      parameters:
        - name: bagId
          required: true
          in: path
          description: Bag ID
          schema:
            type: string
      responses:
        200:
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataObjectResponse'

  /version:
    get:
      operationId: stateApi.getVersion
      description: Returns server version.
      tags:
        - state
      responses:
        200:
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VersionResponse'
  /state/data:
    get:
      operationId: stateApi.getLocalDataStats
      description: Returns local uploading directory stats.
      tags:
        - state
      responses:
        200:
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataStatsResponse'

components:
  securitySchemes:
    UploadAuth:
      type: apiKey
      in: header
      name: x-api-key
  schemas:
    TokenRequest:
      type: object
      required:
        - data
        - signature
      properties:
        data:
          type: object
          required:
            - memberId
            - accountId
            - dataObjectId
            - storageBucketId
            - bagId
          properties:
            memberId:
              type: integer
              format: int64
            accountId:
              type: string
            dataObjectId:
              type: integer
              format: int64
            storageBucketId:
              type: integer
              format: int64
            bagId:
              type: string
        signature:
          type: string
    ErrorResponse:
      type: object
      required:
        - message
      properties:
        type:
          type: string
        message:
          type: string
    DataStatsResponse:
      type: object
      required:
        - totalSize
        - objectNumber
      properties:
        totalSize:
          type: integer
          format: int64
        objectNumber:
          type: integer
          format: int64
        tempDirSize:
          type: integer
          format: int64
        tempDownloads:
          type: integer
          format: int64
    VersionResponse:
      type: object
      required:
        - version
      properties:
        version:
          type: string
        userAgent:
          type: string
    DataObjectResponse:
      type: array
      items:
        type: string
