PeerTube/shared/extra-utils/videos/history-command.ts

60 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-08 16:21:42 +02:00
import { ResultList, Video } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class HistoryCommand extends AbstractCommand {
wathVideo (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
})
}
remove (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
})
}
}