From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- server/controllers/api/search.ts | 5 +++-- server/controllers/api/users/index.ts | 3 ++- server/controllers/api/users/me.ts | 2 +- server/controllers/api/users/my-history.ts | 1 - server/controllers/api/video-channel.ts | 2 +- server/controllers/api/video-playlist.ts | 36 +++++++++++++++--------------- server/controllers/api/videos/abuse.ts | 7 +++--- server/controllers/api/videos/blacklist.ts | 17 +++++++------- server/controllers/api/videos/captions.ts | 9 ++++---- server/controllers/api/videos/comment.ts | 17 ++++++-------- server/controllers/api/videos/import.ts | 34 +++++++++++++++------------- server/controllers/api/videos/index.ts | 15 +++++++------ server/controllers/api/videos/ownership.ts | 5 +++-- server/controllers/api/videos/rate.ts | 2 +- server/controllers/api/videos/watching.ts | 2 +- 15 files changed, 81 insertions(+), 76 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 9a1e30b83..7fef7c173 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts @@ -19,6 +19,7 @@ import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel import { logger } from '../../helpers/logger' import { VideoChannelModel } from '../../models/video/video-channel' import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' +import { MChannelAccountDefault, MVideoAccountAllFiles } from '../../typings/models' const searchRouter = express.Router() @@ -84,7 +85,7 @@ async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: expr } async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean, res: express.Response) { - let videoChannel: VideoChannelModel + let videoChannel: MChannelAccountDefault let uri = search if (isWebfingerSearch) { @@ -137,7 +138,7 @@ async function searchVideosDB (query: VideosSearchQuery, res: express.Response) } async function searchVideoURI (url: string, res: express.Response) { - let video: VideoModel + let video: MVideoAccountAllFiles // Check if we can fetch a remote video with the URL if (isUserAbleToSearchRemoteURI(res)) { diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index ae40e86f8..e6b678f3a 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -48,6 +48,7 @@ import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' import { UserRegister } from '../../../../shared/models/users/user-register.model' +import { MUser, MUserAccountDefault } from '@server/typings/models' const auditLogger = auditLoggerFactory('users') @@ -359,7 +360,7 @@ function success (req: express.Request, res: express.Response) { res.end() } -async function changeUserBlock (res: express.Response, user: UserModel, block: boolean, reason?: string) { +async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) user.blocked = block diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index e7ed3de64..af054f620 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -147,7 +147,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons } async function getUserVideoRating (req: express.Request, res: express.Response) { - const videoId = res.locals.video.id + const videoId = res.locals.videoId.id const accountId = +res.locals.oauth.token.User.Account.id const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 7025c0ff1..4da1f3496 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts @@ -7,7 +7,6 @@ import { setDefaultPagination, userHistoryRemoveValidator } from '../../../middlewares' -import { UserModel } from '../../../models/account/user' import { getFormattedObjects } from '../../../helpers/utils' import { UserVideoHistoryModel } from '../../../models/account/user-video-history' import { sequelizeTypescript } from '../../../initializers' diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 81a03a62b..2b6184a83 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -136,7 +136,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp async function addVideoChannel (req: express.Request, res: express.Response) { const videoChannelInfo: VideoChannelCreate = req.body - const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { + const videoChannelCreated = await sequelizeTypescript.transaction(async t => { const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) return createVideoChannel(videoChannelInfo, account, t) diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index bd454f553..d9f0ff925 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -40,7 +40,7 @@ import { JobQueue } from '../../lib/job-queue' import { CONFIG } from '../../initializers/config' import { sequelizeTypescript } from '../../initializers/database' import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail' -import { VideoModel } from '../../models/video/video' +import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/typings/models' const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) @@ -58,7 +58,7 @@ videoPlaylistRouter.get('/', ) videoPlaylistRouter.get('/:playlistId', - asyncMiddleware(videoPlaylistsGetValidator), + asyncMiddleware(videoPlaylistsGetValidator('summary')), getVideoPlaylist ) @@ -83,7 +83,7 @@ videoPlaylistRouter.delete('/:playlistId', ) videoPlaylistRouter.get('/:playlistId/videos', - asyncMiddleware(videoPlaylistsGetValidator), + asyncMiddleware(videoPlaylistsGetValidator('summary')), paginationValidator, setDefaultPagination, optionalAuthenticate, @@ -140,7 +140,7 @@ async function listVideoPlaylists (req: express.Request, res: express.Response) } function getVideoPlaylist (req: express.Request, res: express.Response) { - const videoPlaylist = res.locals.videoPlaylist + const videoPlaylist = res.locals.videoPlaylistSummary if (videoPlaylist.isOutdated()) { JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video-playlist', url: videoPlaylist.url } }) @@ -159,7 +159,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { description: videoPlaylistInfo.description, privacy: videoPlaylistInfo.privacy || VideoPlaylistPrivacy.PRIVATE, ownerAccountId: user.Account.id - }) + }) as MVideoPlaylistFull videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object @@ -175,8 +175,8 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist, false) : undefined - const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { - const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) + const videoPlaylistCreated = await sequelizeTypescript.transaction(async t => { + const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) as MVideoPlaylistFull if (thumbnailModel) { thumbnailModel.automaticallyGenerated = false @@ -201,7 +201,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { } async function updateVideoPlaylist (req: express.Request, res: express.Response) { - const videoPlaylistInstance = res.locals.videoPlaylist + const videoPlaylistInstance = res.locals.videoPlaylistFull const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON() const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate @@ -275,7 +275,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) } async function removeVideoPlaylist (req: express.Request, res: express.Response) { - const videoPlaylistInstance = res.locals.videoPlaylist + const videoPlaylistInstance = res.locals.videoPlaylistSummary await sequelizeTypescript.transaction(async t => { await videoPlaylistInstance.destroy({ transaction: t }) @@ -290,10 +290,10 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response) async function addVideoInPlaylist (req: express.Request, res: express.Response) { const body: VideoPlaylistElementCreate = req.body - const videoPlaylist = res.locals.videoPlaylist - const video = res.locals.video + const videoPlaylist = res.locals.videoPlaylistFull + const video = res.locals.onlyVideo - const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { + const playlistElement = await sequelizeTypescript.transaction(async t => { const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t) const playlistElement = await VideoPlaylistElementModel.create({ @@ -330,7 +330,7 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { const body: VideoPlaylistElementUpdate = req.body - const videoPlaylist = res.locals.videoPlaylist + const videoPlaylist = res.locals.videoPlaylistFull const videoPlaylistElement = res.locals.videoPlaylistElement const playlistElement: VideoPlaylistElementModel = await sequelizeTypescript.transaction(async t => { @@ -354,7 +354,7 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re async function removeVideoFromPlaylist (req: express.Request, res: express.Response) { const videoPlaylistElement = res.locals.videoPlaylistElement - const videoPlaylist = res.locals.videoPlaylist + const videoPlaylist = res.locals.videoPlaylistFull const positionToDelete = videoPlaylistElement.position await sequelizeTypescript.transaction(async t => { @@ -381,7 +381,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo } async function reorderVideosPlaylist (req: express.Request, res: express.Response) { - const videoPlaylist = res.locals.videoPlaylist + const videoPlaylist = res.locals.videoPlaylistFull const body: VideoPlaylistReorder = req.body const start: number = body.startPosition @@ -434,7 +434,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons } async function getVideoPlaylistVideos (req: express.Request, res: express.Response) { - const videoPlaylistInstance = res.locals.videoPlaylist + const videoPlaylistInstance = res.locals.videoPlaylistSummary const user = res.locals.oauth ? res.locals.oauth.token.User : undefined const server = await getServerActor() @@ -453,7 +453,7 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon return res.json(getFormattedObjects(resultList.data, resultList.total, options)) } -async function regeneratePlaylistThumbnail (videoPlaylist: VideoPlaylistModel) { +async function regeneratePlaylistThumbnail (videoPlaylist: MVideoPlaylistThumbnail) { await videoPlaylist.Thumbnail.destroy() videoPlaylist.Thumbnail = null @@ -461,7 +461,7 @@ async function regeneratePlaylistThumbnail (videoPlaylist: VideoPlaylistModel) { if (firstElement) await generateThumbnailForPlaylist(videoPlaylist, firstElement.Video) } -async function generateThumbnailForPlaylist (videoPlaylist: VideoPlaylistModel, video: VideoModel) { +async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbnail, video: MVideoThumbnail) { logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url) const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getMiniature().filename) diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 77808466c..39c841ffe 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -21,6 +21,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' import { Notifier } from '../../../lib/notifier' import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' +import { MVideoAbuseAccountVideo } from '../../../typings/models/video' const auditLogger = auditLoggerFactory('abuse') const abuseVideoRouter = express.Router() @@ -94,10 +95,10 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) { } async function reportVideoAbuse (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const body: VideoAbuseCreate = req.body - const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { + const videoAbuse = await sequelizeTypescript.transaction(async t => { const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) const abuseToCreate = { @@ -107,7 +108,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { state: VideoAbuseState.PENDING } - const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) + const videoAbuseInstance: MVideoAbuseAccountVideo = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) videoAbuseInstance.Video = videoInstance videoAbuseInstance.Account = reporterAccount diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 9ff494def..2a667480d 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import { VideoBlacklist, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' +import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { @@ -11,15 +11,16 @@ import { setBlacklistSort, setDefaultPagination, videosBlacklistAddValidator, + videosBlacklistFiltersValidator, videosBlacklistRemoveValidator, - videosBlacklistUpdateValidator, - videosBlacklistFiltersValidator + videosBlacklistUpdateValidator } from '../../../middlewares' import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { sequelizeTypescript } from '../../../initializers' import { Notifier } from '../../../lib/notifier' import { sendDeleteVideo } from '../../../lib/activitypub/send' import { federateVideoIfNeeded } from '../../../lib/activitypub' +import { MVideoBlacklistVideo } from '@server/typings/models' const blacklistRouter = express.Router() @@ -64,7 +65,7 @@ export { // --------------------------------------------------------------------------- async function addVideoToBlacklist (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const body: VideoBlacklistCreate = req.body const toCreate = { @@ -74,7 +75,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) type: VideoBlacklistType.MANUAL } - const blacklist = await VideoBlacklistModel.create(toCreate) + const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create(toCreate) blacklist.Video = videoInstance if (body.unfederate === true) { @@ -83,7 +84,7 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) Notifier.Instance.notifyOnVideoBlacklist(blacklist) - logger.info('Video %s blacklisted.', res.locals.video.uuid) + logger.info('Video %s blacklisted.', videoInstance.uuid) return res.type('json').status(204).end() } @@ -108,7 +109,7 @@ async function listBlacklist (req: express.Request, res: express.Response) { async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) { const videoBlacklist = res.locals.videoBlacklist - const video = res.locals.video + const video = res.locals.videoAll const videoBlacklistType = await sequelizeTypescript.transaction(async t => { const unfederated = videoBlacklist.unfederated @@ -135,7 +136,7 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex Notifier.Instance.notifyOnNewVideoIfNeeded(video) } - logger.info('Video %s removed from blacklist.', res.locals.video.uuid) + logger.info('Video %s removed from blacklist.', video.uuid) return res.type('json').status(204).end() } diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 44c255232..37481d12f 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts @@ -10,6 +10,7 @@ import { federateVideoIfNeeded } from '../../../lib/activitypub' import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' +import { MVideoCaptionVideo } from '@server/typings/models' const reqVideoCaptionAdd = createReqFiles( [ 'captionfile' ], @@ -46,19 +47,19 @@ export { // --------------------------------------------------------------------------- async function listVideoCaptions (req: express.Request, res: express.Response) { - const data = await VideoCaptionModel.listVideoCaptions(res.locals.video.id) + const data = await VideoCaptionModel.listVideoCaptions(res.locals.videoId.id) return res.json(getFormattedObjects(data, data.length)) } async function addVideoCaption (req: express.Request, res: express.Response) { const videoCaptionPhysicalFile = req.files['captionfile'][0] - const video = res.locals.video + const video = res.locals.videoAll const videoCaption = new VideoCaptionModel({ videoId: video.id, language: req.params.captionLanguage - }) + }) as MVideoCaptionVideo videoCaption.Video = video // Move physical file @@ -75,7 +76,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) { } async function deleteVideoCaption (req: express.Request, res: express.Response) { - const video = res.locals.video + const video = res.locals.videoAll const videoCaption = res.locals.videoCaption await sequelizeTypescript.transaction(async t => { diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index bc6d81a7c..b2b06b170 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -27,9 +27,6 @@ import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../. import { AccountModel } from '../../../models/account/account' import { Notifier } from '../../../lib/notifier' import { Hooks } from '../../../lib/plugins/hooks' -import { ActorModel } from '../../../models/activitypub/actor' -import { VideoChannelModel } from '../../../models/video/video-channel' -import { VideoModel } from '../../../models/video/video' import { sendDeleteVideoComment } from '../../../lib/activitypub/send' const auditLogger = auditLoggerFactory('comments') @@ -75,7 +72,7 @@ export { // --------------------------------------------------------------------------- async function listVideoThreads (req: express.Request, res: express.Response) { - const video = res.locals.video + const video = res.locals.onlyVideo const user = res.locals.oauth ? res.locals.oauth.token.User : undefined let resultList: ResultList @@ -86,7 +83,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { start: req.query.start, count: req.query.count, sort: req.query.sort, - user: user + user }, 'filter:api.video-threads.list.params') resultList = await Hooks.wrapPromiseFun( @@ -105,7 +102,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) { } async function listVideoThreadComments (req: express.Request, res: express.Response) { - const video = res.locals.video + const video = res.locals.onlyVideo const user = res.locals.oauth ? res.locals.oauth.token.User : undefined let resultList: ResultList @@ -141,7 +138,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons return createVideoComment({ text: videoCommentInfo.text, inReplyToComment: null, - video: res.locals.video, + video: res.locals.videoAll, account }, t) }) @@ -164,8 +161,8 @@ async function addVideoCommentReply (req: express.Request, res: express.Response return createVideoComment({ text: videoCommentInfo.text, - inReplyToComment: res.locals.videoComment, - video: res.locals.video, + inReplyToComment: res.locals.videoCommentFull, + video: res.locals.videoAll, account }, t) }) @@ -179,7 +176,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response } async function removeVideoComment (req: express.Request, res: express.Response) { - const videoCommentInstance = res.locals.videoComment + const videoCommentInstance = res.locals.videoCommentFull await sequelizeTypescript.transaction(async t => { await videoCommentInstance.destroy({ transaction: t }) diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 04c9b547b..adc2f9aa2 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -15,7 +15,6 @@ import { VideoImportModel } from '../../../models/video/video-import' import { JobQueue } from '../../../lib/job-queue/job-queue' import { join } from 'path' import { isArray } from '../../../helpers/custom-validators/misc' -import { VideoChannelModel } from '../../../models/video/video-channel' import * as Bluebird from 'bluebird' import * as parseTorrent from 'parse-torrent' import { getSecureTorrentName } from '../../../helpers/utils' @@ -25,8 +24,14 @@ import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' -import { ThumbnailModel } from '../../../models/video/thumbnail' -import { UserModel } from '../../../models/account/user' +import { + MChannelActorAccountDefault, + MThumbnail, + MUser, + MVideoThumbnailAccountDefault, + MVideoWithBlacklistLight +} from '@server/typings/models' +import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' const auditLogger = auditLoggerFactory('video-imports') const videoImportsRouter = express.Router() @@ -225,28 +230,28 @@ async function processPreview (req: express.Request, video: VideoModel) { } function insertIntoDB (parameters: { - video: VideoModel, - thumbnailModel: ThumbnailModel, - previewModel: ThumbnailModel, - videoChannel: VideoChannelModel, + video: MVideoThumbnailAccountDefault, + thumbnailModel: MThumbnail, + previewModel: MThumbnail, + videoChannel: MChannelActorAccountDefault, tags: string[], - videoImportAttributes: Partial, - user: UserModel -}): Bluebird { + videoImportAttributes: Partial, + user: MUser +}): Bluebird { const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters return sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } // Save video object in database - const videoCreated = await video.save(sequelizeOptions) + const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight) videoCreated.VideoChannel = videoChannel if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) await autoBlacklistVideoIfNeeded({ - video, + video: videoCreated, user, notify: false, isRemote: false, @@ -259,16 +264,13 @@ function insertIntoDB (parameters: { const tagInstances = await TagModel.findOrCreateTags(tags, t) await videoCreated.$set('Tags', tagInstances, sequelizeOptions) - videoCreated.Tags = tagInstances - } else { - videoCreated.Tags = [] } // Create video import object in database const videoImport = await VideoImportModel.create( Object.assign({ videoId: videoCreated.id }, videoImportAttributes), sequelizeOptions - ) + ) as MVideoImportVideo videoImport.Video = videoCreated return videoImport diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 155ca4678..9af71d276 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -63,6 +63,7 @@ import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../ import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' import { Hooks } from '../../../lib/plugins/hooks' +import { MVideoFullLight } from '@server/typings/models' const auditLogger = auditLoggerFactory('videos') const videosRouter = express.Router() @@ -238,7 +239,7 @@ async function addVideo (req: express.Request, res: express.Response) { const { videoCreated } = await sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } - const videoCreated = await video.save(sequelizeOptions) + const videoCreated = await video.save(sequelizeOptions) as MVideoFullLight await videoCreated.addAndSaveThumbnail(thumbnailModel, t) await videoCreated.addAndSaveThumbnail(previewModel, t) @@ -318,7 +319,7 @@ async function addVideo (req: express.Request, res: express.Response) { } async function updateVideo (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const videoFieldsSave = videoInstance.toJSON() const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) const videoInfoToUpdate: VideoUpdate = req.body @@ -371,7 +372,7 @@ async function updateVideo (req: express.Request, res: express.Response) { } } - const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) + const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) as MVideoFullLight if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t) if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t) @@ -447,7 +448,7 @@ async function getVideo (req: express.Request, res: express.Response) { const video = await Hooks.wrapPromiseFun( VideoModel.loadForGetAPI, - { id: res.locals.video.id, userId }, + { id: res.locals.onlyVideoWithRights.id, userId }, 'filter:api.video.get.result' ) @@ -460,7 +461,7 @@ async function getVideo (req: express.Request, res: express.Response) { } async function viewVideo (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const ip = req.ip const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) @@ -483,7 +484,7 @@ async function viewVideo (req: express.Request, res: express.Response) { } async function getVideoDescription (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll let description = '' if (videoInstance.isOwned()) { @@ -522,7 +523,7 @@ async function listVideos (req: express.Request, res: express.Response) { } async function removeVideo (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll await sequelizeTypescript.transaction(async t => { await videoInstance.destroy({ transaction: t }) diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 5272c1385..abb34082e 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts @@ -18,6 +18,7 @@ import { getFormattedObjects } from '../../../helpers/utils' import { changeVideoChannelShare } from '../../../lib/activitypub' import { sendUpdateVideo } from '../../../lib/activitypub/send' import { VideoModel } from '../../../models/video/video' +import { MVideoFullLight } from '@server/typings/models' const ownershipVideoRouter = express.Router() @@ -56,7 +57,7 @@ export { // --------------------------------------------------------------------------- async function giveVideoOwnership (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const initiatorAccountId = res.locals.oauth.token.User.Account.id const nextOwner = res.locals.nextOwner @@ -107,7 +108,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) { targetVideo.channelId = channel.id - const targetVideoUpdated = await targetVideo.save({ transaction: t }) + const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight targetVideoUpdated.VideoChannel = channel if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) { diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index b65babedf..3d2f3d728 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts @@ -27,7 +27,7 @@ export { async function rateVideo (req: express.Request, res: express.Response) { const body: UserVideoRateUpdate = req.body const rateType = body.rating - const videoInstance = res.locals.video + const videoInstance = res.locals.videoAll const userAccount = res.locals.oauth.token.User.Account await sequelizeTypescript.transaction(async t => { diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts index dcd1f070d..036e16f3a 100644 --- a/server/controllers/api/videos/watching.ts +++ b/server/controllers/api/videos/watching.ts @@ -23,7 +23,7 @@ async function userWatchVideo (req: express.Request, res: express.Response) { const user = res.locals.oauth.token.User const body: UserWatchingVideo = req.body - const { id: videoId } = res.locals.video as { id: number } + const { id: videoId } = res.locals.videoId await UserVideoHistoryModel.upsert({ videoId, -- cgit v1.2.3