// ---------------------------------------------------------------------------
function accountController (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)
}
async function accountFollowersController (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
const activityPubResult = await actorFollowers(req, account.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
async function accountFollowingController (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
const activityPubResult = await actorFollowing(req, account.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
async function accountPlaylistsController (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
const activityPubResult = await actorPlaylists(req, account)
return activityPubResponse(activityPubContextify(activityPubResult), res)
function getAccountVideoRate (rateType: VideoRateType) {
return (req: express.Request, res: express.Response) => {
- const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate
+ const accountVideoRate = res.locals.accountVideoRate
const byActor = accountVideoRate.Account.Actor
const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
async function videoController (req: express.Request, res: express.Response) {
// We need more attributes
- const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id)
+ const video = await VideoModel.loadForGetAPI(res.locals.video.id)
if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url)
}
async function videoAnnounceController (req: express.Request, res: express.Response) {
- const share = res.locals.videoShare as VideoShareModel
+ const share = res.locals.videoShare
if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url)
}
async function videoAnnouncesController (req: express.Request, res: express.Response) {
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const handler = async (start: number, count: number) => {
const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count)
}
async function videoLikesController (req: express.Request, res: express.Response) {
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
async function videoDislikesController (req: express.Request, res: express.Response) {
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
async function videoCommentsController (req: express.Request, res: express.Response) {
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const handler = async (start: number, count: number) => {
const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count)
}
async function videoChannelController (req: express.Request, res: express.Response) {
- const videoChannel: VideoChannelModel = res.locals.videoChannel
+ const videoChannel = res.locals.videoChannel
return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
}
async function videoChannelFollowersController (req: express.Request, res: express.Response) {
- const videoChannel: VideoChannelModel = res.locals.videoChannel
+ const videoChannel = res.locals.videoChannel
const activityPubResult = await actorFollowers(req, videoChannel.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
async function videoChannelFollowingController (req: express.Request, res: express.Response) {
- const videoChannel: VideoChannelModel = res.locals.videoChannel
+ const videoChannel = res.locals.videoChannel
const activityPubResult = await actorFollowing(req, videoChannel.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
async function videoCommentController (req: express.Request, res: express.Response) {
- const videoComment: VideoCommentModel = res.locals.videoComment
+ const videoComment = res.locals.videoComment
if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url)
}
async function videoRedundancyController (req: express.Request, res: express.Response) {
- const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy
+ const videoRedundancy = res.locals.videoRedundancy
if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
const serverActor = await getServerActor()
}
async function videoPlaylistController (req: express.Request, res: express.Response) {
- const playlist: VideoPlaylistModel = res.locals.videoPlaylist
+ const playlist = res.locals.videoPlaylist
// We need more attributes
playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId)
}
async function videoPlaylistElementController (req: express.Request, res: express.Response) {
- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement
+ const videoPlaylistElement = res.locals.videoPlaylistElement
const json = videoPlaylistElement.toActivityPubObject()
return activityPubResponse(activityPubContextify(json), res)
import { processActivities } from '../../lib/activitypub/process/process'
import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
-import { VideoChannelModel } from '../../models/video/video-channel'
-import { AccountModel } from '../../models/account/account'
import { queue } from 'async'
import { ActorModel } from '../../models/activitypub/actor'
activities = activities.filter(a => isActivityValid(a))
logger.debug('We keep %d activities.', activities.length, { activities })
- let accountOrChannel: VideoChannelModel | AccountModel
- if (res.locals.account) {
- accountOrChannel = res.locals.account
- } else if (res.locals.videoChannel) {
- accountOrChannel = res.locals.videoChannel
- }
+ const accountOrChannel = res.locals.account || res.locals.videoChannel
logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
// ---------------------------------------------------------------------------
async function outboxController (req: express.Request, res: express.Response) {
- const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel
+ const accountOrVideoChannel = res.locals.account || res.locals.videoChannel
const actor = accountOrVideoChannel.Actor
const actorOutboxUrl = actor.url + '/outbox'
import { JobQueue } from '../../lib/job-queue'
import { logger } from '../../helpers/logger'
import { VideoPlaylistModel } from '../../models/video/video-playlist'
-import { UserModel } from '../../models/account/user'
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
const accountsRouter = express.Router()
// ---------------------------------------------------------------------------
function getAccount (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
if (account.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } })
// Allow users to see their private/unlisted video playlists
let privateAndUnlisted = false
- if (res.locals.oauth && (res.locals.oauth.token.User as UserModel).Account.id === res.locals.account.id) {
+ if (res.locals.oauth && res.locals.oauth.token.User.Account.id === res.locals.account.id) {
privateAndUnlisted = true
}
}
async function listAccountVideos (req: express.Request, res: express.Response) {
- const account: AccountModel = res.locals.account
+ const account = res.locals.account
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
const resultList = await VideoModel.listForApi({
// ---------------------------------------------------------------------------
-function pong (req: express.Request, res: express.Response, next: express.NextFunction) {
+function pong (req: express.Request, res: express.Response) {
return res.send('pong').status(200).end()
}
// ---------------------------------------------------------------------------
-async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function listFollowing (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const resultList = await ActorFollowModel.listFollowingForApi(
serverActor.id,
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function listFollowers (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const resultList = await ActorFollowModel.listFollowersForApi(
serverActor.id,
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function followInstance (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function followInstance (req: express.Request, res: express.Response) {
const hosts = req.body.hosts as string[]
const follower = await getServerActor()
return res.status(204).end()
}
-async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) {
- const follow: ActorFollowModel = res.locals.follow
+async function removeFollow (req: express.Request, res: express.Response) {
+ const follow = res.locals.follow
await sequelizeTypescript.transaction(async t => {
if (follow.state === 'accepted') await sendUndoFollow(follow, t)
import { UserRight } from '../../../../shared/models/users'
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'
-import { ServerModel } from '../../../models/server/server'
import { removeRedundancyOf } from '../../../lib/redundancy'
import { logger } from '../../../helpers/logger'
// ---------------------------------------------------------------------------
-async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
- const server = res.locals.server as ServerModel
+async function updateRedundancy (req: express.Request, res: express.Response) {
+ const server = res.locals.server
server.redundancyAllowed = req.body.redundancyAllowed
unblockAccountByServerValidator,
unblockServerByServerValidator
} from '../../../middlewares/validators'
-import { AccountModel } from '../../../models/account/account'
import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist'
import { ServerBlocklistModel } from '../../../models/server/server-blocklist'
-import { ServerModel } from '../../../models/server/server'
import { UserRight } from '../../../../shared/models/users'
const serverBlocklistRouter = express.Router()
async function blockAccount (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
- const accountToBlock: AccountModel = res.locals.account
+ const accountToBlock = res.locals.account
await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id)
}
async function unblockAccount (req: express.Request, res: express.Response) {
- const accountBlock: AccountBlocklistModel = res.locals.accountBlock
+ const accountBlock = res.locals.accountBlock
await removeAccountFromBlocklist(accountBlock)
async function blockServer (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
- const serverToBlock: ServerModel = res.locals.server
+ const serverToBlock = res.locals.server
await addServerInBlocklist(serverActor.Account.id, serverToBlock.id)
}
async function unblockServer (req: express.Request, res: express.Response) {
- const serverBlock: ServerBlocklistModel = res.locals.serverBlock
+ const serverBlock = res.locals.serverBlock
await removeServerFromBlocklist(serverBlock)
return res.type('json').status(204).end()
}
-async function unblockUser (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user: UserModel = res.locals.user
+async function unblockUser (req: express.Request, res: express.Response) {
+ const user = res.locals.user
await changeUserBlock(res, user, false)
}
async function blockUser (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.user
+ const user = res.locals.user
const reason = req.body.reason
await changeUserBlock(res, user, true, reason)
}
function getUser (req: express.Request, res: express.Response) {
- return res.json((res.locals.user as UserModel).toFormattedJSON())
+ return res.json(res.locals.user.toFormattedJSON())
}
async function autocompleteUsers (req: express.Request, res: express.Response) {
}
async function removeUser (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.user
+ const user = res.locals.user
await user.destroy()
async function updateUser (req: express.Request, res: express.Response) {
const body: UserUpdate = req.body
- const userToUpdate = res.locals.user as UserModel
+ const userToUpdate = res.locals.user
const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON())
const roleChanged = body.role !== undefined && body.role !== userToUpdate.role
return res.sendStatus(204)
}
-async function askResetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.user as UserModel
+async function askResetUserPassword (req: express.Request, res: express.Response) {
+ const user = res.locals.user
const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)
const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString
return res.status(204).end()
}
-async function resetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.user as UserModel
+async function resetUserPassword (req: express.Request, res: express.Response) {
+ const user = res.locals.user
user.password = req.body.password
await user.save()
return
}
-async function askSendVerifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.user as UserModel
+async function askSendVerifyUserEmail (req: express.Request, res: express.Response) {
+ const user = res.locals.user
await sendVerifyUserEmail(user)
return res.status(204).end()
}
-async function verifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.user as UserModel
+async function verifyUserEmail (req: express.Request, res: express.Response) {
+ const user = res.locals.user
user.emailVerified = true
await user.save()
return res.status(204).end()
}
-function success (req: express.Request, res: express.Response, next: express.NextFunction) {
+function success (req: express.Request, res: express.Response) {
res.end()
}
// ---------------------------------------------------------------------------
-async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.oauth.token.User as UserModel
+async function getUserVideos (req: express.Request, res: express.Response) {
+ const user = res.locals.oauth.token.User
const resultList = await VideoModel.listUserVideosForApi(
user.Account.id,
req.query.start as number,
return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
}
-async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.oauth.token.User as UserModel
+async function getUserVideoImports (req: express.Request, res: express.Response) {
+ const user = res.locals.oauth.token.User
const resultList = await VideoImportModel.listUserVideoImportsForApi(
user.id,
req.query.start as number,
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function getUserInformation (req: express.Request, res: express.Response) {
// We did not load channels in res.locals.user
const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
return res.json(user.toFormattedJSON())
}
-async function getUserVideoQuotaUsed (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) {
// We did not load channels in res.locals.user
const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user)
return res.json(data)
}
-async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function getUserVideoRating (req: express.Request, res: express.Response) {
const videoId = res.locals.video.id
const accountId = +res.locals.oauth.token.User.Account.id
}
async function deleteMe (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
await user.destroy()
async function updateMe (req: express.Request, res: express.Response) {
const body: UserUpdateMe = req.body
- const user: UserModel = res.locals.oauth.token.user
+ const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
if (body.password !== undefined) user.password = body.password
async function updateMyAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
- const user: UserModel = res.locals.oauth.token.user
+ const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
const userAccount = await AccountModel.load(user.Account.id)
serversBlocklistSortValidator,
unblockServerByAccountValidator
} from '../../../middlewares/validators'
-import { UserModel } from '../../../models/account/user'
import { AccountModel } from '../../../models/account/account'
import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist'
// ---------------------------------------------------------------------------
async function listBlockedAccounts (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)
}
async function blockAccount (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
- const accountToBlock: AccountModel = res.locals.account
+ const user = res.locals.oauth.token.User
+ const accountToBlock = res.locals.account
await addAccountInBlocklist(user.Account.id, accountToBlock.id)
}
async function unblockAccount (req: express.Request, res: express.Response) {
- const accountBlock: AccountBlocklistModel = res.locals.accountBlock
+ const accountBlock = res.locals.accountBlock
await removeAccountFromBlocklist(accountBlock)
}
async function listBlockedServers (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)
}
async function blockServer (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
- const serverToBlock: ServerModel = res.locals.server
+ const user = res.locals.oauth.token.User
+ const serverToBlock = res.locals.server
await addServerInBlocklist(user.Account.id, serverToBlock.id)
}
async function unblockServer (req: express.Request, res: express.Response) {
- const serverBlock: ServerBlocklistModel = res.locals.serverBlock
+ const serverBlock = res.locals.serverBlock
await removeServerFromBlocklist(serverBlock)
// ---------------------------------------------------------------------------
async function listMyVideosHistory (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)
}
async function removeUserHistory (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const beforeDate = req.body.beforeDate || null
await sequelizeTypescript.transaction(t => {
setDefaultSort,
userNotificationsSortValidator
} from '../../../middlewares'
-import { UserModel } from '../../../models/account/user'
import { getFormattedObjects } from '../../../helpers/utils'
import { UserNotificationModel } from '../../../models/account/user-notification'
import { meRouter } from './me'
// ---------------------------------------------------------------------------
async function updateNotificationSettings (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
- const body = req.body
+ const user = res.locals.oauth.token.User
+ const body = req.body as UserNotificationSetting
const query = {
where: {
}
async function listUserNotifications (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread)
}
async function markAsReadUserNotifications (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
await UserNotificationModel.markAsRead(user.id, req.body.ids)
}
async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
await UserNotificationModel.markAllAsRead(user.id)
userSubscriptionGetValidator
} from '../../../middlewares'
import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators'
-import { UserModel } from '../../../models/account/user'
import { VideoModel } from '../../../models/video/video'
import { buildNSFWFilter } from '../../../helpers/express-utils'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
async function areSubscriptionsExist (req: express.Request, res: express.Response) {
const uris = req.query.uris as string[]
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const handles = uris.map(u => {
let [ name, host ] = u.split('@')
}
async function addUserSubscription (req: express.Request, res: express.Response) {
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const [ name, host ] = req.body.uri.split('@')
const payload = {
}
function getUserSubscription (req: express.Request, res: express.Response) {
- const subscription: ActorFollowModel = res.locals.subscription
+ const subscription = res.locals.subscription
return res.json(subscription.ActorFollowing.VideoChannel.toFormattedJSON())
}
async function deleteUserSubscription (req: express.Request, res: express.Response) {
- const subscription: ActorFollowModel = res.locals.subscription
+ const subscription = res.locals.subscription
await sequelizeTypescript.transaction(async t => {
return subscription.destroy({ transaction: t })
}
async function getUserSubscriptions (req: express.Request, res: express.Response) {
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const actorId = user.Account.Actor.id
const resultList = await ActorFollowModel.listSubscriptionsForApi(actorId, req.query.start, req.query.count, req.query.sort)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function getUserSubscriptionVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.oauth.token.User as UserModel
+async function getUserSubscriptionVideos (req: express.Request, res: express.Response) {
+ const user = res.locals.oauth.token.User
const resultList = await VideoModel.listForApi({
start: req.query.start,
count: req.query.count,
import * as express from 'express'
import { asyncMiddleware, authenticate } from '../../../middlewares'
-import { UserModel } from '../../../models/account/user'
import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {
const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10))
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)
import { updateActorAvatarFile } from '../../lib/avatar'
import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'
import { resetSequelizeInstance } from '../../helpers/database-utils'
-import { UserModel } from '../../models/account/user'
import { JobQueue } from '../../lib/job-queue'
import { VideoPlaylistModel } from '../../models/video/video-playlist'
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
// ---------------------------------------------------------------------------
-async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function listVideoChannels (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
const resultList = await VideoChannelModel.listForApi(serverActor.id, req.query.start, req.query.count, req.query.sort)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function updateVideoChannelAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
- const videoChannel = res.locals.videoChannel as VideoChannelModel
+ const videoChannel = res.locals.videoChannel
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())
const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel)
const videoChannelInfo: VideoChannelCreate = req.body
const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {
- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoChannel(videoChannelInfo, account, t)
})
}
async function updateVideoChannel (req: express.Request, res: express.Response) {
- const videoChannelInstance = res.locals.videoChannel as VideoChannelModel
+ const videoChannelInstance = res.locals.videoChannel
const videoChannelFieldsSave = videoChannelInstance.toJSON()
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())
const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
}
async function removeVideoChannel (req: express.Request, res: express.Response) {
- const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
+ const videoChannelInstance = res.locals.videoChannel
await sequelizeTypescript.transaction(async t => {
await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t)
return res.type('json').status(204).end()
}
-async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function getVideoChannel (req: express.Request, res: express.Response) {
const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)
if (videoChannelWithVideos.isOutdated()) {
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
- const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
+async function listVideoChannelVideos (req: express.Request, res: express.Response) {
+ const videoChannelInstance = res.locals.videoChannel
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
const resultList = await VideoModel.listForApi({
setDefaultPagination,
setDefaultSort
} from '../../middlewares'
-import { VideoChannelModel } from '../../models/video/video-channel'
import { videoPlaylistsSortValidator } from '../../middlewares/validators'
import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { CONFIG, MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
import { processImage } from '../../helpers/image-utils'
import { join } from 'path'
-import { UserModel } from '../../models/account/user'
import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
}
function getVideoPlaylist (req: express.Request, res: express.Response) {
- const videoPlaylist = res.locals.videoPlaylist as VideoPlaylistModel
+ const videoPlaylist = res.locals.videoPlaylist
return res.json(videoPlaylist.toFormattedJSON())
}
async function addVideoPlaylist (req: express.Request, res: express.Response) {
const videoPlaylistInfo: VideoPlaylistCreate = req.body
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const videoPlaylist = new VideoPlaylistModel({
name: videoPlaylistInfo.displayName,
videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object
if (videoPlaylistInfo.videoChannelId) {
- const videoChannel = res.locals.videoChannel as VideoChannelModel
+ const videoChannel = res.locals.videoChannel
videoPlaylist.videoChannelId = videoChannel.id
videoPlaylist.VideoChannel = videoChannel
}
async function updateVideoPlaylist (req: express.Request, res: express.Response) {
- const videoPlaylistInstance = res.locals.videoPlaylist as VideoPlaylistModel
+ const videoPlaylistInstance = res.locals.videoPlaylist
const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON()
const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate
const wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE
if (videoPlaylistInfoToUpdate.videoChannelId === null) {
videoPlaylistInstance.videoChannelId = null
} else {
- const videoChannel = res.locals.videoChannel as VideoChannelModel
+ const videoChannel = res.locals.videoChannel
videoPlaylistInstance.videoChannelId = videoChannel.id
videoPlaylistInstance.VideoChannel = videoChannel
}
async function removeVideoPlaylist (req: express.Request, res: express.Response) {
- const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylistInstance = res.locals.videoPlaylist
await sequelizeTypescript.transaction(async t => {
await videoPlaylistInstance.destroy({ transaction: t })
async function addVideoInPlaylist (req: express.Request, res: express.Response) {
const body: VideoPlaylistElementCreate = req.body
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
- const video: VideoModel = res.locals.video
+ const videoPlaylist = res.locals.videoPlaylist
+ const video = res.locals.video
const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => {
const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t)
async function updateVideoPlaylistElement (req: express.Request, res: express.Response) {
const body: VideoPlaylistElementUpdate = req.body
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement
+ const videoPlaylist = res.locals.videoPlaylist
+ const videoPlaylistElement = res.locals.videoPlaylistElement
const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => {
if (body.startTimestamp !== undefined) videoPlaylistElement.startTimestamp = body.startTimestamp
}
async function removeVideoFromPlaylist (req: express.Request, res: express.Response) {
- const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylistElement = res.locals.videoPlaylistElement
+ const videoPlaylist = res.locals.videoPlaylist
const positionToDelete = videoPlaylistElement.position
await sequelizeTypescript.transaction(async t => {
}
async function reorderVideosPlaylist (req: express.Request, res: express.Response) {
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylist = res.locals.videoPlaylist
const body: VideoPlaylistReorder = req.body
const start: number = body.startPosition
}
async function getVideoPlaylistVideos (req: express.Request, res: express.Response) {
- const videoPlaylistInstance: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylistInstance = res.locals.videoPlaylist
const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
const resultList = await VideoModel.listForApi({
videoAbuseUpdateValidator
} from '../../../middlewares'
import { AccountModel } from '../../../models/account/account'
-import { VideoModel } from '../../../models/video/video'
import { VideoAbuseModel } from '../../../models/video/video-abuse'
import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
-import { UserModel } from '../../../models/account/user'
import { Notifier } from '../../../lib/notifier'
import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag'
}
async function updateVideoAbuse (req: express.Request, res: express.Response) {
- const videoAbuse: VideoAbuseModel = res.locals.videoAbuse
+ const videoAbuse = res.locals.videoAbuse
if (req.body.moderationComment !== undefined) videoAbuse.moderationComment = req.body.moderationComment
if (req.body.state !== undefined) videoAbuse.state = req.body.state
}
async function deleteVideoAbuse (req: express.Request, res: express.Response) {
- const videoAbuse: VideoAbuseModel = res.locals.videoAbuse
+ const videoAbuse = res.locals.videoAbuse
await sequelizeTypescript.transaction(t => {
return videoAbuse.destroy({ transaction: t })
}
async function reportVideoAbuse (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.video as VideoModel
+ const videoInstance = res.locals.video
const body: VideoAbuseCreate = req.body
const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => {
- const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
const abuseToCreate = {
reporterAccountId: reporterAccount.id,
import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
import { sequelizeTypescript } from '../../../initializers'
import { Notifier } from '../../../lib/notifier'
-import { VideoModel } from '../../../models/video/video'
import { sendDeleteVideo } from '../../../lib/activitypub/send'
import { federateVideoIfNeeded } from '../../../lib/activitypub'
}
async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
- const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
+ const videoBlacklist = res.locals.videoBlacklist
if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason
}
async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
- const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
- const video: VideoModel = res.locals.video
+ const videoBlacklist = res.locals.videoBlacklist
+ const video = res.locals.video
await sequelizeTypescript.transaction(async t => {
const unfederated = videoBlacklist.unfederated
import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers'
import { getFormattedObjects } from '../../../helpers/utils'
import { VideoCaptionModel } from '../../../models/video/video-caption'
-import { VideoModel } from '../../../models/video/video'
import { logger } from '../../../helpers/logger'
import { federateVideoIfNeeded } from '../../../lib/activitypub'
import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
async function addVideoCaption (req: express.Request, res: express.Response) {
const videoCaptionPhysicalFile = req.files['captionfile'][0]
- const video = res.locals.video as VideoModel
+ const video = res.locals.video
const videoCaption = new VideoCaptionModel({
videoId: video.id,
}
async function deleteVideoCaption (req: express.Request, res: express.Response) {
- const video = res.locals.video as VideoModel
- const videoCaption = res.locals.videoCaption as VideoCaptionModel
+ const video = res.locals.video
+ const videoCaption = res.locals.videoCaption
await sequelizeTypescript.transaction(async t => {
await videoCaption.destroy({ transaction: t })
import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
- authenticate, optionalAuthenticate,
+ authenticate,
+ optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort
removeVideoCommentValidator,
videoCommentThreadsSortValidator
} from '../../../middlewares/validators'
-import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
import { AccountModel } from '../../../models/account/account'
-import { UserModel } from '../../../models/account/user'
import { Notifier } from '../../../lib/notifier'
const auditLogger = auditLoggerFactory('comments')
// ---------------------------------------------------------------------------
-async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = res.locals.video as VideoModel
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+async function listVideoThreads (req: express.Request, res: express.Response) {
+ const video = res.locals.video
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
let resultList: ResultList<VideoCommentModel>
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = res.locals.video as VideoModel
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+async function listVideoThreadComments (req: express.Request, res: express.Response) {
+ const video = res.locals.video
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
let resultList: ResultList<VideoCommentModel>
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoComment({
text: videoCommentInfo.text,
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoComment({
text: videoCommentInfo.text,
}
async function removeVideoComment (req: express.Request, res: express.Response) {
- const videoCommentInstance: VideoCommentModel = res.locals.videoComment
+ const videoCommentInstance = res.locals.videoComment
await sequelizeTypescript.transaction(async t => {
await videoCommentInstance.destroy({ transaction: t })
state: VideoImportState.PENDING,
userId: user.id
}
- const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
+ const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
// Create job to import the video
const payload = {
state: VideoImportState.PENDING,
userId: user.id
}
- const videoImport: VideoImportModel = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
+ const videoImport = await insertIntoDB(video, res.locals.videoChannel, tags, videoImportAttributes)
// Create job to import the video
const payload = {
}
async function updateVideo (req: express.Request, res: express.Response) {
- const videoInstance: VideoModel = res.locals.video
+ const videoInstance = res.locals.video
const videoFieldsSave = videoInstance.toJSON()
const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
const videoInfoToUpdate: VideoUpdate = req.body
async function getVideo (req: express.Request, res: express.Response) {
// We need more attributes
const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null
- const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)
+ const video = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)
if (video.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
}
async function removeVideo (req: express.Request, res: express.Response) {
- const videoInstance: VideoModel = res.locals.video
+ const videoInstance = res.locals.video
await sequelizeTypescript.transaction(async t => {
await videoInstance.destroy({ transaction: t })
videosChangeOwnershipValidator,
videosTerminateChangeOwnershipValidator
} from '../../../middlewares'
-import { AccountModel } from '../../../models/account/account'
-import { VideoModel } from '../../../models/video/video'
import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos'
import { VideoChannelModel } from '../../../models/video/video-channel'
// ---------------------------------------------------------------------------
async function giveVideoOwnership (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.video as VideoModel
- const initiatorAccountId = (res.locals.oauth.token.User as UserModel).Account.id
- const nextOwner = res.locals.nextOwner as AccountModel
+ const videoInstance = res.locals.video
+ const initiatorAccountId = res.locals.oauth.token.User.Account.id
+ const nextOwner = res.locals.nextOwner
await sequelizeTypescript.transaction(t => {
return VideoChangeOwnershipModel.findOrCreate({
}
async function listVideoOwnership (req: express.Request, res: express.Response) {
- const currentAccountId = (res.locals.oauth.token.User as UserModel).Account.id
+ const currentAccountId = res.locals.oauth.token.User.Account.id
const resultList = await VideoChangeOwnershipModel.listForApi(
currentAccountId,
async function acceptOwnership (req: express.Request, res: express.Response) {
return sequelizeTypescript.transaction(async t => {
- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
+ const videoChangeOwnership = res.locals.videoChangeOwnership
const targetVideo = videoChangeOwnership.Video
- const channel = res.locals.videoChannel as VideoChannelModel
+ const channel = res.locals.videoChannel
const oldVideoChannel = await VideoChannelModel.loadByIdAndPopulateAccount(targetVideo.channelId)
async function refuseOwnership (req: express.Request, res: express.Response) {
return sequelizeTypescript.transaction(async t => {
- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
+ const videoChangeOwnership = res.locals.videoChangeOwnership
videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED)
await videoChangeOwnership.save({ transaction: t })
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares'
import { AccountModel } from '../../../models/account/account'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
-import { VideoModel } from '../../../models/video/video'
const rateVideoRouter = express.Router()
async function rateVideo (req: express.Request, res: express.Response) {
const body: UserVideoRateUpdate = req.body
const rateType = body.rating
- const videoInstance: VideoModel = res.locals.video
- const userAccount: AccountModel = res.locals.oauth.token.User.Account
+ const videoInstance = res.locals.video
+ const userAccount = res.locals.oauth.token.User.Account
await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t }
// ---------------------------------------------------------------------------
async function userWatchVideo (req: express.Request, res: express.Response) {
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const body: UserWatchingVideo = req.body
const { id: videoId } = res.locals.video as { id: number }
} from '../middlewares'
import { VideoModel } from '../models/video/video'
import * as Feed from 'pfeed'
-import { AccountModel } from '../models/account/account'
import { cacheRoute } from '../middlewares/cache'
-import { VideoChannelModel } from '../models/video/video-channel'
import { VideoCommentModel } from '../models/video/video-comment'
import { buildNSFWFilter } from '../helpers/express-utils'
// ---------------------------------------------------------------------------
-async function generateVideoCommentsFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function generateVideoCommentsFeed (req: express.Request, res: express.Response) {
const start = 0
- const video = res.locals.video as VideoModel
+ const video = res.locals.video
const videoId: number = video ? video.id : undefined
const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId)
return sendFeed(feed, req, res)
}
-async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function generateVideoFeed (req: express.Request, res: express.Response) {
const start = 0
- const account: AccountModel = res.locals.account
- const videoChannel: VideoChannelModel = res.locals.videoChannel
+ const account = res.locals.account
+ const videoChannel = res.locals.videoChannel
const nsfw = buildNSFWFilter(res, req.query.nsfw)
let name: string
// ---------------------------------------------------------------------------
-function generateOEmbed (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = res.locals.video as VideoModel
+function generateOEmbed (req: express.Request, res: express.Response) {
+ const video = res.locals.video
const webserverUrl = CONFIG.WEBSERVER.URL
const maxHeight = parseInt(req.query.maxheight, 10)
const maxWidth = parseInt(req.query.maxwidth, 10)
function getVideoAndFile (req: express.Request, res: express.Response) {
const resolution = parseInt(req.params.resolution, 10)
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const videoFile = video.VideoFiles.find(f => f.resolution === resolution)
import * as express from 'express'
import { asyncMiddleware } from '../middlewares'
import { webfingerValidator } from '../middlewares/validators'
-import { ActorModel } from '../models/activitypub/actor'
const webfingerRouter = express.Router()
// ---------------------------------------------------------------------------
-function webfingerController (req: express.Request, res: express.Response, next: express.NextFunction) {
- const actor = res.locals.actor as ActorModel
+function webfingerController (req: express.Request, res: express.Response) {
+ const actor = res.locals.actor
const json = {
subject: req.query.resource,
import { deleteFileAsync, generateRandomString } from './utils'
import { extname } from 'path'
import { isArray } from './custom-validators/misc'
-import { UserModel } from '../models/account/user'
function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
if (paramNSFW === 'true') return true
if (paramNSFW === 'both') return undefined
if (res && res.locals.oauth) {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
// User does not want NSFW videos
if (user.nsfwPolicy === 'do_not_list') return false
}
function isUserAbleToSearchRemoteURI (res: express.Response) {
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
return CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true ||
(CONFIG.SEARCH.REMOTE_URI.USERS === true && user !== undefined)
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers'
import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'
-import { ActorModel } from '../models/activitypub/actor'
import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
async function checkSignature (req: Request, res: Response, next: NextFunction) {
const httpSignatureChecked = await checkHttpSignature(req, res)
if (httpSignatureChecked !== true) return
- const actor: ActorModel = res.locals.signature.actor
+ const actor = res.locals.signature.actor
// Forwarded activity
const bodyActor = req.body.actor
import 'express-validator'
import { UserRight } from '../../shared'
import { logger } from '../helpers/logger'
-import { UserModel } from '../models/account/user'
function ensureUserHasRight (userRight: UserRight) {
return function (req: express.Request, res: express.Response, next: express.NextFunction) {
- const user = res.locals.oauth.token.user as UserModel
+ const user = res.locals.oauth.token.user
if (user.hasRight(userRight) === false) {
const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`
logger.info(message)
import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
import { logger } from '../../../helpers/logger'
import { getServerActor } from '../../../helpers/utils'
-import { ActorModel } from '../../../models/activitypub/actor'
async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
logger.debug('Checking activity pub parameters')
}
const serverActor = await getServerActor()
- const remoteActor = res.locals.signature.actor as ActorModel
+ const remoteActor = res.locals.signature.actor
if (serverActor.id === remoteActor.id) {
logger.error('Receiving request in INBOX by ourselves!', req.body)
return res.status(409).end()
if (areValidationErrors(req, res)) return
if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const accountToBlock = res.locals.account
if (user.Account.id === accountToBlock.id) {
if (areValidationErrors(req, res)) return
if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
const targetAccount = res.locals.account
if (!await doesUnblockAccountExist(user.Account.id, targetAccount.id, res)) return
if (areValidationErrors(req, res)) return
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
if (!await doesUnblockServerExist(user.Account.id, req.params.host, res)) return
return next()
import * as express from 'express'
import 'express-validator'
-import { param, body } from 'express-validator/check'
+import { body, param } from 'express-validator/check'
import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
import { doesVideoExist } from '../../helpers/custom-validators/videos'
import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils'
-import { VideoModel } from '../../models/video/video'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
import { isHostValid } from '../../helpers/custom-validators/servers'
-import { getServerActor } from '../../helpers/utils'
-import { ActorFollowModel } from '../../models/activitypub/actor-follow'
-import { SERVER_ACTOR_NAME } from '../../initializers'
import { ServerModel } from '../../models/server/server'
const videoFileRedundancyGetValidator = [
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res)) return
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const videoFile = video.VideoFiles.find(f => {
return f.resolution === req.params.resolution && (!req.params.fps || f.fps === req.params.fps)
})
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res)) return
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType)
if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' })
import { areValidationErrors } from './utils'
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
-import { UserModel } from '../../models/account/user'
import { CONFIG } from '../../initializers'
import { toArray } from '../../helpers/custom-validators/misc'
let [ name, host ] = req.params.uri.split('@')
if (host === CONFIG.WEBSERVER.HOST) host = null
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host)
if (!subscription || !subscription.ActorFollowing.VideoChannel) {
isUserRoleValid,
isUserUsernameValid,
isUserVideoQuotaDailyValid,
- isUserVideoQuotaValid, isUserVideosHistoryEnabledValid
+ isUserVideoQuotaValid,
+ isUserVideosHistoryEnabledValid
} from '../../helpers/custom-validators/users'
import { doesVideoExist } from '../../helpers/custom-validators/videos'
import { logger } from '../../helpers/logger'
const deleteMeValidator = [
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- const user: UserModel = res.locals.oauth.token.User
+ const user = res.locals.oauth.token.User
if (user.username === 'root') {
return res.status(400)
.send({ error: 'You cannot delete your root account.' })
.end()
}
- const user: UserModel = res.locals.oauth.token.User
-
+ const user= res.locals.oauth.token.User
if (await user.isPasswordMatch(req.body.currentPassword) !== true) {
return res.status(401)
.send({ error: 'currentPassword is invalid.' })
if (areValidationErrors(req, res)) return
if (!await checkUserIdExist(req.params.id, res)) return
- const user = res.locals.user as UserModel
+ const user = res.locals.user
const redisVerificationString = await Redis.Instance.getResetPasswordLink(user.id)
if (redisVerificationString !== req.body.verificationString) {
if (areValidationErrors(req, res)) return
if (!await checkUserIdExist(req.params.id, res)) return
- const user = res.locals.user as UserModel
+ const user = res.locals.user
const redisVerificationString = await Redis.Instance.getVerifyEmailLink(user.id)
if (redisVerificationString !== req.body.verificationString) {
import { logger } from '../../../helpers/logger'
import { areValidationErrors } from '../utils'
import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
-import { VideoModel } from '../../../models/video/video'
const videosBlacklistRemoveValidator = [
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res)) return
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
if (req.body.unfederate === true && video.remote === true) {
return res
.status(409)
if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylist = res.locals.videoPlaylist
if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {
return res.status(400)
.json({ error: 'Cannot delete a watch later playlist.' })
if (!await doesVideoPlaylistExist(req.params.playlistId, res)) return
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylist = res.locals.videoPlaylist
// Video is unlisted, check we used the uuid to fetch it
if (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED) {
if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
await authenticatePromiseIfNeeded(req, res)
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : null
-
+ const user = res.locals.oauth ? res.locals.oauth.token.User : null
if (
!user ||
(videoPlaylist.OwnerAccount.userId !== user.id && !user.hasRight(UserRight.UPDATE_ANY_VIDEO_PLAYLIST))
if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return
if (!await doesVideoExist(req.body.videoId, res, 'only-video')) return
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
- const video: VideoModel = res.locals.video
+ const videoPlaylist = res.locals.videoPlaylist
+ const video = res.locals.video
const videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndVideo(videoPlaylist.id, video.id)
if (videoPlaylistElement) {
if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return
if (!await doesVideoExist(req.params.videoId, res, 'id')) return
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
- const video: VideoModel = res.locals.video
+ const videoPlaylist = res.locals.videoPlaylist
+ const video = res.locals.video
const videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndVideo(videoPlaylist.id, video.id)
if (!videoPlaylistElement) {
if (!await doesVideoPlaylistExist(req.params.playlistId, res, 'all')) return
- const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
+ const videoPlaylist = res.locals.videoPlaylist
if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, videoPlaylist, UserRight.UPDATE_ANY_VIDEO_PLAYLIST, res)) return
const nextPosition = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id)
import { logger } from '../../../helpers/logger'
import { VideoShareModel } from '../../../models/video/video-share'
import { areValidationErrors } from '../utils'
-import { VideoModel } from '../../../models/video/video'
const videosShareValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.id, res)) return
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
const share = await VideoShareModel.load(req.params.actorId, video.id)
if (!share) {
import { doesVideoExist } from '../../../helpers/custom-validators/videos'
import { areValidationErrors } from '../utils'
import { logger } from '../../../helpers/logger'
-import { UserModel } from '../../../models/account/user'
const videoWatchingValidator = [
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res, 'id')) return
- const user = res.locals.oauth.token.User as UserModel
+ const user = res.locals.oauth.token.User
if (user.videosHistoryEnabled === false) {
logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id)
return res.status(409).end()
])
async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
// Anybody can watch local videos
if (video.isOwned() === true) return next()
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.id, res, fetchType)) return
- const video: VideoModel = res.locals.video
+ const video = res.locals.video
// Video private or blacklisted
if (video.privacy === VideoPrivacy.PRIVATE || video.VideoBlacklist) {
await authenticatePromiseIfNeeded(req, res)
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : null
+ const user = res.locals.oauth ? res.locals.oauth.token.User : null
// Only the owner or a user that have blacklist rights can see the video
if (
return next()
},
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
+ const videoChangeOwnership = res.locals.videoChangeOwnership
if (videoChangeOwnership.status === VideoChangeOwnershipStatus.WAITING) {
return next()
if (!await doesVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return
const user = res.locals.oauth.token.User
- const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel
+ const videoChangeOwnership = res.locals.videoChangeOwnership
const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getOriginalFile())
if (isAble === false) {
res.status(403)
if (areValidationErrors(req, res)) return
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
if (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) {
res.status(401)
.json({ error: 'You are not allowed to see all local videos.' })
--- /dev/null
+import { VideoChannelModel } from '../models/video/video-channel'
+import { VideoPlaylistModel } from '../models/video/video-playlist'
+import { VideoPlaylistElementModel } from '../models/video/video-playlist-element'
+import { UserModel } from '../models/account/user'
+import { VideoModel } from '../models/video/video'
+import { AccountModel } from '../models/account/account'
+import { VideoChangeOwnershipModel } from '../models/video/video-change-ownership'
+import { ActorModel } from '../models/activitypub/actor'
+import { VideoCommentModel } from '../models/video/video-comment'
+import { VideoShareModel } from '../models/video/video-share'
+import { AccountVideoRateModel } from '../models/account/account-video-rate'
+import { ActorFollowModel } from '../models/activitypub/actor-follow'
+import { ServerModel } from '../models/server/server'
+import { VideoFileModel } from '../models/video/video-file'
+import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
+import { ServerBlocklistModel } from '../models/server/server-blocklist'
+import { AccountBlocklistModel } from '../models/account/account-blocklist'
+import { VideoImportModel } from '../models/video/video-import'
+import { VideoAbuseModel } from '../models/video/video-abuse'
+import { VideoBlacklistModel } from '../models/video/video-blacklist'
+import { VideoCaptionModel } from '../models/video/video-caption'
+import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
+
+declare module 'express' {
+
+ interface Response {
+ locals: {
+ video?: VideoModel
+ videoShare?: VideoShareModel
+ videoFile?: VideoFileModel
+
+ videoImport?: VideoImportModel
+
+ videoBlacklist?: VideoBlacklistModel
+
+ videoCaption?: VideoCaptionModel
+
+ videoAbuse?: VideoAbuseModel
+
+ videoStreamingPlaylist?: VideoStreamingPlaylistModel
+
+ videoChannel?: VideoChannelModel
+
+ videoPlaylist?: VideoPlaylistModel
+ videoPlaylistElement?: VideoPlaylistElementModel
+
+ accountVideoRate?: AccountVideoRateModel
+
+ videoComment?: VideoCommentModel
+ videoCommentThread?: VideoCommentModel
+
+ follow?: ActorFollowModel
+ subscription?: ActorFollowModel
+
+ nextOwner?: AccountModel
+ videoChangeOwnership?: VideoChangeOwnershipModel
+ account?: AccountModel
+ actor?: ActorModel
+ user?: UserModel
+
+ server?: ServerModel
+
+ videoRedundancy?: VideoRedundancyModel
+
+ accountBlock?: AccountBlocklistModel
+ serverBlock?: ServerBlocklistModel
+
+ oauth?: {
+ token: {
+ User: UserModel
+ user: UserModel
+ }
+ }
+
+ signature?: {
+ actor: ActorModel
+ }
+
+ authenticated?: boolean
+ }
+ }
+}
"es2016",
"es2017"
],
- "types": [
- "node",
- "chai-xml",
- "chai-json-schema"
- ]
+ "typeRoots": [ "node_modules/@types", "server/typings" ]
},
"exclude": [
"client/node_modules",