From b5fecbf44192144d1ca27c23a0b53922de288c10 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Aug 2019 14:31:57 +0200 Subject: Type toActivityPubObject functions --- 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 +++++++++------ 6 files changed, 26 insertions(+), 15 deletions(-) (limited to 'server/models/video') 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) } -- cgit v1.2.3