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