import * as express from 'express'
+import { Hooks } from '@server/lib/plugins/hooks'
import { getServerActor } from '@server/models/application/application'
import { MChannelAccountDefault } from '@server/types/models'
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
import { sequelizeTypescript } from '../../initializers/database'
import { setAsyncActorKeys } from '../../lib/activitypub/actor'
import { sendUpdateActor } from '../../lib/activitypub/send'
-import { updateActorAvatarFile } from '../../lib/avatar'
+import { deleteLocalActorAvatarFile, updateLocalActorAvatarFile } from '../../lib/avatar'
import { JobQueue } from '../../lib/job-queue'
import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
import {
asyncMiddleware(updateVideoChannelAvatar)
)
+videoChannelRouter.delete('/:nameWithHost/avatar',
+ authenticate,
+ // Check the rights
+ asyncMiddleware(videoChannelsUpdateValidator),
+ asyncMiddleware(deleteVideoChannelAvatar)
+)
+
videoChannelRouter.put('/:nameWithHost',
authenticate,
asyncMiddleware(videoChannelsUpdateValidator),
const videoChannel = res.locals.videoChannel
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())
- const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel)
+ const avatar = await updateLocalActorAvatarFile(videoChannel, avatarPhysicalFile)
auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys)
.end()
}
+async function deleteVideoChannelAvatar (req: express.Request, res: express.Response) {
+ const videoChannel = res.locals.videoChannel
+
+ await deleteLocalActorAvatarFile(videoChannel)
+
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+}
+
async function addVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInfo: VideoChannelCreate = req.body
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
const countVideos = getCountVideos(req)
- const resultList = await VideoModel.listForApi({
+ const apiOptions = await Hooks.wrapObject({
followerActorId,
start: req.query.start,
count: req.query.count,
videoChannelId: videoChannelInstance.id,
user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
countVideos
- })
+ }, 'filter:api.video-channels.videos.list.params')
+
+ const resultList = await Hooks.wrapPromiseFun(
+ VideoModel.listForApi,
+ apiOptions,
+ 'filter:api.video-channels.videos.list.result'
+ )
return res.json(getFormattedObjects(resultList.data, resultList.total))
}