From 0883b3245bf0deb9106c4041e9afbd3521b79280 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Apr 2018 11:01:34 +0200 Subject: Add ability to choose what policy we have for NSFW videos There is a global instance setting and a per user setting --- server/models/account/user.ts | 14 ++++++++------ server/models/video/video.ts | 24 +++++++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'server/models') diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 8afd246b2..56af2f30a 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -21,7 +21,7 @@ import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' import { User, UserRole } from '../../../shared/models/users' import { isUserAutoPlayVideoValid, - isUserDisplayNSFWValid, + isUserNSFWPolicyValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, @@ -32,6 +32,9 @@ import { OAuthTokenModel } from '../oauth/oauth-token' import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { AccountModel } from './account' +import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' +import { values } from 'lodash' +import { NSFW_POLICY_TYPES } from '../../initializers' @DefaultScope({ include: [ @@ -83,10 +86,9 @@ export class UserModel extends Model { email: string @AllowNull(false) - @Default(false) - @Is('UserDisplayNSFW', value => throwIfNotValid(value, isUserDisplayNSFWValid, 'display NSFW boolean')) - @Column - displayNSFW: boolean + @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) + @Column(DataType.ENUM(values(NSFW_POLICY_TYPES))) + nsfwPolicy: NSFWPolicyType @AllowNull(false) @Default(true) @@ -265,7 +267,7 @@ export class UserModel extends Model { id: this.id, username: this.username, email: this.email, - displayNSFW: this.displayNSFW, + nsfwPolicy: this.nsfwPolicy, autoPlayVideo: this.autoPlayVideo, role: this.role, roleLabel: USER_ROLE_LABELS[ this.role ], diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a7923b477..2e66f9aa7 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -95,7 +95,7 @@ enum ScopeNames { } @Scopes({ - [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, filter?: VideoFilter, withFiles?: boolean) => { + [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean) => { const query: IFindOptions = { where: { id: { @@ -161,6 +161,11 @@ enum ScopeNames { }) } + // Hide nsfw videos? + if (hideNSFW === true) { + query.where['nsfw'] = false + } + return query }, [ScopeNames.WITH_ACCOUNT_DETAILS]: { @@ -640,7 +645,7 @@ export class VideoModel extends Model { }) } - static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { + static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, hideNSFW: boolean, withFiles = false) { const query: IFindOptions = { offset: start, limit: count, @@ -669,6 +674,12 @@ export class VideoModel extends Model { }) } + if (hideNSFW === true) { + query.where = { + nsfw: false + } + } + return VideoModel.findAndCountAll(query).then(({ rows, count }) => { return { data: rows, @@ -677,7 +688,7 @@ export class VideoModel extends Model { }) } - static async listForApi (start: number, count: number, sort: string, filter?: VideoFilter, withFiles = false) { + static async listForApi (start: number, count: number, sort: string, hideNSFW: boolean, filter?: VideoFilter, withFiles = false) { const query = { offset: start, limit: count, @@ -685,8 +696,7 @@ export class VideoModel extends Model { } const serverActor = await getServerActor() - - return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, filter, withFiles ] }) + return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles ] }) .findAndCountAll(query) .then(({ rows, count }) => { return { @@ -696,7 +706,7 @@ export class VideoModel extends Model { }) } - static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string) { + static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string, hideNSFW: boolean) { const query: IFindOptions = { offset: start, limit: count, @@ -724,7 +734,7 @@ export class VideoModel extends Model { const serverActor = await getServerActor() - return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id ] }) + return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW ] }) .findAndCountAll(query) .then(({ rows, count }) => { return { -- cgit v1.2.3 From 2243730c8edf210c0a3ffc161bac89785f6a52f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Apr 2018 14:52:10 +0200 Subject: Add information concerning video privacy in my videos list --- server/models/video/video.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2e66f9aa7..c08d18b71 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -884,6 +884,13 @@ export class VideoModel extends Model { return languageLabel } + private static getPrivacyLabel (id: number) { + let privacyLabel = VIDEO_PRIVACIES[id] + if (!privacyLabel) privacyLabel = 'Unknown' + + return privacyLabel + } + getOriginalFile () { if (Array.isArray(this.VideoFiles) === false) return undefined @@ -990,6 +997,10 @@ export class VideoModel extends Model { id: this.language, label: VideoModel.getLanguageLabel(this.language) }, + privacy: { + id: this.privacy, + label: VideoModel.getPrivacyLabel(this.privacy) + }, nsfw: this.nsfw, description: this.getTruncatedDescription(), isLocal: this.isOwned(), @@ -1016,15 +1027,7 @@ export class VideoModel extends Model { toFormattedDetailsJSON (): VideoDetails { const formattedJson = this.toFormattedJSON() - // Maybe our server is not up to date and there are new privacy settings since our version - let privacyLabel = VIDEO_PRIVACIES[this.privacy] - if (!privacyLabel) privacyLabel = 'Unknown' - const detailsJson = { - privacy: { - id: this.privacy, - label: privacyLabel - }, support: this.support, descriptionPath: this.getDescriptionPath(), channel: this.VideoChannel.toFormattedJSON(), -- cgit v1.2.3 From 81e504b34e71e91633442c8021e05f9cd52a49c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Apr 2018 15:13:41 +0200 Subject: Better file name for torrent --- server/models/video/video.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index c08d18b71..70d3948ee 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -944,8 +944,10 @@ export class VideoModel extends Model { return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) } - createTorrentAndSetInfoHash = async function (videoFile: VideoFileModel) { + async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { const options = { + name: this.name + videoFile.extname, + createdBy: 'PeerTube', announceList: [ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ], [ CONFIG.WEBSERVER.URL + '/tracker/announce' ] @@ -1240,7 +1242,7 @@ export class VideoModel extends Model { return peertubeTruncate(this.description, maxLength) } - optimizeOriginalVideofile = async function () { + async optimizeOriginalVideofile () { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR const newExtname = '.mp4' const inputVideoFile = this.getOriginalFile() @@ -1277,7 +1279,7 @@ export class VideoModel extends Model { } } - transcodeOriginalVideofile = async function (resolution: VideoResolution, isPortraitMode: boolean) { + async transcodeOriginalVideofile (resolution: VideoResolution, isPortraitMode: boolean) { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR const extname = '.mp4' -- cgit v1.2.3 From 6cced8f9155175184341416cf5b8d1698f641eb7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Apr 2018 15:37:44 +0200 Subject: Add resolution in torrent file name --- server/models/video/video.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'server/models') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 70d3948ee..aef75d206 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -946,7 +946,8 @@ export class VideoModel extends Model { async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { const options = { - name: this.name + videoFile.extname, + // 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}`, createdBy: 'PeerTube', announceList: [ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ], -- cgit v1.2.3