aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/server-commands/videos/history-command.ts
blob: e9dc634626f39a29da5d5be7c14c6551e355b571 (plain) (tree)
1
2
3
4
5
6
                                                                  



                                                                   
                                                 



































                                                          















                                                             














                                                          
import { HttpStatusCode, ResultList, Video } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

export class HistoryCommand extends AbstractCommand {

  watchVideo (options: OverrideCommandOptions & {
    videoId: number | string
    currentTime: number
  }) {
    const { videoId, currentTime } = options

    const path = '/api/v1/videos/' + videoId + '/watching'
    const fields = { currentTime }

    return this.putBodyRequest({
      ...options,

      path,
      fields,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  list (options: OverrideCommandOptions & {
    search?: string
  } = {}) {
    const { search } = options
    const path = '/api/v1/users/me/history/videos'

    return this.getRequestBody<ResultList<Video>>({
      ...options,

      path,
      query: {
        search
      },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  removeElement (options: OverrideCommandOptions & {
    videoId: number
  }) {
    const { videoId } = options
    const path = '/api/v1/users/me/history/videos/' + videoId

    return this.deleteRequest({
      ...options,

      path,
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }

  removeAll (options: OverrideCommandOptions & {
    beforeDate?: string
  } = {}) {
    const { beforeDate } = options
    const path = '/api/v1/users/me/history/videos/remove'

    return this.postBodyRequest({
      ...options,

      path,
      fields: { beforeDate },
      implicitToken: true,
      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
    })
  }
}