X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=272bba0e1c6ee08aa187a457765d47521c966cdf;hb=d95d15598847c7f020aa056e7e6e0c02d2bbf732;hp=ccb9d64ca4ad24a583429d58f75e23a5b647596e;hpb=0251197e249cc03b65805ed6805da72bf4573529;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index ccb9d64ca..272bba0e1 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1,4 +1,5 @@ import * as Bluebird from 'bluebird' +import { remove } from 'fs-extra' import { maxBy, minBy, pick } from 'lodash' import { join } from 'path' import { FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' @@ -23,10 +24,18 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { UserRight, VideoPrivacy, VideoState } from '../../../shared' +import { buildNSFWFilter } from '@server/helpers/express-utils' +import { getPrivaciesForFederation, isPrivacyForFederation } from '@server/helpers/video' +import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' +import { getServerActor } from '@server/models/application/application' +import { ModelCache } from '@server/models/model-cache' +import { VideoFile } from '@shared/models/videos/video-file.model' +import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' import { Video, VideoDetails } from '../../../shared/models/videos' +import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { VideoFilter } from '../../../shared/models/videos/video-query.type' +import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' import { peertubeTruncate } from '../../helpers/core-utils' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isBooleanValid } from '../../helpers/custom-validators/misc' @@ -43,7 +52,7 @@ import { } from '../../helpers/custom-validators/videos' import { getVideoFileResolution } from '../../helpers/ffmpeg-utils' import { logger } from '../../helpers/logger' -import { getServerActor } from '../../helpers/utils' +import { CONFIG } from '../../initializers/config' import { ACTIVITY_PUB, API_VERSION, @@ -60,40 +69,6 @@ import { WEBSERVER } from '../../initializers/constants' import { sendDeleteVideo } from '../../lib/activitypub/send' -import { AccountModel } from '../account/account' -import { AccountVideoRateModel } from '../account/account-video-rate' -import { ActorModel } from '../activitypub/actor' -import { AvatarModel } from '../avatar/avatar' -import { ServerModel } from '../server/server' -import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' -import { TagModel } from './tag' -import { VideoAbuseModel } from './video-abuse' -import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' -import { VideoCommentModel } from './video-comment' -import { VideoFileModel } from './video-file' -import { VideoShareModel } from './video-share' -import { VideoTagModel } from './video-tag' -import { ScheduleVideoUpdateModel } from './schedule-video-update' -import { VideoCaptionModel } from './video-caption' -import { VideoBlacklistModel } from './video-blacklist' -import { remove } from 'fs-extra' -import { VideoViewModel } from './video-views' -import { VideoRedundancyModel } from '../redundancy/video-redundancy' -import { - videoFilesModelToFormattedJSON, - VideoFormattingJSONOptions, - videoModelToActivityPubObject, - videoModelToFormattedDetailsJSON, - videoModelToFormattedJSON -} from './video-format-utils' -import { UserVideoHistoryModel } from '../account/user-video-history' -import { VideoImportModel } from './video-import' -import { VideoStreamingPlaylistModel } from './video-streaming-playlist' -import { VideoPlaylistElementModel } from './video-playlist-element' -import { CONFIG } from '../../initializers/config' -import { ThumbnailModel } from './thumbnail' -import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' -import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' import { MChannel, MChannelAccountDefault, @@ -118,14 +93,40 @@ import { MVideoWithAllFiles, MVideoWithFile, MVideoWithRights -} from '../../typings/models' -import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file' -import { MThumbnail } from '../../typings/models/video/thumbnail' -import { VideoFile } from '@shared/models/videos/video-file.model' -import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' -import { ModelCache } from '@server/models/model-cache' +} from '../../types/models' +import { MThumbnail } from '../../types/models/video/thumbnail' +import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file' +import { VideoAbuseModel } from '../abuse/video-abuse' +import { AccountModel } from '../account/account' +import { AccountVideoRateModel } from '../account/account-video-rate' +import { UserVideoHistoryModel } from '../account/user-video-history' +import { ActorModel } from '../activitypub/actor' +import { AvatarModel } from '../avatar/avatar' +import { VideoRedundancyModel } from '../redundancy/video-redundancy' +import { ServerModel } from '../server/server' +import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' +import { ScheduleVideoUpdateModel } from './schedule-video-update' +import { TagModel } from './tag' +import { ThumbnailModel } from './thumbnail' +import { VideoBlacklistModel } from './video-blacklist' +import { VideoCaptionModel } from './video-caption' +import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' +import { VideoCommentModel } from './video-comment' +import { VideoFileModel } from './video-file' +import { + videoFilesModelToFormattedJSON, + VideoFormattingJSONOptions, + videoModelToActivityPubObject, + videoModelToFormattedDetailsJSON, + videoModelToFormattedJSON +} from './video-format-utils' +import { VideoImportModel } from './video-import' +import { VideoPlaylistElementModel } from './video-playlist-element' import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder' -import { buildNSFWFilter } from '@server/helpers/express-utils' +import { VideoShareModel } from './video-share' +import { VideoStreamingPlaylistModel } from './video-streaming-playlist' +import { VideoTagModel } from './video-tag' +import { VideoViewModel } from './video-view' export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', @@ -499,7 +500,7 @@ export class VideoModel extends Model { @AllowNull(false) @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy')) @Column - privacy: number + privacy: VideoPrivacy @AllowNull(false) @Is('VideoNSFW', value => throwIfNotValid(value, isBooleanValid, 'NSFW boolean')) @@ -859,15 +860,12 @@ export class VideoModel extends Model { distinct: true, offset: start, limit: count, - order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings + order: getVideoSort('-createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings where: { id: { [Op.in]: Sequelize.literal('(' + rawQuery + ')') }, - [Op.or]: [ - { privacy: VideoPrivacy.PUBLIC }, - { privacy: VideoPrivacy.UNLISTED } - ] + [Op.or]: getPrivaciesForFederation() }, include: [ { @@ -1368,7 +1366,7 @@ export class VideoModel extends Model { // Instances only share videos const query = 'SELECT 1 FROM "videoShare" ' + 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + - 'WHERE "actorFollow"."actorId" = $followerActorId AND "videoShare"."videoId" = $videoId ' + + 'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "videoShare"."videoId" = $videoId ' + 'LIMIT 1' const options = { @@ -1444,7 +1442,7 @@ export class VideoModel extends Model { private static async getAvailableForApi ( options: BuildVideosQueryOptions, countVideos = true - ) { + ): Promise> { function getCount () { if (countVideos !== true) return Promise.resolve(undefined) @@ -1582,12 +1580,6 @@ export class VideoModel extends Model { return videos } - private static isPrivacyForFederation (privacy: VideoPrivacy) { - const castedPrivacy = parseInt(privacy + '', 10) - - return castedPrivacy === VideoPrivacy.PUBLIC || castedPrivacy === VideoPrivacy.UNLISTED - } - static getCategoryLabel (id: number) { return VIDEO_CATEGORIES[id] || 'Misc' } @@ -1613,8 +1605,7 @@ export class VideoModel extends Model { } isBlocked () { - return (this.VideoChannel.Account.Actor.Server && this.VideoChannel.Account.Actor.Server.isBlocked()) || - this.VideoChannel.Account.isBlocked() + return this.VideoChannel.Account.Actor.Server?.isBlocked() || this.VideoChannel.Account.isBlocked() } getQualityFileBy (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { @@ -1813,11 +1804,11 @@ export class VideoModel extends Model { } hasPrivacyForFederation () { - return VideoModel.isPrivacyForFederation(this.privacy) + return isPrivacyForFederation(this.privacy) } isNewVideo (newPrivacy: VideoPrivacy) { - return this.hasPrivacyForFederation() === false && VideoModel.isPrivacyForFederation(newPrivacy) === true + return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true } setAsRefreshed () {