123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import { pick } from '@shared/core-utils'
- import {
- ActorFollow,
- HttpStatusCode,
- ResultList,
- VideoChannel,
- VideoChannelCreate,
- VideoChannelCreateResult,
- VideoChannelUpdate,
- VideosImportInChannelCreate
- } from '@shared/models'
- import { unwrapBody } from '../requests'
- import { AbstractCommand, OverrideCommandOptions } from '../shared'
- export class ChannelsCommand extends AbstractCommand {
- list (options: OverrideCommandOptions & {
- start?: number
- count?: number
- sort?: string
- withStats?: boolean
- } = {}) {
- const path = '/api/v1/video-channels'
- return this.getRequestBody<ResultList<VideoChannel>>({
- ...options,
- path,
- query: pick(options, [ 'start', 'count', 'sort', 'withStats' ]),
- implicitToken: false,
- defaultExpectedStatus: HttpStatusCode.OK_200
- })
- }
- listByAccount (options: OverrideCommandOptions & {
- accountName: string
- start?: number
- count?: number
- sort?: string
- withStats?: boolean
- search?: string
- }) {
- const { accountName, sort = 'createdAt' } = options
- const path = '/api/v1/accounts/' + accountName + '/video-channels'
- return this.getRequestBody<ResultList<VideoChannel>>({
- ...options,
- path,
- query: { sort, ...pick(options, [ 'start', 'count', 'withStats', 'search' ]) },
- implicitToken: false,
- defaultExpectedStatus: HttpStatusCode.OK_200
- })
- }
- async create (options: OverrideCommandOptions & {
- attributes: Partial<VideoChannelCreate>
- }) {
- const path = '/api/v1/video-channels/'
- // Default attributes
- const defaultAttributes = {
- displayName: 'my super video channel',
- description: 'my super channel description',
- support: 'my super channel support'
- }
- const attributes = { ...defaultAttributes, ...options.attributes }
- const body = await unwrapBody<{ videoChannel: VideoChannelCreateResult }>(this.postBodyRequest({
- ...options,
- path,
- fields: attributes,
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.OK_200
- }))
- return body.videoChannel
- }
- update (options: OverrideCommandOptions & {
- channelName: string
- attributes: VideoChannelUpdate
- }) {
- const { channelName, attributes } = options
- const path = '/api/v1/video-channels/' + channelName
- return this.putBodyRequest({
- ...options,
- path,
- fields: attributes,
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
- })
- }
- delete (options: OverrideCommandOptions & {
- channelName: string
- }) {
- const path = '/api/v1/video-channels/' + options.channelName
- return this.deleteRequest({
- ...options,
- path,
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
- })
- }
- get (options: OverrideCommandOptions & {
- channelName: string
- }) {
- const path = '/api/v1/video-channels/' + options.channelName
- return this.getRequestBody<VideoChannel>({
- ...options,
- path,
- implicitToken: false,
- defaultExpectedStatus: HttpStatusCode.OK_200
- })
- }
- updateImage (options: OverrideCommandOptions & {
- fixture: string
- channelName: string | number
- type: 'avatar' | 'banner'
- }) {
- const { channelName, fixture, type } = options
- const path = `/api/v1/video-channels/${channelName}/${type}/pick`
- return this.updateImageRequest({
- ...options,
- path,
- fixture,
- fieldname: type + 'file',
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.OK_200
- })
- }
- deleteImage (options: OverrideCommandOptions & {
- channelName: string | number
- type: 'avatar' | 'banner'
- }) {
- const { channelName, type } = options
- const path = `/api/v1/video-channels/${channelName}/${type}`
- return this.deleteRequest({
- ...options,
- path,
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
- })
- }
- listFollowers (options: OverrideCommandOptions & {
- channelName: string
- start?: number
- count?: number
- sort?: string
- search?: string
- }) {
- const { channelName, start, count, sort, search } = options
- const path = '/api/v1/video-channels/' + channelName + '/followers'
- const query = { start, count, sort, search }
- return this.getRequestBody<ResultList<ActorFollow>>({
- ...options,
- path,
- query,
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.OK_200
- })
- }
- importVideos (options: OverrideCommandOptions & VideosImportInChannelCreate & {
- channelName: string
- }) {
- const { channelName, externalChannelUrl, videoChannelSyncId } = options
- const path = `/api/v1/video-channels/${channelName}/import-videos`
- return this.postBodyRequest({
- ...options,
- path,
- fields: { externalChannelUrl, videoChannelSyncId },
- implicitToken: true,
- defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
- })
- }
- }
|