From b5fecbf44192144d1ca27c23a0b53922de288c10 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Aug 2019 14:31:57 +0200 Subject: [PATCH] Type toActivityPubObject functions --- server/controllers/activitypub/client.ts | 4 ++-- server/controllers/api/video-channel.ts | 3 ++- server/helpers/utils.ts | 5 ++++- server/lib/activitypub/send/send-update.ts | 6 +++--- .../validators/videos/video-playlists.ts | 2 +- server/models/account/account.ts | 4 ++-- server/models/activitypub/actor.ts | 13 +++++++------ server/models/redundancy/video-redundancy.ts | 4 ++-- server/models/video/video-channel.ts | 7 +++++-- server/models/video/video-comment.ts | 3 ++- server/models/video/video-format-utils.ts | 4 ++-- server/models/video/video-playlist-element.ts | 8 ++++++-- server/models/video/video-playlist.ts | 4 ++-- server/models/video/video.ts | 15 +++++++++------ server/typings/express.ts | 3 ++- server/typings/models/account/account.ts | 4 ++++ server/typings/models/account/actor.ts | 9 ++++++--- server/typings/models/video/video-channels.ts | 10 +++++++++- server/typings/models/video/video-comment.ts | 12 +++++++++--- .../models/video/video-playlist-element.ts | 9 ++++----- server/typings/models/video/video-playlist.ts | 6 +++++- server/typings/models/video/video-redundancy.ts | 16 ++++++++++++++-- .../models/video/video-streaming-playlist.ts | 7 +++++-- server/typings/models/video/video.ts | 4 ++-- 24 files changed, 109 insertions(+), 53 deletions(-) diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 98f5c8865..453ced8bf 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -214,7 +214,7 @@ async function videoController (req: express.Request, res: express.Response) { // We need captions to render AP object const captions = await VideoCaptionModel.listVideoCaptions(video.id) - const videoWithCaptions: MVideoAPWithoutCaption = Object.assign(video, { VideoCaptions: captions }) + const videoWithCaptions = Object.assign(video, { VideoCaptions: captions }) const audience = getAudience(videoWithCaptions.VideoChannel.Account.Actor, videoWithCaptions.privacy === VideoPrivacy.PUBLIC) const videoObject = audiencify(videoWithCaptions.toActivityPubObject(), audience) @@ -351,7 +351,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo } async function videoPlaylistElementController (req: express.Request, res: express.Response) { - const videoPlaylistElement = res.locals.videoPlaylistElement + const videoPlaylistElement = res.locals.videoPlaylistElementAP const json = videoPlaylistElement.toActivityPubObject() return activityPubResponse(activityPubContextify(json), res) diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index d4ca7a0af..acc5b2987 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -35,6 +35,7 @@ import { VideoPlaylistModel } from '../../models/video/video-playlist' import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' import { CONFIG } from '../../initializers/config' import { sequelizeTypescript } from '../../initializers/database' +import { MChannelAccountDefault } from '@server/typings/models' const auditLogger = auditLoggerFactory('channels') const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) @@ -181,7 +182,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) } } - const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) + const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) as MChannelAccountDefault await sendUpdateActor(videoChannelInstanceUpdated, t) auditLogger.update( diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 1464b1477..ba07eaaf3 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -19,7 +19,10 @@ async function generateRandomString (size: number) { return raw.toString('hex') } -interface FormattableToJSON { toFormattedJSON (args?: U): V } +interface FormattableToJSON { + toFormattedJSON (args?: U): V +} + function getFormattedObjects> (objects: T[], objectsTotal: number, formattedArg?: U) { const formattedObjects = objects.map(o => o.toFormattedJSON(formattedArg)) diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 3a5cc1853..37517c2be 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -12,10 +12,10 @@ import { VideoCaptionModel } from '../../../models/video/video-caption' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' import { getServerActor } from '../../../helpers/utils' import { - MAccountActor, + MAccountDefault, MActor, MActorLight, - MChannelActor, + MChannelDefault, MVideoAP, MVideoAPWithoutCaption, MVideoPlaylistFull, @@ -49,7 +49,7 @@ async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t) } -async function sendUpdateActor (accountOrChannel: MAccountActor | MChannelActor, t: Transaction) { +async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefault, t: Transaction) { const byActor = accountOrChannel.Actor logger.info('Creating job to update actor %s.', byActor.url) diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index ca36d419a..27ee62b1f 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts @@ -267,7 +267,7 @@ const videoPlaylistElementAPGetValidator = [ return res.status(403).end() } - res.locals.videoPlaylistElement = videoPlaylistElement + res.locals.videoPlaylistElementAP = videoPlaylistElement return next() } diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 8369738b9..394a55f5e 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -32,7 +32,7 @@ import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequ import { AccountBlocklistModel } from './account-blocklist' import { ServerBlocklistModel } from '../server/server-blocklist' import { ActorFollowModel } from '../activitypub/actor-follow' -import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable } from '../../typings/models' +import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable, MAccountAP } from '../../typings/models' import * as Bluebird from 'bluebird' export enum ScopeNames { @@ -380,7 +380,7 @@ export class AccountModel extends Model { } } - toActivityPubObject () { + toActivityPubObject (this: MAccountAP) { const obj = this.Actor.toActivityPubObject(this.name, 'Account') return Object.assign(obj, { diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index e2213afa1..fb4327e4f 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -39,12 +39,13 @@ import { VideoModel } from '../video/video' import { MActor, MActorAccountChannelId, + MActorAP, MActorFormattable, - MActorFull, MActorHost, + MActorFull, + MActorHost, + MActorRedundancyAllowedOpt, MActorServer, - MActorSummaryFormattable, - MServerHost, - MActorRedundancyAllowed + MActorSummaryFormattable } from '../../typings/models' import * as Bluebird from 'bluebird' @@ -429,7 +430,7 @@ export class ActorModel extends Model { }) } - toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') { + toActivityPubObject (this: MActorAP, name: string, type: 'Account' | 'Application' | 'VideoChannel') { let activityPubType if (type === 'Account') { activityPubType = 'Person' as 'Person' @@ -528,7 +529,7 @@ export class ActorModel extends Model { return this.Server ? this.Server.host : WEBSERVER.HOST } - getRedundancyAllowed (this: MActorRedundancyAllowed) { + getRedundancyAllowed () { return this.Server ? this.Server.redundancyAllowed : false } diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index 1c216b300..61d9a5612 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts @@ -30,7 +30,7 @@ import * as Bluebird from 'bluebird' import { col, FindOptions, fn, literal, Op, Transaction } from 'sequelize' import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' import { CONFIG } from '../../initializers/config' -import { MVideoRedundancy, MVideoRedundancyVideo } from '@server/typings/models' +import { MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/typings/models' export enum ScopeNames { WITH_VIDEO = 'WITH_VIDEO' @@ -488,7 +488,7 @@ export class VideoRedundancyModel extends Model { return !!this.strategy } - toActivityPubObject (): CacheFileObject { + toActivityPubObject (this: MVideoRedundancyAP): CacheFileObject { if (this.VideoStreamingPlaylist) { return { id: this.url, diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 7a4df516a..7178631b4 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -37,7 +37,10 @@ import * as Bluebird from 'bluebird' import { MChannelAccountDefault, MChannelActor, - MChannelActorAccountDefaultVideos, MChannelSummaryFormattable, MChannelFormattable + MChannelActorAccountDefaultVideos, + MChannelAP, + MChannelFormattable, + MChannelSummaryFormattable } from '../../typings/models/video' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation @@ -513,7 +516,7 @@ export class VideoChannelModel extends Model { return Object.assign(actor, videoChannel) } - toActivityPubObject (): ActivityPubActor { + toActivityPubObject (this: MChannelAP): ActivityPubActor { const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel') return Object.assign(obj, { diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 84d71c553..2e4220434 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -17,6 +17,7 @@ import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'se import * as Bluebird from 'bluebird' import { MComment, + MCommentAP, MCommentFormattable, MCommentId, MCommentOwner, @@ -491,7 +492,7 @@ export class VideoCommentModel extends Model { } as VideoComment } - toActivityPubObject (threadParentComments: MCommentOwner[]): VideoCommentObject { + toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject { let inReplyTo: string // New thread, so in AS we reply to the video if (this.inReplyToCommentId === null) { diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 6aa7c1e3e..2987aa780 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -16,7 +16,7 @@ import { } from '../../lib/activitypub' import { isArray } from '../../helpers/custom-validators/misc' import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' -import { MVideo, MVideoAP, MVideoFormattable, MVideoFormattableDetails } from '../../typings/models' +import { MStreamingPlaylistRedundanciesOpt, MVideo, MVideoAP, MVideoFormattable, MVideoFormattableDetails } from '../../typings/models' import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' @@ -143,7 +143,7 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid return Object.assign(formattedJson, detailsJson) } -function streamingPlaylistsModelToFormattedJSON (playlists: MStreamingPlaylistRedundancies[]): VideoStreamingPlaylist[] { +function streamingPlaylistsModelToFormattedJSON (playlists: MStreamingPlaylistRedundanciesOpt[]): VideoStreamingPlaylist[] { if (isArray(playlists) === false) return [] return playlists diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 80ca22a18..a28021313 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -29,6 +29,7 @@ import { MVideoPlaylistElement, MVideoPlaylistElementAP, MVideoPlaylistElementFormattable, + MVideoPlaylistElementVideoUrlPlaylistPrivacy, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' import { MUserAccountId } from '@server/typings/models' @@ -184,7 +185,10 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementModel.findByPk(playlistElementId) } - static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird { + static loadByPlaylistAndVideoForAP ( + playlistId: number | string, + videoId: number | string + ): Bluebird { const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } @@ -336,7 +340,7 @@ export class VideoPlaylistElementModel extends Model } } - toActivityPubObject (): PlaylistElementObject { + toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject { const base: PlaylistElementObject = { id: this.url, type: 'PlaylistElement', diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 80dd65322..278d80ac0 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -45,7 +45,7 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects' import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' import * as Bluebird from 'bluebird' import { - MVideoPlaylistAccountThumbnail, + MVideoPlaylistAccountThumbnail, MVideoPlaylistAP, MVideoPlaylistFormattable, MVideoPlaylistFull, MVideoPlaylistFullSummary, @@ -510,7 +510,7 @@ export class VideoPlaylistModel extends Model { } } - toActivityPubObject (page: number, t: Transaction): Promise { + toActivityPubObject (this: MVideoPlaylistAP, page: number, t: Transaction): Promise { const handler = (start: number, count: number) => { return VideoPlaylistElementModel.listUrlsOfForAP(this.id, start, count, t) } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 9c24d1ba8..ab7b49f1e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -127,14 +127,17 @@ import { MUserId, MVideoAccountLight, MVideoAccountLightBlacklistAllFiles, + MVideoAP, MVideoDetails, + MVideoFormattable, + MVideoFormattableDetails, MVideoForUser, MVideoFullLight, MVideoIdThumbnail, MVideoThumbnail, - MVideoWithAllFiles, MVideoWithFile, - MVideoWithRights, - MVideoFormattable + MVideoWithAllFiles, + MVideoWithFile, + MVideoWithRights } from '../../typings/models' import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' import { MThumbnail } from '../../typings/models/video/thumbnail' @@ -1879,11 +1882,11 @@ export class VideoModel extends Model { return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) } - toFormattedJSON (this: T, options?: VideoFormattingJSONOptions): Video { + toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { return videoModelToFormattedJSON(this, options) } - toFormattedDetailsJSON (): VideoDetails { + toFormattedDetailsJSON (this: MVideoFormattableDetails): VideoDetails { return videoModelToFormattedDetailsJSON(this) } @@ -1891,7 +1894,7 @@ export class VideoModel extends Model { return videoFilesModelToFormattedJSON(this, this.VideoFiles) } - toActivityPubObject (): VideoTorrentObject { + toActivityPubObject (this: MVideoAP): VideoTorrentObject { return videoModelToActivityPubObject(this) } diff --git a/server/typings/express.ts b/server/typings/express.ts index 1fd809c1b..3cc7c7632 100644 --- a/server/typings/express.ts +++ b/server/typings/express.ts @@ -22,7 +22,7 @@ import { import { MVideoPlaylistFull, MVideoPlaylistFullSummary } from './models/video/video-playlist' import { MVideoImportDefault } from '@server/typings/models/video/video-import' import { MAccountBlocklist, MStreamingPlaylist, MVideoFile } from '@server/typings/models' -import { MVideoPlaylistElement } from '@server/typings/models/video/video-playlist-element' +import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/typings/models/video/video-playlist-element' import { MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate' import { MVideoChangeOwnershipFull } from './models/video/video-change-ownership' import { MPlugin, MServer } from '@server/typings/models/server' @@ -59,6 +59,7 @@ declare module 'express' { videoPlaylistSummary?: MVideoPlaylistFullSummary videoPlaylistElement?: MVideoPlaylistElement + videoPlaylistElementAP?: MVideoPlaylistElementVideoUrlPlaylistPrivacy accountVideoRate?: MAccountVideoRateAccountVideo diff --git a/server/typings/models/account/account.ts b/server/typings/models/account/account.ts index cd20fe81b..ec78fece8 100644 --- a/server/typings/models/account/account.ts +++ b/server/typings/models/account/account.ts @@ -1,6 +1,7 @@ import { AccountModel } from '../../../models/account/account' import { MActor, + MActorAP, MActorAPI, MActorAudience, MActorDefault, @@ -89,3 +90,6 @@ export type MAccountSummaryFormattable = FunctionProperties & export type MAccountFormattable = FunctionProperties & Pick & Use<'Actor', MActorFormattable> + +export type MAccountAP = Pick & + Use<'Actor', MActorAP> diff --git a/server/typings/models/account/actor.ts b/server/typings/models/account/actor.ts index 14ab2cd5b..d4bcac4a3 100644 --- a/server/typings/models/account/actor.ts +++ b/server/typings/models/account/actor.ts @@ -1,5 +1,5 @@ import { ActorModel } from '../../../models/activitypub/actor' -import { FunctionProperties, PickWith } from '../../utils' +import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server' import { MAvatar, MAvatarFormattable } from './avatar' @@ -29,7 +29,7 @@ export type MActorLight = Omit // Some association attributes export type MActorHost = Use<'Server', MServerHost> -export type MActorRedundancyAllowed = Use<'Server', MServerRedundancyAllowed> +export type MActorRedundancyAllowedOpt = PickWithOpt export type MActorDefaultLight = MActorLight & Use<'Server', MServerHost> & @@ -115,4 +115,7 @@ export type MActorSummaryFormattable = FunctionProperties & export type MActorFormattable = MActorSummaryFormattable & Pick & - Use<'Server', MServer> + Use<'Server', MServerHost & Partial>> + +export type MActorAP = MActor & + Use<'Avatar', MAvatar> diff --git a/server/typings/models/video/video-channels.ts b/server/typings/models/video/video-channels.ts index 2be7dd7ed..292d0ac95 100644 --- a/server/typings/models/video/video-channels.ts +++ b/server/typings/models/video/video-channels.ts @@ -8,16 +8,18 @@ import { MAccountLight, MAccountSummaryBlocks, MAccountSummaryFormattable, + MAccountUrl, MAccountUserId, MActor, MActorAccountChannelId, + MActorAP, MActorAPI, MActorDefault, MActorDefaultLight, MActorFormattable, MActorLight, MActorSummary, - MActorSummaryFormattable + MActorSummaryFormattable, MActorUrl } from '../account' import { MVideo } from './video' @@ -42,6 +44,8 @@ export type MChannelUserId = Pick & export type MChannelActor = MChannel & Use<'Actor', MActor> +export type MChannelUrl = Use<'Actor', MActorUrl> + // Default scope export type MChannelDefault = MChannel & Use<'Actor', MActorDefault> @@ -116,3 +120,7 @@ export type MChannelFormattable = FunctionProperties & Pick & Use<'Actor', MActorFormattable> & PickWithOpt + +export type MChannelAP = Pick & + Use<'Actor', MActorAP> & + Use<'Account', MAccountUrl> diff --git a/server/typings/models/video/video-comment.ts b/server/typings/models/video/video-comment.ts index e8bccba0f..4fd1c29e8 100644 --- a/server/typings/models/video/video-comment.ts +++ b/server/typings/models/video/video-comment.ts @@ -1,7 +1,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' -import { PickWith } from '../../utils' -import { MAccountDefault, MAccountFormattable } from '../account' -import { MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video' +import { PickWith, PickWithOpt } from '../../utils' +import { MAccountDefault, MAccountFormattable, MAccountUrl, MActorUrl } from '../account' +import { MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video' type Use = PickWith @@ -10,6 +10,7 @@ type Use = PickWith export type MCommentTotalReplies = MComment & { totalReplies?: number } export type MCommentId = Pick +export type MCommentUrl = Pick // ############################################################################ @@ -49,3 +50,8 @@ export type MCommentAPI = MComment & { totalReplies: number } export type MCommentFormattable = MCommentTotalReplies & Use<'Account', MAccountFormattable> + +export type MCommentAP = MComment & + Use<'Account', MAccountUrl> & + PickWithOpt & + PickWithOpt diff --git a/server/typings/models/video/video-playlist-element.ts b/server/typings/models/video/video-playlist-element.ts index 1c256fd25..7b1b993ce 100644 --- a/server/typings/models/video/video-playlist-element.ts +++ b/server/typings/models/video/video-playlist-element.ts @@ -19,11 +19,7 @@ export type MVideoPlaylistElementLight = Pick -// ############################################################################ - -// For API - -export type MVideoPlaylistElementAP = MVideoPlaylistElement & +export type MVideoPlaylistElementVideoUrlPlaylistPrivacy = MVideoPlaylistElement & Use<'Video', MVideoUrl> & Use<'VideoPlaylist', MVideoPlaylistPrivacy> @@ -33,3 +29,6 @@ export type MVideoPlaylistElementAP = MVideoPlaylistElement & export type MVideoPlaylistElementFormattable = MVideoPlaylistElement & Use<'Video', MVideoFormattable> + +export type MVideoPlaylistElementAP = MVideoPlaylistElement & + Use<'Video', MVideoUrl> diff --git a/server/typings/models/video/video-playlist.ts b/server/typings/models/video/video-playlist.ts index a926106c5..a40c7aca9 100644 --- a/server/typings/models/video/video-playlist.ts +++ b/server/typings/models/video/video-playlist.ts @@ -2,7 +2,7 @@ import { VideoPlaylistModel } from '../../../models/video/video-playlist' import { PickWith } from '../../utils' import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account' import { MThumbnail } from './thumbnail' -import { MChannelDefault, MChannelSummary, MChannelSummaryFormattable } from './video-channels' +import { MChannelDefault, MChannelSummary, MChannelSummaryFormattable, MChannelUrl } from './video-channels' import { MVideoPlaylistElementLight } from '@server/typings/models/video/video-playlist-element' type Use = PickWith @@ -86,3 +86,7 @@ export type MVideoPlaylistFullSummary = MVideoPlaylist & export type MVideoPlaylistFormattable = MVideoPlaylistVideosLength & Use<'OwnerAccount', MAccountSummaryFormattable> & Use<'VideoChannel', MChannelSummaryFormattable> + +export type MVideoPlaylistAP = MVideoPlaylist & + Use<'Thumbnail', MThumbnail> & + Use<'VideoChannel', MChannelUrl> diff --git a/server/typings/models/video/video-redundancy.ts b/server/typings/models/video/video-redundancy.ts index c25eb9c09..f3846afd7 100644 --- a/server/typings/models/video/video-redundancy.ts +++ b/server/typings/models/video/video-redundancy.ts @@ -1,6 +1,10 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' -import { PickWith } from '@server/typings/utils' -import { MStreamingPlaylistVideo, MVideoFile, MVideoFileVideo } from '@server/typings/models' +import { PickWith, PickWithOpt } from '@server/typings/utils' +import { MStreamingPlaylistVideo, MVideoFile, MVideoFileVideo, MVideoUrl } from '@server/typings/models' +import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' +import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' +import { VideoFile } from '../../../../shared/models/videos' +import { VideoFileModel } from '@server/models/video/video-file' type Use = PickWith @@ -24,3 +28,11 @@ export type MVideoRedundancyStreamingPlaylistVideo = MVideoRedundancy & export type MVideoRedundancyVideo = MVideoRedundancy & Use<'VideoFile', MVideoFileVideo> & Use<'VideoStreamingPlaylist', MStreamingPlaylistVideo> + +// ############################################################################ + +// Format for API or AP object + +export type MVideoRedundancyAP = MVideoRedundancy & + PickWithOpt> & + PickWithOpt> diff --git a/server/typings/models/video/video-streaming-playlist.ts b/server/typings/models/video/video-streaming-playlist.ts index f1b3438b6..79696bcff 100644 --- a/server/typings/models/video/video-streaming-playlist.ts +++ b/server/typings/models/video/video-streaming-playlist.ts @@ -1,7 +1,7 @@ import { VideoStreamingPlaylistModel } from '../../../models/video/video-streaming-playlist' -import { PickWith } from '../../utils' +import { PickWith, PickWithOpt } from '../../utils' import { MVideoRedundancyFileUrl } from './video-redundancy' -import { MVideo } from '@server/typings/models' +import { MVideo, MVideoUrl } from '@server/typings/models' type Use = PickWith @@ -14,3 +14,6 @@ export type MStreamingPlaylistVideo = MStreamingPlaylist & export type MStreamingPlaylistRedundancies = MStreamingPlaylist & Use<'RedundancyVideos', MVideoRedundancyFileUrl[]> + +export type MStreamingPlaylistRedundanciesOpt = MStreamingPlaylist & + PickWithOpt diff --git a/server/typings/models/video/video.ts b/server/typings/models/video/video.ts index bc6d56607..be32d4617 100644 --- a/server/typings/models/video/video.ts +++ b/server/typings/models/video/video.ts @@ -10,7 +10,7 @@ import { } from './video-channels' import { MTag } from './tag' import { MVideoCaptionLanguage } from './video-caption' -import { MStreamingPlaylist, MStreamingPlaylistRedundancies } from './video-streaming-playlist' +import { MStreamingPlaylist, MStreamingPlaylistRedundancies, MStreamingPlaylistRedundanciesOpt } from './video-streaming-playlist' import { MVideoFile, MVideoFileRedundanciesOpt } from './video-file' import { MThumbnail } from './thumbnail' import { MVideoBlacklist, MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist' @@ -165,5 +165,5 @@ export type MVideoFormattable = MVideo & export type MVideoFormattableDetails = MVideoFormattable & Use<'VideoChannel', MChannelFormattable> & Use<'Tags', MTag[]> & - Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundancies[]> & + Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundanciesOpt[]> & Use<'VideoFiles', MVideoFileRedundanciesOpt[]>