From 22a73cb879a5cc775d4bec3d72fa9c9cf52e5175 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Dec 2019 15:47:47 +0100 Subject: Add internal privacy mode --- server/models/video/video.ts | 55 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index af6fae0b6..7e18af497 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -348,9 +348,8 @@ export type AvailableForListIDsOptions = { // Only list public/published videos if (!options.filter || options.filter !== 'all-local') { - const privacyWhere = { - // Always list public videos - privacy: VideoPrivacy.PUBLIC, + + const publishWhere = { // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding [ Op.or ]: [ { @@ -364,8 +363,26 @@ export type AvailableForListIDsOptions = { } ] } + whereAnd.push(publishWhere) - whereAnd.push(privacyWhere) + // List internal videos if the user is logged in + if (options.user) { + const privacyWhere = { + [Op.or]: [ + { + privacy: VideoPrivacy.INTERNAL + }, + { + privacy: VideoPrivacy.PUBLIC + } + ] + } + + whereAnd.push(privacyWhere) + } else { // Or only public videos + const privacyWhere = { privacy: VideoPrivacy.PUBLIC } + whereAnd.push(privacyWhere) + } } if (options.videoPlaylistId) { @@ -1773,6 +1790,10 @@ export class VideoModel extends Model { } } + private static isPrivacyForFederation (privacy: VideoPrivacy) { + return privacy === VideoPrivacy.PUBLIC || privacy === VideoPrivacy.UNLISTED + } + static getCategoryLabel (id: number) { return VIDEO_CATEGORIES[ id ] || 'Misc' } @@ -1980,12 +2001,38 @@ export class VideoModel extends Model { return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL) } + hasPrivacyForFederation () { + return VideoModel.isPrivacyForFederation(this.privacy) + } + + isNewVideo (newPrivacy: VideoPrivacy) { + return this.hasPrivacyForFederation() === false && VideoModel.isPrivacyForFederation(newPrivacy) === true + } + setAsRefreshed () { this.changed('updatedAt', true) return this.save() } + requiresAuth () { + return this.privacy === VideoPrivacy.PRIVATE || this.privacy === VideoPrivacy.INTERNAL || !!this.VideoBlacklist + } + + setPrivacy (newPrivacy: VideoPrivacy) { + if (this.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) { + this.publishedAt = new Date() + } + + this.privacy = newPrivacy + } + + isConfidential () { + return this.privacy === VideoPrivacy.PRIVATE || + this.privacy === VideoPrivacy.UNLISTED || + this.privacy === VideoPrivacy.INTERNAL + } + async publishIfNeededAndSave (t: Transaction) { if (this.state !== VideoState.PUBLISHED) { this.state = VideoState.PUBLISHED -- cgit v1.2.3