From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- server/models/video/video-abuse.ts | 8 +- server/models/video/video-blacklist.ts | 6 +- server/models/video/video-caption.ts | 8 +- server/models/video/video-change-ownership.ts | 6 +- server/models/video/video-channel.ts | 35 +++++--- server/models/video/video-comment.ts | 83 ++++++------------ server/models/video/video-file.ts | 3 +- server/models/video/video-format-utils.ts | 15 ++-- server/models/video/video-import.ts | 12 ++- server/models/video/video-playlist-element.ts | 13 +-- server/models/video/video-playlist.ts | 18 ++-- server/models/video/video-share.ts | 14 +-- server/models/video/video-streaming-playlist.ts | 12 +-- server/models/video/video.ts | 111 +++++++++++++----------- 14 files changed, 179 insertions(+), 165 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 1ac7919b3..af7b40d11 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -11,6 +11,8 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoAbuseState } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' +import { MVideoAbuse, MVideoAbuseAccountVideo, MVideoAbuseVideo } from '../../typings/models' +import * as Bluebird from 'bluebird' @Table({ tableName: 'videoAbuse', @@ -73,7 +75,7 @@ export class VideoAbuseModel extends Model { }) Video: VideoModel - static loadByIdAndVideoId (id: number, videoId: number) { + static loadByIdAndVideoId (id: number, videoId: number): Bluebird { const query = { where: { id, @@ -106,7 +108,7 @@ export class VideoAbuseModel extends Model { }) } - toFormattedJSON (): VideoAbuse { + toFormattedJSON (this: MVideoAbuseAccountVideo): VideoAbuse { return { id: this.id, reason: this.reason, @@ -125,7 +127,7 @@ export class VideoAbuseModel extends Model { } } - toActivityPubObject (): VideoAbuseObject { + toActivityPubObject (this: MVideoAbuseVideo): VideoAbuseObject { return { type: 'Flag' as 'Flag', content: this.reason, diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 22d949da0..5a0cac94a 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -1,12 +1,14 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { getSortOnModel, SortType, throwIfNotValid } from '../utils' -import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' +import { VideoModel } from './video' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { FindOptions } from 'sequelize' import { ThumbnailModel } from './thumbnail' +import * as Bluebird from 'bluebird' +import { MVideoBlacklist } from '@server/typings/models' @Table({ tableName: 'videoBlacklist', @@ -99,7 +101,7 @@ export class VideoBlacklistModel extends Model { }) } - static loadByVideoId (id: number) { + static loadByVideoId (id: number): Bluebird { const query = { where: { videoId: id diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index a01565851..9ce350d12 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts @@ -21,6 +21,8 @@ import { join } from 'path' import { logger } from '../../helpers/logger' import { remove } from 'fs-extra' import { CONFIG } from '../../initializers/config' +import * as Bluebird from 'bluebird' +import { MVideoCaptionVideo } from '@server/typings/models' export enum ScopeNames { WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' @@ -30,7 +32,7 @@ export enum ScopeNames { [ScopeNames.WITH_VIDEO_UUID_AND_REMOTE]: { include: [ { - attributes: [ 'uuid', 'remote' ], + attributes: [ 'id', 'uuid', 'remote' ], model: VideoModel.unscoped(), required: true } @@ -93,7 +95,7 @@ export class VideoCaptionModel extends Model { return undefined } - static loadByVideoIdAndLanguage (videoId: string | number, language: string) { + static loadByVideoIdAndLanguage (videoId: string | number, language: string): Bluebird { const videoInclude = { model: VideoModel.unscoped(), attributes: [ 'id', 'remote', 'uuid' ], @@ -122,7 +124,7 @@ export class VideoCaptionModel extends Model { .then(([ caption ]) => caption) } - static listVideoCaptions (videoId: number) { + static listVideoCaptions (videoId: number): Bluebird { const query = { order: [ [ 'language', 'ASC' ] ] as OrderItem[], where: { diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index b545a2f8c..2d0ff48fb 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts @@ -3,6 +3,8 @@ import { AccountModel } from '../account/account' import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' import { getSort } from '../utils' +import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' +import * as Bluebird from 'bluebird' enum ScopeNames { WITH_ACCOUNTS = 'WITH_ACCOUNTS', @@ -108,11 +110,11 @@ export class VideoChangeOwnershipModel extends Model return Promise.all([ VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query), - VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query) + VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query) ]).then(([ count, rows ]) => ({ total: count, data: rows })) } - static load (id: number) { + static load (id: number): Bluebird { return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]) .findByPk(id) } diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 6241a75a3..79b9e7d2b 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -33,6 +33,13 @@ import { ServerModel } from '../server/server' import { FindOptions, ModelIndexesOptions, Op } from 'sequelize' import { AvatarModel } from '../avatar/avatar' import { VideoPlaylistModel } from './video-playlist' +import * as Bluebird from 'bluebird' +import { + MChannelAccountDefault, + MChannelActor, + MChannelActorAccountDefault, + MChannelActorAccountDefaultVideos +} from '../../typings/models/video' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation const indexes: ModelIndexesOptions[] = [ @@ -47,7 +54,7 @@ const indexes: ModelIndexesOptions[] = [ ] export enum ScopeNames { - AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', + FOR_API = 'FOR_API', WITH_ACCOUNT = 'WITH_ACCOUNT', WITH_ACTOR = 'WITH_ACTOR', WITH_VIDEOS = 'WITH_VIDEOS', @@ -74,10 +81,10 @@ export type SummaryOptions = { @Scopes(() => ({ [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { const base: FindOptions = { - attributes: [ 'name', 'description', 'id', 'actorId' ], + attributes: [ 'id', 'name', 'description', 'actorId' ], include: [ { - attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], + attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], model: ActorModel.unscoped(), required: true, include: [ @@ -106,7 +113,7 @@ export type SummaryOptions = { return base }, - [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { + [ScopeNames.FOR_API]: (options: AvailableForListOptions) => { // Only list local channels OR channels that are on an instance followed by actorId const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId) @@ -268,7 +275,7 @@ export class VideoChannelModel extends Model { } const scopes = { - method: [ ScopeNames.AVAILABLE_FOR_LIST, { actorId } as AvailableForListOptions ] + method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] } return VideoChannelModel .scope(scopes) @@ -278,7 +285,7 @@ export class VideoChannelModel extends Model { }) } - static listLocalsForSitemap (sort: string) { + static listLocalsForSitemap (sort: string): Bluebird { const query = { attributes: [ ], offset: 0, @@ -331,7 +338,7 @@ export class VideoChannelModel extends Model { } const scopes = { - method: [ ScopeNames.AVAILABLE_FOR_LIST, { actorId: options.actorId } as AvailableForListOptions ] + method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] } return VideoChannelModel .scope(scopes) @@ -369,13 +376,13 @@ export class VideoChannelModel extends Model { }) } - static loadByIdAndPopulateAccount (id: number) { + static loadByIdAndPopulateAccount (id: number): Bluebird { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) } - static loadByIdAndAccount (id: number, accountId: number) { + static loadByIdAndAccount (id: number, accountId: number): Bluebird { const query = { where: { id, @@ -388,13 +395,13 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadAndPopulateAccount (id: number) { + static loadAndPopulateAccount (id: number): Bluebird { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) } - static loadByUrlAndPopulateAccount (url: string) { + static loadByUrlAndPopulateAccount (url: string): Bluebird { const query = { include: [ { @@ -420,7 +427,7 @@ export class VideoChannelModel extends Model { return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) } - static loadLocalByNameAndPopulateAccount (name: string) { + static loadLocalByNameAndPopulateAccount (name: string): Bluebird { const query = { include: [ { @@ -439,7 +446,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadByNameAndHostAndPopulateAccount (name: string, host: string) { + static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird { const query = { include: [ { @@ -464,7 +471,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadAndPopulateAccountAndVideos (id: number) { + static loadAndPopulateAccountAndVideos (id: number): Bluebird { const options = { include: [ VideoModel diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 58b75510d..c88dac1c1 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -1,36 +1,30 @@ -import { - AllowNull, - BeforeDestroy, - BelongsTo, - Column, - CreatedAt, - DataType, - ForeignKey, - Is, - Model, - Scopes, - Table, - UpdatedAt -} from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' import { VideoComment } from '../../../shared/models/videos/video-comment.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' -import { sendDeleteVideoComment } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' import { ActorModel } from '../activitypub/actor' -import { AvatarModel } from '../avatar/avatar' -import { ServerModel } from '../server/server' import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoChannelModel } from './video-channel' import { getServerActor } from '../../helpers/utils' -import { UserModel } from '../account/user' import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' import { regexpCapture } from '../../helpers/regexp' import { uniq } from 'lodash' -import { FindOptions, literal, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' +import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' +import * as Bluebird from 'bluebird' +import { + MComment, + MCommentId, + MCommentOwner, + MCommentOwnerReplyVideoLight, + MCommentOwnerVideo, + MCommentOwnerVideoFeed, + MCommentOwnerVideoReply +} from '../../typings/models/video' +import { MUserAccountId } from '@server/typings/models' enum ScopeNames { WITH_ACCOUNT = 'WITH_ACCOUNT', @@ -68,22 +62,7 @@ enum ScopeNames { [ScopeNames.WITH_ACCOUNT]: { include: [ { - model: AccountModel, - include: [ - { - model: ActorModel, - include: [ - { - model: ServerModel, - required: false - }, - { - model: AvatarModel, - required: false - } - ] - } - ] + model: AccountModel } ] }, @@ -102,22 +81,12 @@ enum ScopeNames { required: true, include: [ { - model: VideoChannelModel.unscoped(), + model: VideoChannelModel, required: true, include: [ - { - model: ActorModel, - required: true - }, { model: AccountModel, - required: true, - include: [ - { - model: ActorModel, - required: true - } - ] + required: true } ] } @@ -212,7 +181,7 @@ export class VideoCommentModel extends Model { }) Account: AccountModel - static loadById (id: number, t?: Transaction) { + static loadById (id: number, t?: Transaction): Bluebird { const query: FindOptions = { where: { id @@ -224,7 +193,7 @@ export class VideoCommentModel extends Model { return VideoCommentModel.findOne(query) } - static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction) { + static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction): Bluebird { const query: FindOptions = { where: { id @@ -238,7 +207,7 @@ export class VideoCommentModel extends Model { .findOne(query) } - static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction) { + static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction): Bluebird { const query: FindOptions = { where: { url @@ -250,7 +219,7 @@ export class VideoCommentModel extends Model { return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query) } - static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction) { + static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction): Bluebird { const query: FindOptions = { where: { url @@ -273,7 +242,7 @@ export class VideoCommentModel extends Model { start: number, count: number, sort: string, - user?: UserModel + user?: MUserAccountId }) { const { videoId, start, count, sort, user } = parameters @@ -314,7 +283,7 @@ export class VideoCommentModel extends Model { static async listThreadCommentsForApi (parameters: { videoId: number, threadId: number, - user?: UserModel + user?: MUserAccountId }) { const { videoId, threadId, user } = parameters @@ -353,7 +322,7 @@ export class VideoCommentModel extends Model { }) } - static listThreadParentComments (comment: VideoCommentModel, t: Transaction, order: 'ASC' | 'DESC' = 'ASC') { + static listThreadParentComments (comment: MCommentId, t: Transaction, order: 'ASC' | 'DESC' = 'ASC'): Bluebird { const query = { order: [ [ 'createdAt', order ] ] as Order, where: { @@ -389,10 +358,10 @@ export class VideoCommentModel extends Model { transaction: t } - return VideoCommentModel.findAndCountAll(query) + return VideoCommentModel.findAndCountAll(query) } - static listForFeed (start: number, count: number, videoId?: number) { + static listForFeed (start: number, count: number, videoId?: number): Bluebird { const query = { order: [ [ 'createdAt', 'DESC' ] ] as Order, offset: start, @@ -521,7 +490,7 @@ export class VideoCommentModel extends Model { } as VideoComment } - toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject { + toActivityPubObject (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-file.ts b/server/models/video/video-file.ts index 05c490759..6304f741c 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -25,6 +25,7 @@ import { VideoRedundancyModel } from '../redundancy/video-redundancy' import { VideoStreamingPlaylistModel } from './video-streaming-playlist' import { FindOptions, QueryTypes, Transaction } from 'sequelize' import { MIMETYPES } from '../../initializers/constants' +import { MVideoFile } from '@server/typings/models' @Table({ tableName: 'videoFile', @@ -166,7 +167,7 @@ export class VideoFileModel extends Model { return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname] } - hasSameUniqueKeysThan (other: VideoFileModel) { + hasSameUniqueKeysThan (other: MVideoFile) { return this.fps === other.fps && this.resolution === other.resolution && this.videoId === other.videoId diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 284539def..4e7eb5f0c 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -1,6 +1,5 @@ import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' import { VideoModel } from './video' -import { VideoFileModel } from './video-file' import { ActivityPlaylistInfohashesObject, ActivityPlaylistSegmentHashesObject, @@ -17,7 +16,9 @@ import { } from '../../lib/activitypub' import { isArray } from '../../helpers/custom-validators/misc' import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' -import { VideoStreamingPlaylistModel } from './video-streaming-playlist' +import { MVideo, MVideoAP, MVideoDetails } from '../../typings/models' +import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' +import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' export type VideoFormattingJSONOptions = { completeDescription?: boolean @@ -102,7 +103,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting return videoObject } -function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { +function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails { const formattedJson = video.toFormattedJSON({ additionalAttributes: { scheduledUpdate: true, @@ -114,7 +115,7 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { const tags = video.Tags ? video.Tags.map(t => t.name) : [] - const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists) + const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video.VideoStreamingPlaylists) const detailsJson = { support: video.support, @@ -142,7 +143,7 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails { return Object.assign(formattedJson, detailsJson) } -function streamingPlaylistsModelToFormattedJSON (video: VideoModel, playlists: VideoStreamingPlaylistModel[]): VideoStreamingPlaylist[] { +function streamingPlaylistsModelToFormattedJSON (playlists: MStreamingPlaylistRedundancies[]): VideoStreamingPlaylist[] { if (isArray(playlists) === false) return [] return playlists @@ -161,7 +162,7 @@ function streamingPlaylistsModelToFormattedJSON (video: VideoModel, playlists: V }) } -function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFileModel[]): VideoFile[] { +function videoFilesModelToFormattedJSON (video: MVideo, videoFiles: MVideoFileRedundanciesOpt[]): VideoFile[] { const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() return videoFiles @@ -189,7 +190,7 @@ function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFil }) } -function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { +function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject { const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() if (!video.Tags) video.Tags = [] diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index 480a671c8..f596eea9d 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts @@ -20,6 +20,8 @@ import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../help import { VideoImport, VideoImportState } from '../../../shared' import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' import { UserModel } from '../account/user' +import * as Bluebird from 'bluebird' +import { MVideoImportDefault } from '@server/typings/models/video/video-import' @DefaultScope(() => ({ include: [ @@ -28,7 +30,11 @@ import { UserModel } from '../account/user' required: true }, { - model: VideoModel.scope([ VideoModelScopeNames.WITH_ACCOUNT_DETAILS, VideoModelScopeNames.WITH_TAGS]), + model: VideoModel.scope([ + VideoModelScopeNames.WITH_ACCOUNT_DETAILS, + VideoModelScopeNames.WITH_TAGS, + VideoModelScopeNames.WITH_THUMBNAILS + ]), required: false } ] @@ -114,7 +120,7 @@ export class VideoImportModel extends Model { return undefined } - static loadAndPopulateVideo (id: number) { + static loadAndPopulateVideo (id: number): Bluebird { return VideoImportModel.findByPk(id) } @@ -135,7 +141,7 @@ export class VideoImportModel extends Model { } } - return VideoImportModel.findAndCountAll(query) + return VideoImportModel.findAndCountAll(query) .then(({ rows, count }) => { return { data: rows, diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index dd7653533..901113161 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -25,6 +25,9 @@ import { UserModel } from '../account/user' import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' import { AccountModel } from '../account/account' import { VideoPrivacy } from '../../../shared/models/videos' +import * as Bluebird from 'bluebird' +import { MVideoPlaylistAP, MVideoPlaylistElement, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' +import { MUserAccountId } from '@server/typings/models' @Table({ tableName: 'videoPlaylistElement', @@ -116,7 +119,7 @@ export class VideoPlaylistElementModel extends Model count: number, videoPlaylistId: number, serverAccount: AccountModel, - user?: UserModel + user?: MUserAccountId }) { const accountIds = [ options.serverAccount.id ] const videoScope: (ScopeOptions | string)[] = [ @@ -162,7 +165,7 @@ export class VideoPlaylistElementModel extends Model ]).then(([ total, data ]) => ({ total, data })) } - static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number) { + static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number): Bluebird { const query = { where: { videoPlaylistId, @@ -173,11 +176,11 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementModel.findOne(query) } - static loadById (playlistElementId: number) { + static loadById (playlistElementId: number): Bluebird { return VideoPlaylistElementModel.findByPk(playlistElementId) } - static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string) { + 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 } @@ -218,7 +221,7 @@ export class VideoPlaylistElementModel extends Model }) } - static loadFirstElementWithVideoThumbnail (videoPlaylistId: number) { + static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Bluebird { const query = { order: getSort('position'), where: { diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index c8e97c491..9f1d03ac5 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -43,6 +43,14 @@ import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video- import { ThumbnailModel } from './thumbnail' import { ActivityIconObject } from '../../../shared/models/activitypub/objects' import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' +import * as Bluebird from 'bluebird' +import { + MVideoPlaylistAccountThumbnail, + MVideoPlaylistFull, + MVideoPlaylistFullSummary, + MVideoPlaylistIdWithElements +} from '../../typings/models/video/video-playlist' +import { MThumbnail } from '../../typings/models/video/thumbnail' enum ScopeNames { AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', @@ -332,7 +340,7 @@ export class VideoPlaylistModel extends Model { }) } - static listPlaylistIdsOf (accountId: number, videoIds: number[]) { + static listPlaylistIdsOf (accountId: number, videoIds: number[]): Bluebird { const query = { attributes: [ 'id' ], where: { @@ -368,7 +376,7 @@ export class VideoPlaylistModel extends Model { .then(e => !!e) } - static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction) { + static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const query = { @@ -381,7 +389,7 @@ export class VideoPlaylistModel extends Model { .findOne(query) } - static loadWithAccountAndChannel (id: number | string, transaction: Transaction) { + static loadWithAccountAndChannel (id: number | string, transaction: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const query = { @@ -394,7 +402,7 @@ export class VideoPlaylistModel extends Model { .findOne(query) } - static loadByUrlAndPopulateAccount (url: string) { + static loadByUrlAndPopulateAccount (url: string): Bluebird { const query = { where: { url @@ -423,7 +431,7 @@ export class VideoPlaylistModel extends Model { return VideoPlaylistModel.update({ privacy: VideoPlaylistPrivacy.PRIVATE, videoChannelId: null }, query) } - async setAndSaveThumbnail (thumbnail: ThumbnailModel, t: Transaction) { + async setAndSaveThumbnail (thumbnail: MThumbnail, t: Transaction) { thumbnail.videoPlaylistId = this.id this.Thumbnail = await thumbnail.save({ transaction: t }) diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index d8ed64557..9019b401a 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -8,6 +8,8 @@ import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoChannelModel } from './video-channel' import { Op, Transaction } from 'sequelize' +import { MVideoShareActor, MVideoShareFull } from '../../typings/models/video' +import { MActorDefault } from '../../typings/models' enum ScopeNames { FULL = 'FULL', @@ -88,7 +90,7 @@ export class VideoShareModel extends Model { }) Video: VideoModel - static load (actorId: number, videoId: number, t?: Transaction) { + static load (actorId: number, videoId: number, t?: Transaction): Bluebird { return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ where: { actorId, @@ -98,7 +100,7 @@ export class VideoShareModel extends Model { }) } - static loadByUrl (url: string, t: Transaction) { + static loadByUrl (url: string, t: Transaction): Bluebird { return VideoShareModel.scope(ScopeNames.FULL).findOne({ where: { url @@ -107,7 +109,7 @@ export class VideoShareModel extends Model { }) } - static loadActorsByShare (videoId: number, t: Transaction) { + static loadActorsByShare (videoId: number, t: Transaction): Bluebird { const query = { where: { videoId @@ -122,10 +124,10 @@ export class VideoShareModel extends Model { } return VideoShareModel.scope(ScopeNames.FULL).findAll(query) - .then(res => res.map(r => r.Actor)) + .then((res: MVideoShareFull[]) => res.map(r => r.Actor)) } - static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird { + static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird { const query = { attributes: [], include: [ @@ -163,7 +165,7 @@ export class VideoShareModel extends Model { .then(res => res.map(r => r.Actor)) } - static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird { + static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird { const query = { attributes: [], include: [ diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 31dc82c54..0ea90d28c 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -1,16 +1,16 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, HasMany, Is, Model, Table, UpdatedAt, DataType } from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' import { throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoRedundancyModel } from '../redundancy/video-redundancy' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' -import { CONSTRAINTS_FIELDS, STATIC_PATHS, P2P_MEDIA_LOADER_PEER_VERSION } from '../../initializers/constants' -import { VideoFileModel } from './video-file' +import { CONSTRAINTS_FIELDS, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_PATHS } from '../../initializers/constants' import { join } from 'path' import { sha1 } from '../../helpers/core-utils' import { isArrayOf } from '../../helpers/custom-validators/misc' -import { QueryTypes, Op } from 'sequelize' +import { Op, QueryTypes } from 'sequelize' +import { MStreamingPlaylist, MVideoFile } from '@server/typings/models' @Table({ tableName: 'videoStreamingPlaylist', @@ -91,7 +91,7 @@ export class VideoStreamingPlaylistModel extends Model results.length === 1) } - static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: VideoFileModel[]) { + static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: MVideoFile[]) { const hashes: string[] = [] // https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L115 @@ -165,7 +165,7 @@ export class VideoStreamingPlaylistModel extends Model { VideoCaptions: VideoCaptionModel[] @BeforeDestroy - static async sendDelete (instance: VideoModel, options) { + static async sendDelete (instance: MVideoAccountLight, options) { if (instance.isOwned()) { if (!instance.VideoChannel) { instance.VideoChannel = await instance.$get('VideoChannel', { include: [ - { - model: AccountModel, - include: [ ActorModel ] - } + ActorModel, + AccountModel ], transaction: options.transaction - }) as VideoChannelModel + }) as MChannelActorAccountDefault } return sendDeleteVideo(instance, options.transaction) @@ -1039,7 +1054,7 @@ export class VideoModel extends Model { return undefined } - static listLocal () { + static listLocal (): Bluebird { const query = { where: { remote: false @@ -1159,7 +1174,7 @@ export class VideoModel extends Model { }) } - static listUserVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { + static listUserVideosForApi (accountId: number, start: number, count: number, sort: string) { function buildBaseQuery (): FindOptions { return { offset: start, @@ -1192,19 +1207,12 @@ export class VideoModel extends Model { ScopeNames.WITH_THUMBNAILS ] - if (withFiles === true) { - findQuery.include.push({ - model: VideoFileModel.unscoped(), - required: true - }) - } - return Promise.all([ VideoModel.count(countQuery), VideoModel.scope(findScopes).findAll(findQuery) ]).then(([ count, rows ]) => { return { - data: rows, + data: rows as MVideoWithBlacklistThumbnailScheduled[], total: count } }) @@ -1228,8 +1236,8 @@ export class VideoModel extends Model { followerActorId?: number videoPlaylistId?: number, trendingDays?: number, - user?: UserModel, - historyOfUser?: UserModel + user?: MUserAccountId, + historyOfUser?: MUserId }, countVideos = true) { if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { throw new Error('Try to filter all-local but no user has not the see all videos right') @@ -1294,7 +1302,7 @@ export class VideoModel extends Model { tagsAllOf?: string[] durationMin?: number // seconds durationMax?: number // seconds - user?: UserModel, + user?: MUserAccountId, filter?: VideoFilter }) { const whereAnd = [] @@ -1387,7 +1395,7 @@ export class VideoModel extends Model { return VideoModel.getAvailableForApi(query, queryOptions) } - static load (id: number | string, t?: Transaction) { + static load (id: number | string, t?: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const options = { where, @@ -1397,7 +1405,7 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) } - static loadWithRights (id: number | string, t?: Transaction) { + static loadWithRights (id: number | string, t?: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const options = { where, @@ -1411,7 +1419,7 @@ export class VideoModel extends Model { ]).findOne(options) } - static loadOnlyId (id: number | string, t?: Transaction) { + static loadOnlyId (id: number | string, t?: Transaction): Bluebird { const where = buildWhereIdOrUUID(id) const options = { @@ -1423,7 +1431,7 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) } - static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean) { + static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird { const where = buildWhereIdOrUUID(id) const query = { @@ -1439,7 +1447,7 @@ export class VideoModel extends Model { ]).findOne(query) } - static loadByUUID (uuid: string) { + static loadByUUID (uuid: string): Bluebird { const options = { where: { uuid @@ -1449,7 +1457,7 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) } - static loadByUrl (url: string, transaction?: Transaction) { + static loadByUrl (url: string, transaction?: Transaction): Bluebird { const query: FindOptions = { where: { url @@ -1460,7 +1468,7 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) } - static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction) { + static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird { const query: FindOptions = { where: { url @@ -1472,11 +1480,12 @@ export class VideoModel extends Model { ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES, ScopeNames.WITH_STREAMING_PLAYLISTS, - ScopeNames.WITH_THUMBNAILS + ScopeNames.WITH_THUMBNAILS, + ScopeNames.WITH_BLACKLISTED ]).findOne(query) } - static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number) { + static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird { const where = buildWhereIdOrUUID(id) const options = { @@ -1508,7 +1517,7 @@ export class VideoModel extends Model { id: number | string, t?: Transaction, userId?: number - }) { + }): Bluebird { const { id, t, userId } = parameters const where = buildWhereIdOrUUID(id) @@ -1586,7 +1595,7 @@ export class VideoModel extends Model { .then(results => results.length === 1) } - static bulkUpdateSupportField (videoChannel: VideoChannelModel, t: Transaction) { + static bulkUpdateSupportField (videoChannel: MChannel, t: Transaction) { const options = { where: { channelId: videoChannel.id @@ -1597,7 +1606,7 @@ export class VideoModel extends Model { return VideoModel.update({ support: videoChannel.support }, options) } - static getAllIdsFromChannel (videoChannel: VideoChannelModel) { + static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird { const query = { attributes: [ 'id' ], where: { @@ -1769,7 +1778,7 @@ export class VideoModel extends Model { return this.VideoFiles.find(f => f.resolution === resolution) } - async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) { + async addAndSaveThumbnail (thumbnail: MThumbnail, transaction: Transaction) { thumbnail.videoId = this.id const savedThumbnail = await thumbnail.save({ transaction }) @@ -1782,7 +1791,7 @@ export class VideoModel extends Model { this.Thumbnails.push(savedThumbnail) } - getVideoFilename (videoFile: VideoFileModel) { + getVideoFilename (videoFile: MVideoFile) { return this.uuid + '-' + videoFile.resolution + videoFile.extname } @@ -1806,7 +1815,7 @@ export class VideoModel extends Model { return this.Thumbnails.find(t => t.type === ThumbnailType.PREVIEW) } - getTorrentFileName (videoFile: VideoFileModel) { + getTorrentFileName (videoFile: MVideoFile) { const extension = '.torrent' return this.uuid + '-' + videoFile.resolution + extension } @@ -1815,15 +1824,15 @@ export class VideoModel extends Model { return this.remote === false } - getTorrentFilePath (videoFile: VideoFileModel) { + getTorrentFilePath (videoFile: MVideoFile) { return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) } - getVideoFilePath (videoFile: VideoFileModel) { + getVideoFilePath (videoFile: MVideoFile) { return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) } - async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { + async createTorrentAndSetInfoHash (videoFile: MVideoFile) { const options = { // Keep the extname, it's used by the client to stream the file inside a web browser name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, @@ -1908,7 +1917,7 @@ export class VideoModel extends Model { return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) } - removeFile (videoFile: VideoFileModel, isRedundancy = false) { + removeFile (videoFile: MVideoFile, isRedundancy = false) { const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR const filePath = join(baseDir, this.getVideoFilename(videoFile)) @@ -1916,7 +1925,7 @@ export class VideoModel extends Model { .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) } - removeTorrent (videoFile: VideoFileModel) { + removeTorrent (videoFile: MVideoFile) { const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) return remove(torrentPath) .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) @@ -1957,7 +1966,7 @@ export class VideoModel extends Model { return { baseUrlHttp, baseUrlWs } } - generateMagnetUri (videoFile: VideoFileModel, baseUrlHttp: string, baseUrlWs: string) { + generateMagnetUri (videoFile: MVideoFileRedundanciesOpt, baseUrlHttp: string, baseUrlWs: string) { const xs = this.getTorrentUrl(videoFile, baseUrlHttp) const announce = this.getTrackerUrls(baseUrlHttp, baseUrlWs) let urlList = [ this.getVideoFileUrl(videoFile, baseUrlHttp) ] @@ -1980,27 +1989,27 @@ export class VideoModel extends Model { return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] } - getTorrentUrl (videoFile: VideoFileModel, baseUrlHttp: string) { + getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) { return baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) } - getTorrentDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { + getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + this.getTorrentFileName(videoFile) } - getVideoFileUrl (videoFile: VideoFileModel, baseUrlHttp: string) { + getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) { return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) } - getVideoRedundancyUrl (videoFile: VideoFileModel, baseUrlHttp: string) { + getVideoRedundancyUrl (videoFile: MVideoFile, baseUrlHttp: string) { return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile) } - getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) { + getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) { return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile) } - getBandwidthBits (videoFile: VideoFileModel) { + getBandwidthBits (videoFile: MVideoFile) { return Math.ceil((videoFile.size * 8) / this.duration) } } -- cgit v1.2.3 From 96ca24f00e5ae5471dee9ee596489fe50af2b46f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 10:22:05 +0200 Subject: Fix tests --- server/models/video/tag.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 0fc3cfd4c..b110f2a43 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts @@ -6,6 +6,7 @@ import { throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoTagModel } from './video-tag' import { VideoPrivacy, VideoState } from '../../../shared/models/videos' +import { MTag } from '@server/typings/models' @Table({ tableName: 'tag', @@ -37,10 +38,10 @@ export class TagModel extends Model { }) Videos: VideoModel[] - static findOrCreateTags (tags: string[], transaction: Transaction) { - if (tags === null) return [] + static findOrCreateTags (tags: string[], transaction: Transaction): Promise { + if (tags === null) return Promise.resolve([]) - const tasks: Bluebird[] = [] + const tasks: Bluebird[] = [] tags.forEach(tag => { const query = { where: { @@ -52,7 +53,7 @@ export class TagModel extends Model { transaction } - const promise = TagModel.findOrCreate(query) + const promise = TagModel.findOrCreate(query) .then(([ tagInstance ]) => tagInstance) tasks.push(promise) }) -- cgit v1.2.3 From 0283eaac2a8e73006c66df3cf5bb9012e37450e5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 13:52:49 +0200 Subject: Cleanup model types --- server/models/video/video-channel.ts | 11 +++++------ server/models/video/video.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'server/models/video') 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 -- cgit v1.2.3 From 1ca9f7c3f7afac2af4c4c25b98426731f7e789c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 19:05:31 +0200 Subject: Type toFormattedJSON --- server/models/video/schedule-video-update.ts | 3 ++- server/models/video/video-abuse.ts | 4 ++-- server/models/video/video-blacklist.ts | 4 ++-- server/models/video/video-caption.ts | 10 ++++----- server/models/video/video-change-ownership.ts | 4 ++-- server/models/video/video-channel.ts | 30 +++++++++++++-------------- server/models/video/video-comment.ts | 3 ++- server/models/video/video-format-utils.ts | 6 +++--- server/models/video/video-import.ts | 4 ++-- server/models/video/video-playlist-element.ts | 19 +++++++++++------ server/models/video/video-playlist.ts | 3 ++- server/models/video/video.ts | 11 +++++----- 12 files changed, 56 insertions(+), 45 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index 603d55692..fc2a424aa 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts @@ -2,6 +2,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Ta import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoPrivacy } from '../../../shared/models/videos' import { Op, Transaction } from 'sequelize' +import { MScheduleVideoUpdateFormattable } from '@server/typings/models' @Table({ tableName: 'scheduleVideoUpdate', @@ -96,7 +97,7 @@ export class ScheduleVideoUpdateModel extends Model { return ScheduleVideoUpdateModel.destroy(query) } - toFormattedJSON () { + toFormattedJSON (this: MScheduleVideoUpdateFormattable) { return { updateAt: this.updateAt, privacy: this.privacy || undefined diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index af7b40d11..6ef1a915d 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -11,7 +11,7 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoAbuseState } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' -import { MVideoAbuse, MVideoAbuseAccountVideo, MVideoAbuseVideo } from '../../typings/models' +import { MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' import * as Bluebird from 'bluebird' @Table({ @@ -108,7 +108,7 @@ export class VideoAbuseModel extends Model { }) } - toFormattedJSON (this: MVideoAbuseAccountVideo): VideoAbuse { + toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse { return { id: this.id, reason: this.reason, diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 5a0cac94a..b4df6cd6a 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -8,7 +8,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { FindOptions } from 'sequelize' import { ThumbnailModel } from './thumbnail' import * as Bluebird from 'bluebird' -import { MVideoBlacklist } from '@server/typings/models' +import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/typings/models' @Table({ tableName: 'videoBlacklist', @@ -111,7 +111,7 @@ export class VideoBlacklistModel extends Model { return VideoBlacklistModel.findOne(query) } - toFormattedJSON (): VideoBlacklist { + toFormattedJSON (this: MVideoBlacklistFormattable): VideoBlacklist { return { id: this.id, createdAt: this.createdAt, diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index 9ce350d12..ad5801768 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts @@ -22,7 +22,7 @@ import { logger } from '../../helpers/logger' import { remove } from 'fs-extra' import { CONFIG } from '../../initializers/config' import * as Bluebird from 'bluebird' -import { MVideoCaptionVideo } from '@server/typings/models' +import { MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models' export enum ScopeNames { WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' @@ -154,7 +154,7 @@ export class VideoCaptionModel extends Model { return this.Video.remote === false } - toFormattedJSON (): VideoCaption { + toFormattedJSON (this: MVideoCaptionFormattable): VideoCaption { return { language: { id: this.language, @@ -164,15 +164,15 @@ export class VideoCaptionModel extends Model { } } - getCaptionStaticPath () { + getCaptionStaticPath (this: MVideoCaptionFormattable) { return join(LAZY_STATIC_PATHS.VIDEO_CAPTIONS, this.getCaptionName()) } - getCaptionName () { + getCaptionName (this: MVideoCaptionFormattable) { return `${this.Video.uuid}-${this.language}.vtt` } - removeCaptionFile () { + removeCaptionFile (this: MVideoCaptionFormattable) { return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) } } diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index 2d0ff48fb..f7a351329 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts @@ -3,7 +3,7 @@ import { AccountModel } from '../account/account' import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' import { getSort } from '../utils' -import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' +import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' import * as Bluebird from 'bluebird' enum ScopeNames { @@ -119,7 +119,7 @@ export class VideoChangeOwnershipModel extends Model .findByPk(id) } - toFormattedJSON (): VideoChangeOwnership { + toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership { return { id: this.id, status: this.status, diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index b6a60827f..7a4df516a 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -37,7 +37,7 @@ import * as Bluebird from 'bluebird' import { MChannelAccountDefault, MChannelActor, - MChannelActorAccountDefaultVideos + MChannelActorAccountDefaultVideos, MChannelSummaryFormattable, MChannelFormattable } from '../../typings/models/video' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation @@ -482,7 +482,20 @@ export class VideoChannelModel extends Model { .findByPk(id, options) } - toFormattedJSON (): VideoChannel { + toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary { + const actor = this.Actor.toFormattedSummaryJSON() + + return { + id: this.id, + name: actor.name, + displayName: this.getDisplayName(), + url: actor.url, + host: actor.host, + avatar: actor.avatar + } + } + + toFormattedJSON (this: MChannelFormattable): VideoChannel { const actor = this.Actor.toFormattedJSON() const videoChannel = { id: this.id, @@ -500,19 +513,6 @@ export class VideoChannelModel extends Model { return Object.assign(actor, videoChannel) } - toFormattedSummaryJSON (): VideoChannelSummary { - const actor = this.Actor.toFormattedJSON() - - return { - id: this.id, - name: actor.name, - displayName: this.getDisplayName(), - url: actor.url, - host: actor.host, - avatar: actor.avatar - } - } - toActivityPubObject (): ActivityPubActor { const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel') diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index c88dac1c1..84d71c553 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, + MCommentFormattable, MCommentId, MCommentOwner, MCommentOwnerReplyVideoLight, @@ -475,7 +476,7 @@ export class VideoCommentModel extends Model { return uniq(result) } - toFormattedJSON () { + toFormattedJSON (this: MCommentFormattable) { return { id: this.id, url: this.url, diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 4e7eb5f0c..6aa7c1e3e 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, MVideoDetails } from '../../typings/models' +import { MVideo, MVideoAP, MVideoFormattable, MVideoFormattableDetails } from '../../typings/models' import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' @@ -29,7 +29,7 @@ export type VideoFormattingJSONOptions = { blacklistInfo?: boolean } } -function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormattingJSONOptions): Video { +function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined const videoObject: Video = { @@ -103,7 +103,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting return videoObject } -function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails { +function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails { const formattedJson = video.toFormattedJSON({ additionalAttributes: { scheduledUpdate: true, diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index f596eea9d..af5314ce9 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts @@ -21,7 +21,7 @@ import { VideoImport, VideoImportState } from '../../../shared' import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' import { UserModel } from '../account/user' import * as Bluebird from 'bluebird' -import { MVideoImportDefault } from '@server/typings/models/video/video-import' +import { MVideoImportDefault, MVideoImportFormattable } from '@server/typings/models/video/video-import' @DefaultScope(() => ({ include: [ @@ -154,7 +154,7 @@ export class VideoImportModel extends Model { return this.targetUrl || this.magnetUri || this.torrentName } - toFormattedJSON (): VideoImport { + toFormattedJSON (this: MVideoImportFormattable): VideoImport { const videoFormatOptions = { completeDescription: true, additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true } diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 901113161..80ca22a18 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -21,12 +21,16 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' import * as validator from 'validator' import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' -import { UserModel } from '../account/user' import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' import { AccountModel } from '../account/account' import { VideoPrivacy } from '../../../shared/models/videos' import * as Bluebird from 'bluebird' -import { MVideoPlaylistAP, MVideoPlaylistElement, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' +import { + MVideoPlaylistElement, + MVideoPlaylistElementAP, + MVideoPlaylistElementFormattable, + MVideoPlaylistVideoThumbnail +} from '@server/typings/models/video/video-playlist-element' import { MUserAccountId } from '@server/typings/models' @Table({ @@ -180,7 +184,7 @@ 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 } @@ -293,7 +297,7 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementModel.increment({ position: by }, query) } - getType (displayNSFW?: boolean, accountId?: number) { + getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { const video = this.Video if (!video) return VideoPlaylistElementType.DELETED @@ -309,14 +313,17 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementType.REGULAR } - getVideoElement (displayNSFW?: boolean, accountId?: number) { + getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { if (!this.Video) return null if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null return this.Video.toFormattedJSON() } - toFormattedJSON (options: { displayNSFW?: boolean, accountId?: number } = {}): VideoPlaylistElement { + toFormattedJSON ( + this: MVideoPlaylistElementFormattable, + options: { displayNSFW?: boolean, accountId?: number } = {} + ): VideoPlaylistElement { return { id: this.id, position: this.position, diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 9f1d03ac5..80dd65322 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -46,6 +46,7 @@ import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } fro import * as Bluebird from 'bluebird' import { MVideoPlaylistAccountThumbnail, + MVideoPlaylistFormattable, MVideoPlaylistFull, MVideoPlaylistFullSummary, MVideoPlaylistIdWithElements @@ -479,7 +480,7 @@ export class VideoPlaylistModel extends Model { return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL) } - toFormattedJSON (): VideoPlaylist { + toFormattedJSON (this: MVideoPlaylistFormattable): VideoPlaylist { return { id: this.id, uuid: this.uuid, diff --git a/server/models/video/video.ts b/server/models/video/video.ts index e62bde344..9c24d1ba8 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -132,8 +132,9 @@ import { MVideoFullLight, MVideoIdThumbnail, MVideoThumbnail, - MVideoWithAllFiles, - MVideoWithRights + MVideoWithAllFiles, MVideoWithFile, + MVideoWithRights, + MVideoFormattable } from '../../typings/models' import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' import { MThumbnail } from '../../typings/models/video/thumbnail' @@ -1765,14 +1766,14 @@ export class VideoModel extends Model { this.VideoChannel.Account.isBlocked() } - getOriginalFile () { + getOriginalFile (this: T) { if (Array.isArray(this.VideoFiles) === false) return undefined // The original file is the file that have the higher resolution return maxBy(this.VideoFiles, file => file.resolution) } - getFile (resolution: number) { + getFile (this: T, resolution: number) { if (Array.isArray(this.VideoFiles) === false) return undefined return this.VideoFiles.find(f => f.resolution === resolution) @@ -1878,7 +1879,7 @@ export class VideoModel extends Model { return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) } - toFormattedJSON (options?: VideoFormattingJSONOptions): Video { + toFormattedJSON (this: T, options?: VideoFormattingJSONOptions): Video { return videoModelToFormattedJSON(this, options) } -- cgit v1.2.3 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