From 0283eaac2a8e73006c66df3cf5bb9012e37450e5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 13:52:49 +0200 Subject: [PATCH] Cleanup model types --- server/controllers/api/search.ts | 4 +- server/controllers/api/videos/import.ts | 4 +- server/helpers/middlewares/video-channels.ts | 4 +- server/helpers/middlewares/videos.ts | 4 +- server/helpers/video.ts | 19 ++- server/lib/activitypub/actor.ts | 13 +- .../activitypub/process/process-announce.ts | 4 +- .../lib/activitypub/process/process-create.ts | 4 +- server/lib/activitypub/video-comments.ts | 4 +- server/lib/activitypub/videos.ts | 12 +- server/lib/avatar.ts | 4 +- server/lib/emailer.ts | 6 +- .../job-queue/handlers/activitypub-follow.ts | 17 ++- server/lib/job-queue/handlers/video-import.ts | 22 +-- server/lib/notifier.ts | 6 +- .../schedulers/videos-redundancy-scheduler.ts | 4 +- .../validators/videos/video-channels.ts | 5 +- .../middlewares/validators/videos/videos.ts | 6 +- server/models/account/user.ts | 4 +- server/models/video/video-channel.ts | 11 +- server/models/video/video.ts | 14 +- server/typings/express.ts | 4 +- .../models/account/account-blocklist.ts | 10 +- server/typings/models/account/account.ts | 69 ++++++--- server/typings/models/account/actor-follow.ts | 56 +++++-- server/typings/models/account/actor.ts | 93 ++++++++---- server/typings/models/index.d.ts | 1 + server/typings/models/oauth/index.d.ts | 2 + server/typings/models/oauth/oauth-token.ts | 6 +- .../typings/models/server/server-blocklist.ts | 10 +- server/typings/models/server/server.ts | 8 +- server/typings/models/user/index.d.ts | 1 + .../typings/models/user/user-notification.ts | 26 ++-- server/typings/models/user/user.ts | 49 ++++-- server/typings/models/video/index.d.ts | 4 + server/typings/models/video/video-abuse.ts | 14 +- .../typings/models/video/video-blacklist.ts | 8 +- server/typings/models/video/video-caption.ts | 8 +- .../models/video/video-change-ownership.ts | 10 +- server/typings/models/video/video-channels.ts | 95 +++++++----- server/typings/models/video/video-comment.ts | 38 +++-- server/typings/models/video/video-file.ts | 8 +- server/typings/models/video/video-import.ts | 23 ++- .../models/video/video-playlist-element.ts | 19 ++- server/typings/models/video/video-playlist.ts | 70 +++++++-- server/typings/models/video/video-rate.ts | 10 +- .../typings/models/video/video-redundancy.ts | 16 +- server/typings/models/video/video-share.ts | 11 +- .../models/video/video-streaming-playlist.ts | 8 +- server/typings/models/video/video.ts | 141 ++++++++++++------ 50 files changed, 668 insertions(+), 321 deletions(-) create mode 100644 server/typings/models/oauth/index.d.ts diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 7fef7c173..349650aca 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts @@ -19,7 +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' +import { MChannelAccountDefault, MVideoAccountLightBlacklistAllFiles } from '../../typings/models' const searchRouter = express.Router() @@ -138,7 +138,7 @@ async function searchVideosDB (query: VideosSearchQuery, res: express.Response) } async function searchVideoURI (url: string, res: express.Response) { - let video: MVideoAccountAllFiles + let video: MVideoAccountLightBlacklistAllFiles // Check if we can fetch a remote video with the URL if (isUserAbleToSearchRemoteURI(res)) { diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index a058b37ef..e7adcc35a 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -25,7 +25,7 @@ import { sequelizeTypescript } from '../../../initializers/database' import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { - MChannelActorAccountDefault, + MChannelAccountDefault, MThumbnail, MUser, MVideoTag, @@ -234,7 +234,7 @@ function insertIntoDB (parameters: { video: MVideoThumbnailAccountDefault, thumbnailModel: MThumbnail, previewModel: MThumbnail, - videoChannel: MChannelActorAccountDefault, + videoChannel: MChannelAccountDefault, tags: string[], videoImportAttributes: Partial, user: MUser diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts index 17b7692c5..1595ecd94 100644 --- a/server/helpers/middlewares/video-channels.ts +++ b/server/helpers/middlewares/video-channels.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { VideoChannelModel } from '../../models/video/video-channel' -import { MChannelActorAccountDefault } from '../../typings/models' +import { MChannelAccountDefault } from '@server/typings/models' async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) @@ -28,7 +28,7 @@ export { doesVideoChannelNameWithHostExist } -function processVideoChannelExist (videoChannel: MChannelActorAccountDefault, res: express.Response) { +function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) { if (!videoChannel) { res.status(404) .json({ error: 'Video channel not found' }) diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts index 964f0c91a..74f529804 100644 --- a/server/helpers/middlewares/videos.ts +++ b/server/helpers/middlewares/videos.ts @@ -2,7 +2,7 @@ import { Response } from 'express' import { fetchVideo, VideoFetchType } from '../video' import { UserRight } from '../../../shared/models/users' import { VideoChannelModel } from '../../models/video/video-channel' -import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoWithRights } from '@server/typings/models' +import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoThumbnail, MVideoWithRights } from '@server/typings/models' async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined @@ -27,7 +27,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi break case 'only-video': - res.locals.onlyVideo = video + res.locals.onlyVideo = video as MVideoThumbnail break case 'only-video-with-rights': diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 26a72ac5c..d066e2b1f 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts @@ -1,6 +1,12 @@ import { VideoModel } from '../models/video/video' import * as Bluebird from 'bluebird' -import { MVideoAccountAllFiles, MVideoFullLight, MVideoThumbnail, MVideoWithRights, MVideoIdThumbnail } from '@server/typings/models' +import { + MVideoAccountLightBlacklistAllFiles, + MVideoFullLight, + MVideoIdThumbnail, + MVideoThumbnail, + MVideoWithRights +} from '@server/typings/models' import { Response } from 'express' type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' @@ -30,10 +36,10 @@ function fetchVideo ( type VideoFetchByUrlType = 'all' | 'only-video' -function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird +function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird -function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird | Bluebird -function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird | Bluebird { +function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird +function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird { if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) if (fetchType === 'only-video') return VideoModel.loadByUrl(url) @@ -43,10 +49,15 @@ function getVideo (res: Response) { return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId } +function getVideoWithAttributes (res: Response) { + return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights +} + export { VideoFetchType, VideoFetchByUrlType, fetchVideo, getVideo, + getVideoWithAttributes, fetchVideoByUrl } diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 7862b0f00..5201bdeef 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -24,15 +24,17 @@ import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor' import { sequelizeTypescript } from '../../initializers/database' import { MAccount, + MAccountDefault, MActor, MActorAccountChannelId, + MActorAccountChannelIdActor, MActorAccountId, MActorDefault, MActorFull, + MActorFullActor, MActorId, - MActorAccountChannelIdActor, MChannel, - MActorFullActor, MAccountActorDefault, MChannelActorDefault, MChannelActorAccountDefault + MChannelAccountDefault } from '../../typings/models' // Set account keys, this could be long so process after the account creation and do not block the client @@ -374,12 +376,11 @@ function saveActorAndServerAndModelIfNotExist ( }) if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { - actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountActorDefault + actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountDefault actorCreated.Account.Actor = actorCreated } else if (actorCreated.type === 'Group') { // Video channel - actorCreated.VideoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t) as MChannelActorAccountDefault - actorCreated.VideoChannel.Actor = actorCreated - actorCreated.VideoChannel.Account = ownerActor.Account + const channel = await saveVideoChannel(actorCreated, result, ownerActor, t) + actorCreated.VideoChannel = Object.assign(channel, { Actor: actorCreated, Account: ownerActor.Account }) } actorCreated.Server = server diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 91a9ad72c..7e22125d5 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts @@ -7,7 +7,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos' import { Notifier } from '../../notifier' import { logger } from '../../../helpers/logger' import { APProcessorOptions } from '../../../typings/activitypub-processor.model' -import { MActorSignature, MVideoAccountAllFiles } from '../../../typings/models' +import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models' async function processAnnounceActivity (options: APProcessorOptions) { const { activity, byActor: actorAnnouncer } = options @@ -28,7 +28,7 @@ export { async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id - let video: MVideoAccountAllFiles + let video: MVideoAccountLightBlacklistAllFiles let videoCreated: boolean try { diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index c45f09f52..bee853721 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -11,7 +11,7 @@ import { Notifier } from '../../notifier' import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' import { createOrUpdateVideoPlaylist } from '../playlist' import { APProcessorOptions } from '../../../typings/activitypub-processor.model' -import { MActorSignature, MCommentOwnerVideo, MVideoAccountAllFiles } from '../../../typings/models' +import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models' async function processCreateActivity (options: APProcessorOptions) { const { activity, byActor } = options @@ -81,7 +81,7 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: MAc if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) - let video: MVideoAccountAllFiles + let video: MVideoAccountLightBlacklistAllFiles let created: boolean let comment: MCommentOwnerVideo try { diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index 375ac0aad..3e8306fa4 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts @@ -7,7 +7,7 @@ import { getOrCreateActorAndServerAndModel } from './actor' import { getOrCreateVideoAndAccountAndChannel } from './videos' import * as Bluebird from 'bluebird' import { checkUrlsSameHost } from '../../helpers/activitypub' -import { MCommentOwner, MCommentOwnerVideo, MVideoAccountAllFiles } from '../../typings/models/video' +import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../typings/models/video' type ResolveThreadParams = { url: string, @@ -15,7 +15,7 @@ type ResolveThreadParams = { isVideo?: boolean, commentCreated?: boolean } -type ResolveThreadResult = Promise<{ video: MVideoAccountAllFiles, comment: MCommentOwnerVideo, commentCreated: boolean }> +type ResolveThreadResult = Promise<{ video: MVideoAccountLightBlacklistAllFiles, comment: MCommentOwnerVideo, commentCreated: boolean }> async function addVideoComments (commentUrls: string[]) { return Bluebird.map(commentUrls, commentUrl => { diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 035994da8..970a953fc 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -58,7 +58,7 @@ import { MChannelDefault, MChannelId, MVideo, - MVideoAccountAllFiles, + MVideoAccountLightBlacklistAllFiles, MVideoAccountLight, MVideoAP, MVideoAPWithoutCaption, @@ -213,19 +213,19 @@ function getOrCreateVideoAndAccountAndChannel (options: { syncParam?: SyncParam, fetchType?: 'all', allowRefresh?: boolean -}): Promise<{ video: MVideoAccountAllFiles, created: boolean, autoBlacklisted?: boolean }> +}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }> function getOrCreateVideoAndAccountAndChannel (options: { videoObject: { id: string } | string, syncParam?: SyncParam, fetchType?: VideoFetchByUrlType, allowRefresh?: boolean -}): Promise<{ video: MVideoAccountAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> +}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> async function getOrCreateVideoAndAccountAndChannel (options: { videoObject: { id: string } | string, syncParam?: SyncParam, fetchType?: VideoFetchByUrlType, allowRefresh?: boolean // true by default -}): Promise<{ video: MVideoAccountAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> { +}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> { // Default params const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false } const fetchType = options.fetchType || 'all' @@ -263,7 +263,7 @@ async function getOrCreateVideoAndAccountAndChannel (options: { } async function updateVideoFromAP (options: { - video: MVideoAccountAllFiles, + video: MVideoAccountLightBlacklistAllFiles, videoObject: VideoTorrentObject, account: MAccountActor, channel: MChannelDefault, @@ -420,7 +420,7 @@ async function refreshVideoIfNeeded (options: { // We need more attributes if the argument video was fetched with not enough joints const video = options.fetchedType === 'all' - ? options.video as MVideoAccountAllFiles + ? options.video as MVideoAccountLightBlacklistAllFiles : await VideoModel.loadByUrlAndPopulateAccount(options.video.url) try { diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index 9005b3e22..ad4cdd3ab 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts @@ -11,11 +11,11 @@ import { sequelizeTypescript } from '../initializers/database' import * as LRUCache from 'lru-cache' import { queue } from 'async' import { downloadImage } from '../helpers/requests' -import { MAccountActorDefault, MChannelActorDefault } from '../typings/models' +import { MAccountDefault, MChannelDefault } from '../typings/models' async function updateActorAvatarFile ( avatarPhysicalFile: Express.Multer.File, - accountOrChannel: MAccountActorDefault | MChannelActorDefault + accountOrChannel: MAccountDefault | MChannelDefault ) { const extension = extname(avatarPhysicalFile.filename) const avatarName = uuidv4() + extension diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index fe57a3e4c..a888b7a72 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -2,14 +2,12 @@ import { createTransport, Transporter } from 'nodemailer' import { isTestInstance } from '../helpers/core-utils' import { bunyanLogger, logger } from '../helpers/logger' import { CONFIG } from '../initializers/config' -import { UserModel } from '../models/account/user' import { JobQueue } from './job-queue' import { EmailPayload } from './job-queue/handlers/email' import { readFileSync } from 'fs-extra' -import { VideoBlacklistModel } from '../models/video/video-blacklist' import { WEBSERVER } from '../initializers/constants' import { MCommentOwnerVideo, MVideo, MVideoAbuseVideo, MVideoAccountLight, MVideoBlacklistVideo } from '../typings/models/video' -import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models' +import { MActorFollowActors, MActorFollowFollowingFullFollowerAccount, MUser } from '../typings/models' import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' type SendEmailOptions = { @@ -109,7 +107,7 @@ class Emailer { return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) } - addNewFollowNotification (to: string[], actorFollow: MActorFollowFull, followType: 'account' | 'channel') { + addNewFollowNotification (to: string[], actorFollow: MActorFollowFollowingFullFollowerAccount, followType: 'account' | 'channel') { const followerName = actorFollow.ActorFollower.Account.getDisplayName() const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 741b1ffde..5cb55cad6 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts @@ -10,7 +10,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { ActorModel } from '../../../models/activitypub/actor' import { Notifier } from '../../notifier' import { sequelizeTypescript } from '../../../initializers/database' -import { MActorFollowFull, MActorFull } from '../../../typings/models' +import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models' export type ActivitypubFollowPayload = { followerActorId: number @@ -45,7 +45,7 @@ export { // --------------------------------------------------------------------------- -async function follow (fromActor: MActorFull, targetActor: MActorFull) { +async function follow (fromActor: MActor, targetActor: MActorFull) { if (fromActor.id === targetActor.id) { throw new Error('Follower is the same than target actor.') } @@ -54,7 +54,7 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) { const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' const actorFollow = await sequelizeTypescript.transaction(async t => { - const [ actorFollow ] = await ActorFollowModel.findOrCreate({ + const [ actorFollow ] = await ActorFollowModel.findOrCreate({ where: { actorId: fromActor.id, targetActorId: targetActor.id @@ -75,5 +75,14 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) { return actorFollow }) - if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollow) + if (actorFollow.state === 'accepted') { + const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount }) + + const actorFollowFull = Object.assign(actorFollow, { + ActorFollowing: targetActor, + ActorFollower: followerFull + }) + + Notifier.Instance.notifyOfNewUserFollow(actorFollowFull) + } } diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index f9dda79f8..ff8c93328 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -111,13 +111,11 @@ type ProcessFileOptions = { generateThumbnail: boolean generatePreview: boolean } -async function processFile (downloader: () => Promise, videoImportArg: MVideoImportDefault, options: ProcessFileOptions) { +async function processFile (downloader: () => Promise, videoImport: MVideoImportDefault, options: ProcessFileOptions) { let tempVideoPath: string let videoDestFile: string let videoFile: VideoFileModel - const videoImport = videoImportArg as MVideoImportDefaultFiles - try { // Download video from youtubeDL tempVideoPath = await downloader() @@ -142,35 +140,37 @@ async function processFile (downloader: () => Promise, videoImportArg: M videoId: videoImport.videoId } videoFile = new VideoFileModel(videoFileData) + + const videoWithFiles = Object.assign(videoImport.Video, { VideoFiles: [ videoFile ] }) // To clean files if the import fails - videoImport.Video.VideoFiles = [ videoFile ] + const videoImportWithFiles: MVideoImportDefaultFiles = Object.assign(videoImport, { Video: videoWithFiles }) // Move file - videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile)) + videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImportWithFiles.Video.getVideoFilename(videoFile)) await move(tempVideoPath, videoDestFile) tempVideoPath = null // This path is not used anymore // Process thumbnail let thumbnailModel: MThumbnail if (options.downloadThumbnail && options.thumbnailUrl) { - thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.MINIATURE) + thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE) } else if (options.generateThumbnail || options.downloadThumbnail) { - thumbnailModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.MINIATURE) + thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE) } // Process preview let previewModel: MThumbnail if (options.downloadPreview && options.thumbnailUrl) { - previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW) + previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW) } else if (options.generatePreview || options.downloadPreview) { - previewModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.PREVIEW) + previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW) } // Create torrent - await videoImport.Video.createTorrentAndSetInfoHash(videoFile) + await videoImportWithFiles.Video.createTorrentAndSetInfoHash(videoFile) const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => { - const videoImportToUpdate = videoImport as MVideoImportVideo + const videoImportToUpdate = videoImportWithFiles as MVideoImportVideo // Refresh video const video = await VideoModel.load(videoImportToUpdate.videoId, t) diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts index f01101b8e..23f76a21a 100644 --- a/server/lib/notifier.ts +++ b/server/lib/notifier.ts @@ -21,7 +21,7 @@ import { MVideoFullLight } from '../typings/models/video' import { MUser, MUserAccount, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/typings/models/user' -import { MActorFollowActors, MActorFollowFull } from '../typings/models' +import { MActorFollowActors, MActorFollowFull, MActorFollowFollowingFullFollowerAccount } from '../typings/models' import { ActorFollowModel } from '../models/activitypub/actor-follow' import { MVideoImportVideo } from '@server/typings/models/video/video-import' import { AccountModel } from '@server/models/account/account' @@ -102,7 +102,7 @@ class Notifier { .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) } - notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { + notifyOfNewUserFollow (actorFollow: MActorFollowFollowingFullFollowerAccount): void { this.notifyUserOfNewActorFollow(actorFollow) .catch(err => { logger.error( @@ -231,7 +231,7 @@ class Notifier { return this.notify({ users, settingGetter, notificationCreator, emailSender }) } - private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) { + private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFollowingFullFollowerAccount) { if (actorFollow.ActorFollowing.isOwned() === false) return // Account follows one of our account? diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index de8fc075b..d9018e606 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -32,7 +32,9 @@ type CandidateToDuplicate = { streamingPlaylists: MStreamingPlaylist[] } -function isMVideoRedundancyFileVideo (o: MVideoRedundancyVideo): o is MVideoRedundancyFileVideo { +function isMVideoRedundancyFileVideo ( + o: MVideoRedundancyFileVideo | MVideoRedundancyStreamingPlaylistVideo +): o is MVideoRedundancyFileVideo { return !!(o as MVideoRedundancyFileVideo).VideoFile } diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index a0df03f7e..d21274527 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -13,8 +13,7 @@ import { isActorPreferredUsernameValid } from '../../../helpers/custom-validator import { ActorModel } from '../../../models/activitypub/actor' import { isBooleanValid } from '../../../helpers/custom-validators/misc' import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' -import { MChannelActorAccountDefault } from '../../../typings/models/video' -import { MUser } from '@server/typings/models' +import { MChannelAccountDefault, MUser } from '@server/typings/models' const videoChannelsAddValidator = [ body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), @@ -132,7 +131,7 @@ export { // --------------------------------------------------------------------------- -function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelActorAccountDefault, res: express.Response) { +function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) { if (videoChannel.Actor.isOwned() === false) { res.status(403) .json({ error: 'Cannot remove video channel of another server.' }) diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index a194d14b3..1449903b7 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -44,7 +44,7 @@ import { isLocalVideoAccepted } from '../../../lib/moderation' import { Hooks } from '../../../lib/plugins/hooks' import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../../../helpers/middlewares' import { MVideoFullLight } from '@server/typings/models' -import { getVideo } from '../../../helpers/video' +import { getVideoWithAttributes } from '../../../helpers/video' const videosAddValidator = getCommonVideoEditAttributes().concat([ body('videofile') @@ -123,7 +123,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ ]) async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) { - const video = getVideo(res) + const video = getVideoWithAttributes(res) // Anybody can watch local videos if (video.isOwned() === true) return next() @@ -157,7 +157,7 @@ const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video- if (areValidationErrors(req, res)) return if (!await doesVideoExist(req.params.id, res, fetchType)) return - const video = getVideo(res) + const video = getVideoWithAttributes(res) const videoAll = video as MVideoFullLight // Video private or blacklisted diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 24b1626e7..cb54d79af 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -55,7 +55,7 @@ import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' import { isThemeNameValid } from '../../helpers/custom-validators/plugins' import { getThemeOrDefault } from '../../lib/plugins/theme-utils' import * as Bluebird from 'bluebird' -import { MUserChannel, MUserDefault, MUserId, MUserWithNotificationSetting } from '@server/typings/models' +import { MUserNotifSettingChannelDefault, MUserDefault, MUserId, MUserWithNotificationSetting } from '@server/typings/models' enum ScopeNames { WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' @@ -384,7 +384,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByUsernameAndPopulateChannels (username: string): Bluebird { + static loadByUsernameAndPopulateChannels (username: string): Bluebird { const query = { where: { username: { [ Op.iLike ]: username } diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 79b9e7d2b..b6a60827f 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -37,7 +37,6 @@ import * as Bluebird from 'bluebird' import { MChannelAccountDefault, MChannelActor, - MChannelActorAccountDefault, MChannelActorAccountDefaultVideos } from '../../typings/models/video' @@ -376,13 +375,13 @@ export class VideoChannelModel extends Model { }) } - static loadByIdAndPopulateAccount (id: number): Bluebird { + static loadByIdAndPopulateAccount (id: number): Bluebird { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) } - static loadByIdAndAccount (id: number, accountId: number): Bluebird { + static loadByIdAndAccount (id: number, accountId: number): Bluebird { const query = { where: { id, @@ -395,7 +394,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadAndPopulateAccount (id: number): Bluebird { + static loadAndPopulateAccount (id: number): Bluebird { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) @@ -427,7 +426,7 @@ export class VideoChannelModel extends Model { return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) } - static loadLocalByNameAndPopulateAccount (name: string): Bluebird { + static loadLocalByNameAndPopulateAccount (name: string): Bluebird { const query = { include: [ { @@ -446,7 +445,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird { + static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird { const query = { include: [ { diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7b1f0bc31..e62bde344 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -121,18 +121,18 @@ import { createTorrentPromise } from '../../helpers/webtorrent' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' import { MChannel, - MChannelActorAccountDefault, + MChannelAccountDefault, MChannelId, MUserAccountId, MUserId, - MVideoAccountAllFiles, MVideoAccountLight, + MVideoAccountLightBlacklistAllFiles, MVideoDetails, + MVideoForUser, MVideoFullLight, MVideoIdThumbnail, MVideoThumbnail, MVideoWithAllFiles, - MVideoWithBlacklistThumbnailScheduled, MVideoWithRights } from '../../typings/models' import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' @@ -1015,7 +1015,7 @@ export class VideoModel extends Model { AccountModel ], transaction: options.transaction - }) as MChannelActorAccountDefault + }) as MChannelAccountDefault } return sendDeleteVideo(instance, options.transaction) @@ -1209,10 +1209,10 @@ export class VideoModel extends Model { return Promise.all([ VideoModel.count(countQuery), - VideoModel.scope(findScopes).findAll(findQuery) + VideoModel.scope(findScopes).findAll(findQuery) ]).then(([ count, rows ]) => { return { - data: rows as MVideoWithBlacklistThumbnailScheduled[], + data: rows, total: count } }) @@ -1468,7 +1468,7 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) } - static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird { + static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird { const query: FindOptions = { where: { url diff --git a/server/typings/express.ts b/server/typings/express.ts index 260091461..1fd809c1b 100644 --- a/server/typings/express.ts +++ b/server/typings/express.ts @@ -5,7 +5,7 @@ import { MActorFollowActorsDefault, MActorFollowActorsDefaultSubscription, MActorFull, - MChannelActorAccountDefault, + MChannelAccountDefault, MComment, MCommentOwnerVideoReply, MUserDefault, @@ -53,7 +53,7 @@ declare module 'express' { videoStreamingPlaylist?: MStreamingPlaylist - videoChannel?: MChannelActorAccountDefault + videoChannel?: MChannelAccountDefault videoPlaylistFull?: MVideoPlaylistFull videoPlaylistSummary?: MVideoPlaylistFullSummary diff --git a/server/typings/models/account/account-blocklist.ts b/server/typings/models/account/account-blocklist.ts index 6d1771de8..d20d97aa8 100644 --- a/server/typings/models/account/account-blocklist.ts +++ b/server/typings/models/account/account-blocklist.ts @@ -2,10 +2,16 @@ import { AccountBlocklistModel } from '../../../models/account/account-blocklist import { PickWith } from '../../utils' import { MAccountDefault } from './account' +type Use = PickWith + +// ############################################################################ + export type MAccountBlocklist = Omit +// ############################################################################ + export type MAccountBlocklistId = Pick export type MAccountBlocklistAccounts = MAccountBlocklist & - PickWith & - PickWith + Use<'ByAccount', MAccountDefault> & + Use<'BlockedAccount', MAccountDefault> diff --git a/server/typings/models/account/account.ts b/server/typings/models/account/account.ts index f3646d510..9a8784e6b 100644 --- a/server/typings/models/account/account.ts +++ b/server/typings/models/account/account.ts @@ -5,7 +5,8 @@ import { MActorAPI, MActorAudience, MActorDefault, - MActorDefaultLight, MActorId, + MActorDefaultLight, + MActorId, MActorServer, MActorSummary, MActorUrl @@ -14,43 +15,63 @@ import { PickWith } from '../../utils' import { MAccountBlocklistId } from './account-blocklist' import { MChannelDefault } from '@server/typings/models' -export type MAccountId = Pick -export type MAccountIdActor = MAccountId & - PickWith -export type MAccountIdActorId = MAccountId & - PickWith +type Use = PickWith + +// ############################################################################ export type MAccount = Omit +// ############################################################################ + +// Only some attributes +export type MAccountId = Pick +export type MAccountUserId = Pick + +// Only some Actor attributes +export type MAccountUrl = Use<'Actor', MActorUrl> +export type MAccountAudience = Use<'Actor', MActorAudience> + +export type MAccountIdActor = MAccountId & + Use<'Actor', MActorAccountChannelId> + +export type MAccountIdActorId = MAccountId & + Use<'Actor', MActorId> + +// ############################################################################ + // Default scope export type MAccountDefault = MAccount & - PickWith + Use<'Actor', MActorDefault> -export type MAccountDefaultChannelDefault = MAccountDefault & - PickWith +// Default with default association scopes +export type MAccountDefaultChannelDefault = MAccount & + Use<'Actor', MActorDefault> & + Use<'VideoChannels', MChannelDefault[]> +// We don't need some actors attributes export type MAccountLight = MAccount & - PickWith + Use<'Actor', MActorDefaultLight> -export type MAccountUserId = Pick +// ############################################################################ +// Full actor export type MAccountActor = MAccount & - PickWith -export type MAccountServer = MAccountActor & - PickWith + Use<'Actor', MActor> -export type MAccountActorDefault = MAccount & - PickWith +// Full actor with server +export type MAccountServer = MAccount & + Use<'Actor', MActorServer> -export type MAccountSummary = Pick & - PickWith +// ############################################################################ -export type MAccountBlocks = MAccountSummary & - PickWith +// For API + +export type MAccountSummary = Pick & + Use<'Actor', MActorSummary> -export type MAccountAPI = MAccountDefault & - PickWith +export type MAccountSummaryBlocks = MAccountSummary & + Use<'BlockedAccounts', MAccountBlocklistId[]> -export type MAccountUrl = PickWith -export type MAccountAudience = PickWith +export type MAccountAPI = MAccount & + Use<'Actor', MActorAPI> diff --git a/server/typings/models/account/actor-follow.ts b/server/typings/models/account/actor-follow.ts index 96c53d857..87050ac63 100644 --- a/server/typings/models/account/actor-follow.ts +++ b/server/typings/models/account/actor-follow.ts @@ -1,27 +1,55 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' -import { MActor, MActorAccountChannel, MActorChannel, MActorChannelAccount, MActorDefault, MActorHost, MActorUsername } from './actor' +import { + MActor, + MActorAccount, + MActorAccountChannel, + MActorChannel, + MActorChannelAccountActor, + MActorDefault, + MActorHost, + MActorUsername +} from './actor' import { PickWith } from '../../utils' +import { ActorModel } from '@server/models/activitypub/actor' + +type Use = PickWith + +// ############################################################################ export type MActorFollow = Omit +// ############################################################################ + +export type MActorFollowFollowingHost = MActorFollow & + Use<'ActorFollowing', MActorUsername & MActorHost> + +// ############################################################################ + +// With actors or actors default + export type MActorFollowActors = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActor> & + Use<'ActorFollowing', MActor> export type MActorFollowActorsDefault = MActorFollow & - PickWith & - PickWith - -export type MActorFollowActorsDefaultSubscription = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActorDefault> & + Use<'ActorFollowing', MActorDefault> export type MActorFollowFull = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActorAccountChannel> & + Use<'ActorFollowing', MActorAccountChannel> -export type MActorFollowFollowingHost = MActorFollow & - PickWith +// ############################################################################ + +// For subscriptions + +export type MActorFollowActorsDefaultSubscription = MActorFollow & + Use<'ActorFollower', MActorDefault> & + Use<'ActorFollowing', MActorDefault & MActorChannel> + +export type MActorFollowFollowingFullFollowerAccount = MActorFollow & + Use<'ActorFollower', MActorAccount> & + Use<'ActorFollowing', MActorAccountChannel> export type MActorFollowSubscriptions = MActorFollow & - PickWith + Use<'ActorFollowing', MActorChannelAccountActor> diff --git a/server/typings/models/account/actor.ts b/server/typings/models/account/actor.ts index f3e752a98..7d99a433b 100644 --- a/server/typings/models/account/actor.ts +++ b/server/typings/models/account/actor.ts @@ -1,74 +1,103 @@ import { ActorModel } from '../../../models/activitypub/actor' import { PickWith } from '../../utils' -import { MAccount, MAccountActorDefault, MAccountId, MAccountIdActor } from './account' -import { MServerHost, MServerHostBlocks, MServer } from '../server' +import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' +import { MServer, MServerHost, MServerHostBlocks } from '../server' import { MAvatar } from './avatar' -import { MChannel, MChannelAccountActor, MChannelActorAccountDefault, MChannelId, MChannelIdActor } from '../video' +import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video' + +type Use = PickWith + +// ############################################################################ export type MActor = Omit +// ############################################################################ + export type MActorUrl = Pick export type MActorId = Pick export type MActorUsername = Pick -export type MActorHost = PickWith export type MActorFollowersUrl = Pick export type MActorAudience = MActorUrl & MActorFollowersUrl +export type MActorFollowerException = Pick +export type MActorSignature = MActorAccountChannelId export type MActorLight = Omit +// ############################################################################ + +// Some association attributes + +export type MActorHost = Use<'Server', MServerHost> + export type MActorDefaultLight = MActorLight & - MActorHost & - PickWith + Use<'Server', MServerHost> & + Use<'Avatar', MAvatar> export type MActorAccountId = MActor & - PickWith + Use<'Account', MAccountId> export type MActorAccountIdActor = MActor & - PickWith + Use<'Account', MAccountIdActor> export type MActorChannelId = MActor & - PickWith + Use<'VideoChannel', MChannelId> export type MActorChannelIdActor = MActor & - PickWith + Use<'VideoChannel', MChannelIdActor> export type MActorAccountChannelId = MActorAccountId & MActorChannelId export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor +// ############################################################################ + +// Include raw account/channel/server + export type MActorAccount = MActor & - PickWith + Use<'Account', MAccount> export type MActorChannel = MActor & - PickWith + Use<'VideoChannel', MChannel> export type MActorAccountChannel = MActorAccount & MActorChannel -export type MActorChannelAccount = MActor & - PickWith - export type MActorServer = MActor & - PickWith + Use<'Server', MServer> -export type MActorDefault = MActorServer & - PickWith +// ############################################################################ -export type MActorFull = MActorDefault & - PickWith & - PickWith +// Complex actor associations -export type MActorFullActor = MActorDefault & - PickWith & - PickWith +export type MActorDefault = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> -export type MActorSummary = Pick & - MActorHost & - PickWith +// Actor with channel that is associated to an account and its actor +// Actor -> VideoChannel -> Account -> Actor +export type MActorChannelAccountActor = MActor & + Use<'VideoChannel', MChannelAccountActor> -export type MActorSummaryBlocks = Omit & - PickWith +export type MActorFull = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> & + Use<'Account', MAccount> & + Use<'VideoChannel', MChannelAccountActor> -export type MActorFollowerException = Pick +// Same than ActorFull, but the account and the channel have their actor +export type MActorFullActor = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> & + Use<'Account', MAccountDefault> & + Use<'VideoChannel', MChannelAccountDefault> + +// ############################################################################ + +// API + +export type MActorSummary = Pick & + Use<'Server', MServerHost> & + Use<'Avatar', MAvatar> + +export type MActorSummaryBlocks = MActorSummary & + Use<'Server', MServerHostBlocks> export type MActorAPI = Omit - -export type MActorSignature = MActorAccountChannelId diff --git a/server/typings/models/index.d.ts b/server/typings/models/index.d.ts index 39e82e4a8..78b4948ce 100644 --- a/server/typings/models/index.d.ts +++ b/server/typings/models/index.d.ts @@ -1,4 +1,5 @@ export * from './account' +export * from './oauth' export * from './server' export * from './user' export * from './video' diff --git a/server/typings/models/oauth/index.d.ts b/server/typings/models/oauth/index.d.ts new file mode 100644 index 000000000..36b7ea8ca --- /dev/null +++ b/server/typings/models/oauth/index.d.ts @@ -0,0 +1,2 @@ +export * from './oauth-client' +export * from './oauth-token' diff --git a/server/typings/models/oauth/oauth-token.ts b/server/typings/models/oauth/oauth-token.ts index 105ea3df3..af3412925 100644 --- a/server/typings/models/oauth/oauth-token.ts +++ b/server/typings/models/oauth/oauth-token.ts @@ -2,8 +2,12 @@ import { OAuthTokenModel } from '@server/models/oauth/oauth-token' import { PickWith } from '@server/typings/utils' import { MUserAccountUrl } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MOAuthToken = Omit export type MOAuthTokenUser = MOAuthToken & - PickWith & + Use<'User', MUserAccountUrl> & { user?: MUserAccountUrl } diff --git a/server/typings/models/server/server-blocklist.ts b/server/typings/models/server/server-blocklist.ts index 38065f382..0ca00b5c2 100644 --- a/server/typings/models/server/server-blocklist.ts +++ b/server/typings/models/server/server-blocklist.ts @@ -2,8 +2,14 @@ import { ServerBlocklistModel } from '@server/models/server/server-blocklist' import { PickWith } from '@server/typings/utils' import { MAccountDefault, MServer } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MServerBlocklist = Omit +// ############################################################################ + export type MServerBlocklistAccountServer = MServerBlocklist & - PickWith & - PickWith + Use<'ByAccount', MAccountDefault> & + Use<'BlockedServer', MServer> diff --git a/server/typings/models/server/server.ts b/server/typings/models/server/server.ts index 6be7bf9bb..c059cff79 100644 --- a/server/typings/models/server/server.ts +++ b/server/typings/models/server/server.ts @@ -2,9 +2,15 @@ import { ServerModel } from '../../../models/server/server' import { PickWith } from '../../utils' import { MAccountBlocklistId } from '../account' +type Use = PickWith + +// ############################################################################ + export type MServer = Omit +// ############################################################################ + export type MServerHost = Pick export type MServerHostBlocks = MServerHost & - PickWith + Use<'BlockedByAccounts', MAccountBlocklistId[]> diff --git a/server/typings/models/user/index.d.ts b/server/typings/models/user/index.d.ts index e3353d0b1..6657b2128 100644 --- a/server/typings/models/user/index.d.ts +++ b/server/typings/models/user/index.d.ts @@ -1,3 +1,4 @@ export * from './user' export * from './user-notification' +export * from './user-notification-setting' export * from './user-video-history' diff --git a/server/typings/models/user/user-notification.ts b/server/typings/models/user/user-notification.ts index b872c5dc5..f9daf5eb2 100644 --- a/server/typings/models/user/user-notification.ts +++ b/server/typings/models/user/user-notification.ts @@ -12,6 +12,10 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { VideoImportModel } from '../../../models/video/video-import' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +type Use = PickWith + +// ############################################################################ + export namespace UserNotificationIncludes { export type VideoInclude = Pick export type VideoIncludeChannel = VideoInclude & @@ -56,14 +60,18 @@ export namespace UserNotificationIncludes { PickWith } -export type UserNotificationModelOnly = Omit -export type UserNotificationModelForApi = UserNotificationModelOnly & - PickWith & - PickWith & - PickWith & - PickWith & - PickWith & - PickWith & - PickWith +// ############################################################################ + +export type UserNotificationModelForApi = MUserNotification & + Use<'Video', UserNotificationIncludes.VideoIncludeChannel> & + Use<'Comment', UserNotificationIncludes.VideoCommentInclude> & + Use<'VideoAbuse', UserNotificationIncludes.VideoAbuseInclude> & + Use<'VideoBlacklist', UserNotificationIncludes.VideoBlacklistInclude> & + Use<'VideoImport', UserNotificationIncludes.VideoImportInclude> & + Use<'ActorFollow', UserNotificationIncludes.ActorFollowInclude> & + Use<'Account', UserNotificationIncludes.AccountIncludeActor> diff --git a/server/typings/models/user/user.ts b/server/typings/models/user/user.ts index b91eed8d9..466cde33b 100644 --- a/server/typings/models/user/user.ts +++ b/server/typings/models/user/user.ts @@ -3,30 +3,49 @@ import { PickWith } from '../../utils' import { MAccount, MAccountDefault, MAccountDefaultChannelDefault, MAccountId, MAccountIdActorId, MAccountUrl } from '../account' import { MNotificationSetting } from './user-notification-setting' +type Use = PickWith + +// ############################################################################ + export type MUser = Omit +// ############################################################################ + export type MUserId = Pick -export type MUserWithNotificationSetting = MUser & - PickWith +// ############################################################################ -export type MUserAccountDefault = MUser & - PickWith +// With account + +export type MUserAccountId = MUser & + Use<'Account', MAccountId> + +export type MUserAccountUrl = MUser & + Use<'Account', MAccountUrl & MAccountIdActorId> export type MUserAccount = MUser & - PickWith + Use<'Account', MAccount> -export type MUserAccountId = MUser & - PickWith +export type MUserAccountDefault = MUser & + Use<'Account', MAccountDefault> -export type MUserNotifSettingAccount = MUserWithNotificationSetting & MUserAccount +// With channel -export type MUserDefault = MUser & - MUserWithNotificationSetting & - MUserAccountDefault +export type MUserNotifSettingChannelDefault = MUser & + Use<'NotificationSetting', MNotificationSetting> & + Use<'Account', MAccountDefaultChannelDefault> -export type MUserChannel = MUserWithNotificationSetting & - PickWith +// With notification settings -export type MUserAccountUrl = MUser & - PickWith +export type MUserWithNotificationSetting = MUser & + Use<'NotificationSetting', MNotificationSetting> + +export type MUserNotifSettingAccount = MUser & + Use<'NotificationSetting', MNotificationSetting> & + Use<'Account', MAccount> + +// Default scope + +export type MUserDefault = MUser & + Use<'NotificationSetting', MNotificationSetting> & + Use<'Account', MAccountDefault> diff --git a/server/typings/models/video/index.d.ts b/server/typings/models/video/index.d.ts index 528e9d274..bd69c8a4b 100644 --- a/server/typings/models/video/index.d.ts +++ b/server/typings/models/video/index.d.ts @@ -5,10 +5,14 @@ export * from './video' export * from './video-abuse' export * from './video-blacklist' export * from './video-caption' +export * from './video-change-ownership' export * from './video-channels' export * from './video-comment' export * from './video-file' +export * from './video-import' export * from './video-playlist' +export * from './video-playlist-element' +export * from './video-rate' export * from './video-redundancy' export * from './video-share' export * from './video-streaming-playlist' diff --git a/server/typings/models/video/video-abuse.ts b/server/typings/models/video/video-abuse.ts index 1667ae55a..0474cac5b 100644 --- a/server/typings/models/video/video-abuse.ts +++ b/server/typings/models/video/video-abuse.ts @@ -3,13 +3,21 @@ import { PickWith } from '../../utils' import { MVideo } from './video' import { MAccountDefault } from '../account' +type Use = PickWith + +// ############################################################################ + export type MVideoAbuse = Omit +// ############################################################################ + export type MVideoAbuseId = Pick export type MVideoAbuseVideo = MVideoAbuse & Pick & - PickWith + Use<'Video', MVideo> -export type MVideoAbuseAccountVideo = MVideoAbuseVideo & - PickWith +export type MVideoAbuseAccountVideo = MVideoAbuse & + Pick & + Use<'Video', MVideo> & + Use<'Account', MAccountDefault> diff --git a/server/typings/models/video/video-blacklist.ts b/server/typings/models/video/video-blacklist.ts index 9242b357d..cc539f95c 100644 --- a/server/typings/models/video/video-blacklist.ts +++ b/server/typings/models/video/video-blacklist.ts @@ -2,10 +2,16 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { PickWith } from '@server/typings/utils' import { MVideo } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MVideoBlacklist = Omit export type MVideoBlacklistLight = Pick export type MVideoBlacklistUnfederated = Pick +// ############################################################################ + export type MVideoBlacklistVideo = MVideoBlacklist & - PickWith + Use<'Video', MVideo> diff --git a/server/typings/models/video/video-caption.ts b/server/typings/models/video/video-caption.ts index 16d8b7392..fe0e664c2 100644 --- a/server/typings/models/video/video-caption.ts +++ b/server/typings/models/video/video-caption.ts @@ -2,9 +2,15 @@ import { VideoCaptionModel } from '../../../models/video/video-caption' import { PickWith } from '@server/typings/utils' import { VideoModel } from '@server/models/video/video' +type Use = PickWith + +// ############################################################################ + export type MVideoCaption = Omit +// ############################################################################ + export type MVideoCaptionLanguage = Pick export type MVideoCaptionVideo = MVideoCaption & - PickWith> + Use<'Video', Pick> diff --git a/server/typings/models/video/video-change-ownership.ts b/server/typings/models/video/video-change-ownership.ts index 718515e2d..0410115c6 100644 --- a/server/typings/models/video/video-change-ownership.ts +++ b/server/typings/models/video/video-change-ownership.ts @@ -2,9 +2,13 @@ import { VideoChangeOwnershipModel } from '@server/models/video/video-change-own import { PickWith } from '@server/typings/utils' import { MAccountDefault, MVideoWithFileThumbnail } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MVideoChangeOwnership = Omit export type MVideoChangeOwnershipFull = MVideoChangeOwnership & - PickWith & - PickWith & - PickWith + Use<'Initiator', MAccountDefault> & + Use<'NextOwner', MAccountDefault> & + Use<'Video', MVideoWithFileThumbnail> diff --git a/server/typings/models/video/video-channels.ts b/server/typings/models/video/video-channels.ts index e10bd6842..b6506ed9f 100644 --- a/server/typings/models/video/video-channels.ts +++ b/server/typings/models/video/video-channels.ts @@ -1,70 +1,97 @@ -import { FunctionProperties, PickWith } from '../../utils' +import { PickWith } from '../../utils' import { VideoChannelModel } from '../../../models/video/video-channel' import { MAccountActor, MAccountAPI, - MAccountBlocks, MAccountDefault, MAccountLight, + MAccountSummaryBlocks, MAccountUserId, MActor, MActorAccountChannelId, MActorAPI, MActorDefault, - MActorDefaultLight, MActorLight, + MActorDefaultLight, + MActorLight, MActorSummary } from '../account' import { MVideo } from './video' -export type MChannelId = FunctionProperties -export type MChannelIdActor = MChannelId & - PickWith +type Use = PickWith + +// ############################################################################ export type MChannel = Omit +// ############################################################################ + +export type MChannelId = Pick + +// ############################################################################ + +export type MChannelIdActor = MChannelId & + Use<'Actor', MActorAccountChannelId> + export type MChannelUserId = Pick & - PickWith + Use<'Account', MAccountUserId> + +export type MChannelActor = MChannel & + Use<'Actor', MActor> // Default scope export type MChannelDefault = MChannel & - PickWith + Use<'Actor', MActorDefault> + +// ############################################################################ + +// Not all association attributes export type MChannelLight = MChannel & - PickWith + Use<'Actor', MActorDefaultLight> -export type MChannelAccountLight = MChannel & - PickWith & - PickWith +export type MChannelActorLight = MChannel & + Use<'Actor', MActorLight> -export type MChannelSummary = Pick & - PickWith +export type MChannelAccountLight = MChannel & + Use<'Actor', MActorDefaultLight> & + Use<'Account', MAccountLight> -export type MChannelSummaryAccount = MChannelSummary & - PickWith +// ############################################################################ -export type MChannelAPI = MChannel & - PickWith & - PickWith +// Account associations export type MChannelAccountActor = MChannel & - PickWith -export type MChannelAccountDefault = MChannelActor & - PickWith + Use<'Account', MAccountActor> + +export type MChannelAccountDefault = MChannel & + Use<'Actor', MActorDefault> & + Use<'Account', MAccountDefault> +export type MChannelActorAccountActor = MChannel & + Use<'Account', MAccountActor> & + Use<'Actor', MActor> + +// ############################################################################ + +// Videos associations export type MChannelVideos = MChannel & - PickWith + Use<'Videos', MVideo[]> -export type MChannelActor = MChannel & - PickWith -export type MChannelActorLight = MChannel & - PickWith -export type MChannelActorDefault = MChannel & - PickWith +export type MChannelActorAccountDefaultVideos = MChannel & + Use<'Actor', MActorDefault> & + Use<'Account', MAccountDefault> & + Use<'Videos', MVideo[]> + +// ############################################################################ + +// For API -export type MChannelActorAccountActor = MChannelAccountActor & MChannelActor +export type MChannelSummary = Pick & + Use<'Actor', MActorSummary> -export type MChannelActorAccountDefault = MChannel & - PickWith & - PickWith +export type MChannelSummaryAccount = MChannelSummary & + Use<'Account', MAccountSummaryBlocks> -export type MChannelActorAccountDefaultVideos = MChannelActorAccountDefault & MChannelVideos +export type MChannelAPI = MChannel & + Use<'Actor', MActorAPI> & + Use<'Account', MAccountAPI> diff --git a/server/typings/models/video/video-comment.ts b/server/typings/models/video/video-comment.ts index 675613804..187461213 100644 --- a/server/typings/models/video/video-comment.ts +++ b/server/typings/models/video/video-comment.ts @@ -1,29 +1,43 @@ import { VideoCommentModel } from '../../../models/video/video-comment' import { PickWith } from '../../utils' import { MAccountDefault } from '../account' -import { MVideoAccountDefault, MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video' +import { MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video' + +type Use = PickWith + +// ############################################################################ export type MComment = Omit export type MCommentId = Pick -export type MCommentAPI = MComment & { totalReplies: number } +// ############################################################################ export type MCommentOwner = MComment & - PickWith + Use<'Account', MAccountDefault> export type MCommentVideo = MComment & - PickWith + Use<'Video', MVideoAccountLight> export type MCommentReply = MComment & - PickWith + Use<'InReplyToVideoComment', MComment> + +export type MCommentOwnerVideo = MComment & + Use<'Account', MAccountDefault> & + Use<'Video', MVideoAccountLight> -export type MCommentOwnerReply = MCommentOwner & MCommentReply -export type MCommentOwnerVideo = MCommentOwner & MCommentVideo -export type MCommentReplyVideo = MCommentReply & MCommentVideo -export type MCommentOwnerVideoReply = MCommentOwnerVideo & MCommentReply +export type MCommentOwnerVideoReply = MComment & + Use<'Account', MAccountDefault> & + Use<'Video', MVideoAccountLight> & + Use<'InReplyToVideoComment', MComment> -export type MCommentOwnerReplyVideoLight = MCommentOwnerReply & - PickWith +export type MCommentOwnerReplyVideoLight = MComment & + Use<'Account', MAccountDefault> & + Use<'InReplyToVideoComment', MComment> & + Use<'Video', MVideoIdUrl> export type MCommentOwnerVideoFeed = MCommentOwner & - PickWith + Use<'Video', MVideoFeed> + +// ############################################################################ + +export type MCommentAPI = MComment & { totalReplies: number } diff --git a/server/typings/models/video/video-file.ts b/server/typings/models/video/video-file.ts index afa659d1f..484351a8d 100644 --- a/server/typings/models/video/video-file.ts +++ b/server/typings/models/video/video-file.ts @@ -3,13 +3,17 @@ import { PickWith, PickWithOpt } from '../../utils' import { MVideo, MVideoUUID } from './video' import { MVideoRedundancyFileUrl } from './video-redundancy' +type Use = PickWith + +// ############################################################################ + export type MVideoFile = Omit export type MVideoFileVideo = MVideoFile & - PickWith + Use<'Video', MVideo> export type MVideoFileVideoUUID = MVideoFile & - PickWith + Use<'Video', MVideoUUID> export type MVideoFileRedundanciesOpt = MVideoFile & PickWithOpt diff --git a/server/typings/models/video/video-import.ts b/server/typings/models/video/video-import.ts index 51be900d6..ada723713 100644 --- a/server/typings/models/video/video-import.ts +++ b/server/typings/models/video/video-import.ts @@ -2,14 +2,23 @@ import { VideoImportModel } from '@server/models/video/video-import' import { PickWith } from '@server/typings/utils' import { MUser, MVideo, MVideoAccountLight, MVideoTag, MVideoThumbnail, MVideoWithFile } from '@server/typings/models' -export type MVideoImport = Omit +type Use = PickWith -export type MVideoImportDefault = MVideoImport & - PickWith & - PickWith +// ############################################################################ -export type MVideoImportDefaultFiles = MVideoImportDefault & - PickWith +export type MVideoImport = Omit export type MVideoImportVideo = MVideoImport & - PickWith + Use<'Video', MVideo> + +// ############################################################################ + +type VideoAssociation = MVideoTag & MVideoAccountLight & MVideoThumbnail + +export type MVideoImportDefault = MVideoImport & + Use<'User', MUser> & + Use<'Video', VideoAssociation> + +export type MVideoImportDefaultFiles = MVideoImport & + Use<'User', MUser> & + Use<'Video', VideoAssociation & MVideoWithFile> diff --git a/server/typings/models/video/video-playlist-element.ts b/server/typings/models/video/video-playlist-element.ts index d1b8a18a0..5a039d7b1 100644 --- a/server/typings/models/video/video-playlist-element.ts +++ b/server/typings/models/video/video-playlist-element.ts @@ -2,14 +2,27 @@ import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-e import { PickWith } from '@server/typings/utils' import { MVideoPlaylistPrivacy, MVideoThumbnail, MVideoUrl } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MVideoPlaylistElement = Omit + +// ############################################################################ + export type MVideoPlaylistElementId = Pick export type MVideoPlaylistElementLight = Pick +// ############################################################################ + export type MVideoPlaylistVideoThumbnail = MVideoPlaylistElement & - PickWith + Use<'Video', MVideoThumbnail> + +// ############################################################################ + +// For API export type MVideoPlaylistAP = MVideoPlaylistElement & - PickWith & - PickWith + Use<'Video', MVideoUrl> & + Use<'VideoPlaylist', MVideoPlaylistPrivacy> diff --git a/server/typings/models/video/video-playlist.ts b/server/typings/models/video/video-playlist.ts index 825b3391c..633818405 100644 --- a/server/typings/models/video/video-playlist.ts +++ b/server/typings/models/video/video-playlist.ts @@ -5,38 +5,76 @@ import { MThumbnail } from './thumbnail' import { MChannelDefault, MChannelSummary } from './video-channels' import { MVideoPlaylistElementLight } from '@server/typings/models/video/video-playlist-element' +type Use = PickWith + +// ############################################################################ + export type MVideoPlaylist = Omit + +// ############################################################################ + export type MVideoPlaylistId = Pick export type MVideoPlaylistPrivacy = Pick +export type MVideoPlaylistUUID = Pick +export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength: number } + +// ############################################################################ + +// With elements export type MVideoPlaylistWithElements = MVideoPlaylist & - PickWith -export type MVideoPlaylistIdWithElements = MVideoPlaylistId & MVideoPlaylistWithElements + Use<'VideoPlaylistElements', MVideoPlaylistElementLight[]> -export type MVideoPlaylistUUID = Pick +export type MVideoPlaylistIdWithElements = MVideoPlaylistId & + Use<'VideoPlaylistElements', MVideoPlaylistElementLight[]> + +// ############################################################################ + +// With account export type MVideoPlaylistOwner = MVideoPlaylist & - PickWith + Use<'OwnerAccount', MAccount> export type MVideoPlaylistOwnerDefault = MVideoPlaylist & - PickWith + Use<'OwnerAccount', MAccountDefault> + +// ############################################################################ + +// With thumbnail export type MVideoPlaylistThumbnail = MVideoPlaylist & - PickWith + Use<'Thumbnail', MThumbnail> -export type MVideoPlaylistAccountThumbnail = MVideoPlaylistOwnerDefault & - PickWith +export type MVideoPlaylistAccountThumbnail = MVideoPlaylist & + Use<'OwnerAccount', MAccountDefault> & + Use<'Thumbnail', MThumbnail> -export type MVideoPlaylistAccountChannelSummary = MVideoPlaylist & - PickWith & - PickWith +// ############################################################################ + +// With channel export type MVideoPlaylistAccountChannelDefault = MVideoPlaylist & - PickWith & - PickWith + Use<'OwnerAccount', MAccountDefault> & + Use<'VideoChannel', MChannelDefault> -export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength: number } +// ############################################################################ -export type MVideoPlaylistFullSummary = MVideoPlaylistAccountChannelSummary & MVideoPlaylistThumbnail +// With all associations + +export type MVideoPlaylistFull = MVideoPlaylist & + Use<'OwnerAccount', MAccountDefault> & + Use<'VideoChannel', MChannelDefault> & + Use<'Thumbnail', MThumbnail> + +// ############################################################################ + +// For API + +export type MVideoPlaylistAccountChannelSummary = MVideoPlaylist & + Use<'OwnerAccount', MAccountSummary> & + Use<'VideoChannel', MChannelSummary> -export type MVideoPlaylistFull = MVideoPlaylist & MVideoPlaylistThumbnail & MVideoPlaylistAccountChannelDefault +export type MVideoPlaylistFullSummary = MVideoPlaylist & + Use<'Thumbnail', MThumbnail> & + Use<'OwnerAccount', MAccountSummary> & + Use<'VideoChannel', MChannelSummary> diff --git a/server/typings/models/video/video-rate.ts b/server/typings/models/video/video-rate.ts index 6eefe6362..fc9329993 100644 --- a/server/typings/models/video/video-rate.ts +++ b/server/typings/models/video/video-rate.ts @@ -2,11 +2,15 @@ import { AccountVideoRateModel } from '@server/models/account/account-video-rate import { PickWith } from '@server/typings/utils' import { MAccountAudience, MAccountUrl, MVideo } from '..' +type Use = PickWith + +// ############################################################################ + export type MAccountVideoRate = Omit export type MAccountVideoRateAccountUrl = MAccountVideoRate & - PickWith + Use<'Account', MAccountUrl> export type MAccountVideoRateAccountVideo = MAccountVideoRate & - PickWith & - PickWith + Use<'Account', MAccountAudience> & + Use<'Video', MVideo> diff --git a/server/typings/models/video/video-redundancy.ts b/server/typings/models/video/video-redundancy.ts index ec61bfb68..c25eb9c09 100644 --- a/server/typings/models/video/video-redundancy.ts +++ b/server/typings/models/video/video-redundancy.ts @@ -2,17 +2,25 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundanc import { PickWith } from '@server/typings/utils' import { MStreamingPlaylistVideo, MVideoFile, MVideoFileVideo } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MVideoRedundancy = Omit export type MVideoRedundancyFileUrl = Pick +// ############################################################################ + export type MVideoRedundancyFile = MVideoRedundancy & - PickWith + Use<'VideoFile', MVideoFile> export type MVideoRedundancyFileVideo = MVideoRedundancy & - PickWith + Use<'VideoFile', MVideoFileVideo> export type MVideoRedundancyStreamingPlaylistVideo = MVideoRedundancy & - PickWith + Use<'VideoStreamingPlaylist', MStreamingPlaylistVideo> -export type MVideoRedundancyVideo = MVideoRedundancyFileVideo | MVideoRedundancyStreamingPlaylistVideo +export type MVideoRedundancyVideo = MVideoRedundancy & + Use<'VideoFile', MVideoFileVideo> & + Use<'VideoStreamingPlaylist', MStreamingPlaylistVideo> diff --git a/server/typings/models/video/video-share.ts b/server/typings/models/video/video-share.ts index 7e8cb8b61..a7a90beeb 100644 --- a/server/typings/models/video/video-share.ts +++ b/server/typings/models/video/video-share.ts @@ -3,10 +3,15 @@ import { PickWith } from '../../utils' import { MActorDefault } from '../account' import { MVideo } from './video' +type Use = PickWith + +// ############################################################################ + export type MVideoShare = Omit export type MVideoShareActor = MVideoShare & - PickWith + Use<'Actor', MActorDefault> -export type MVideoShareFull = MVideoShareActor & - PickWith +export type MVideoShareFull = MVideoShare & + Use<'Actor', MActorDefault> & + Use<'Video', MVideo> diff --git a/server/typings/models/video/video-streaming-playlist.ts b/server/typings/models/video/video-streaming-playlist.ts index 5b6310771..f1b3438b6 100644 --- a/server/typings/models/video/video-streaming-playlist.ts +++ b/server/typings/models/video/video-streaming-playlist.ts @@ -3,10 +3,14 @@ import { PickWith } from '../../utils' import { MVideoRedundancyFileUrl } from './video-redundancy' import { MVideo } from '@server/typings/models' +type Use = PickWith + +// ############################################################################ + export type MStreamingPlaylist = Omit export type MStreamingPlaylistVideo = MStreamingPlaylist & - PickWith + Use<'Video', MVideo> export type MStreamingPlaylistRedundancies = MStreamingPlaylist & - PickWith + Use<'RedundancyVideos', MVideoRedundancyFileUrl[]> diff --git a/server/typings/models/video/video.ts b/server/typings/models/video/video.ts index 0ffd0c302..914eb7f57 100644 --- a/server/typings/models/video/video.ts +++ b/server/typings/models/video/video.ts @@ -1,6 +1,6 @@ import { VideoModel } from '../../../models/video/video' import { PickWith, PickWithOpt } from '../../utils' -import { MChannelAccountLight, MChannelActor, MChannelActorAccountDefault, MChannelUserId } from './video-channels' +import { MChannelAccountDefault, MChannelAccountLight, MChannelActor, MChannelUserId } from './video-channels' import { MTag } from './tag' import { MVideoCaptionLanguage } from './video-caption' import { MStreamingPlaylist, MStreamingPlaylistRedundancies } from './video-streaming-playlist' @@ -10,10 +10,16 @@ import { MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blackl import { MScheduleVideoUpdate } from './schedule-video-update' import { MUserVideoHistoryTime } from '../user/user-video-history' +type Use = PickWith + +// ############################################################################ + export type MVideo = Omit +// ############################################################################ + export type MVideoId = Pick export type MVideoUrl = Pick export type MVideoUUID = Pick @@ -21,83 +27,120 @@ export type MVideoUUID = Pick export type MVideoIdUrl = MVideoId & MVideoUrl export type MVideoFeed = Pick +// ############################################################################ + +// Video raw associations: schedules, video files, tags, thumbnails, captions, streaming playlists + +// "With" to not confuse with the VideoFile model export type MVideoWithFile = MVideo & - PickWith + Use<'VideoFiles', MVideoFile[]> export type MVideoThumbnail = MVideo & - PickWith -export type MVideoIdThumbnail = MVideoThumbnail & MVideoId + Use<'Thumbnails', MThumbnail[]> + +export type MVideoIdThumbnail = MVideoId & + Use<'Thumbnails', MThumbnail[]> + +export type MVideoWithFileThumbnail = MVideo & + Use<'VideoFiles', MVideoFile[]> & + Use<'Thumbnails', MThumbnail[]> export type MVideoTag = MVideo & - PickWith + Use<'Tags', MTag[]> export type MVideoWithSchedule = MVideo & PickWithOpt -export type MVideoWithFileThumbnail = MVideoWithFile & MVideoThumbnail +export type MVideoWithCaptions = MVideo & + Use<'VideoCaptions', MVideoCaptionLanguage[]> -export type MVideoUser = MVideo & - PickWith +export type MVideoWithStreamingPlaylist = MVideo & + Use<'VideoStreamingPlaylists', MStreamingPlaylist[]> -export type MVideoWithCaptions = MVideo & - PickWith +// ############################################################################ + +// Associations with not all their attributes + +export type MVideoUserHistory = MVideo & + Use<'UserVideoHistories', MUserVideoHistoryTime[]> export type MVideoWithBlacklistLight = MVideo & - PickWith + Use<'VideoBlacklist', MVideoBlacklistLight> export type MVideoAccountLight = MVideo & - PickWith + Use<'VideoChannel', MChannelAccountLight> -export type MVideoWithRights = MVideoWithBlacklistLight & MVideoThumbnail & MVideoUser +export type MVideoWithRights = MVideo & + Use<'VideoBlacklist', MVideoBlacklistLight> & + Use<'Thumbnails', MThumbnail[]> & + Use<'VideoChannel', MChannelUserId> -export type MVideoWithStreamingPlaylist = MVideo & - PickWith +// ############################################################################ -export type MVideoWithAllFiles = MVideoWithFileThumbnail & MVideoWithStreamingPlaylist +// All files with some additional associations -export type MVideoAccountAllFiles = MVideoWithAllFiles & MVideoAccountLight & MVideoWithBlacklistLight -export type MVideoAccountAllFilesCaptions = MVideoAccountAllFiles & MVideoWithCaptions +export type MVideoWithAllFiles = MVideo & + Use<'VideoFiles', MVideoFile[]> & + Use<'Thumbnails', MThumbnail[]> & + Use<'VideoStreamingPlaylists', MStreamingPlaylist[]> -export type MVideoUserHistory = MVideo & - PickWith +export type MVideoAccountLightBlacklistAllFiles = MVideo & + Use<'VideoFiles', MVideoFile[]> & + Use<'Thumbnails', MThumbnail[]> & + Use<'VideoStreamingPlaylists', MStreamingPlaylist[]> & + Use<'VideoChannel', MChannelAccountLight> & + Use<'VideoBlacklist', MVideoBlacklistLight> -export type MVideoWithBlacklistThumbnailScheduled = MVideoWithSchedule & MVideoWithBlacklistLight & MVideoWithFileThumbnail +// ############################################################################ + +// With account export type MVideoAccountDefault = MVideo & - PickWith + Use<'VideoChannel', MChannelAccountDefault> -export type MVideoThumbnailAccountDefault = MVideoThumbnail & - PickWith +export type MVideoThumbnailAccountDefault = MVideo & + Use<'Thumbnails', MThumbnail[]> & + Use<'VideoChannel', MChannelAccountDefault> export type MVideoWithChannelActor = MVideo & - PickWith - -export type MVideoFullLight = MVideoThumbnail & - MVideoWithBlacklistLight & - MVideoTag & - MVideoAccountLight & - MVideoUserHistory & - MVideoWithFile & - MVideoWithSchedule & - MVideoWithStreamingPlaylist & - MVideoUserHistory + Use<'VideoChannel', MChannelActor> + +export type MVideoFullLight = MVideo & + Use<'Thumbnails', MThumbnail[]> & + Use<'VideoBlacklist', MVideoBlacklistLight> & + Use<'Tags', MTag[]> & + Use<'VideoChannel', MChannelAccountLight> & + Use<'UserVideoHistories', MUserVideoHistoryTime[]> & + Use<'VideoFiles', MVideoFile[]> & + Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> & + Use<'VideoStreamingPlaylists', MStreamingPlaylist[]> + +// ############################################################################ + +// API export type MVideoAP = MVideo & - MVideoTag & - MVideoAccountLight & - MVideoWithStreamingPlaylist & - MVideoWithCaptions & - PickWith & - PickWith + Use<'Tags', MTag[]> & + Use<'VideoChannel', MChannelAccountLight> & + Use<'VideoStreamingPlaylists', MStreamingPlaylist[]> & + Use<'VideoCaptions', MVideoCaptionLanguage[]> & + Use<'VideoBlacklist', MVideoBlacklistUnfederated> & + Use<'VideoFiles', MVideoFileRedundanciesOpt[]> export type MVideoAPWithoutCaption = Omit export type MVideoDetails = MVideo & - MVideoWithBlacklistLight & - MVideoTag & - MVideoAccountLight & - MVideoWithSchedule & - MVideoThumbnail & - MVideoUserHistory & - PickWith & - PickWith + Use<'VideoBlacklist', MVideoBlacklistLight> & + Use<'Tags', MTag[]> & + Use<'VideoChannel', MChannelAccountLight> & + Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> & + Use<'Thumbnails', MThumbnail[]> & + Use<'UserVideoHistories', MUserVideoHistoryTime[]> & + Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundancies[]> & + Use<'VideoFiles', MVideoFileRedundanciesOpt[]> + +export type MVideoForUser = MVideo & + Use<'VideoChannel', MChannelAccountDefault> & + Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> & + Use<'VideoBlacklist', MVideoBlacklistLight> & + Use<'Thumbnails', MThumbnail[]> -- 2.41.0