1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Improve NSFW system

* Add NSFW flags to videos so the publisher can add more NSFW context
 * Add NSFW summary to videos, similar to content warning system so the
   publisher has a free text to describe NSFW aspect of its video
 * Add additional "warn" NSFW policy: the video thumbnail is not blurred
   and we display a tag below the video miniature, the video player
   includes the NSFW warning (with context if available) and it also
   prevent autoplay
 * "blur" NSFW settings inherits "warn" policy and also blur the video
   thumbnail
 * Add NSFW flag settings to users so they can have more granular
   control about what content they want to hide, warn or display
This commit is contained in:
Chocobozzz 2025-04-24 14:51:07 +02:00
parent fac6b15ada
commit dd4027a10f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
181 changed files with 5081 additions and 2061 deletions

View file

@ -18,7 +18,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
}
async create () {
logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags())
logger.debug('Adding remote video %s.', this.videoObject.id, { ...this.videoObject, ...this.lTags() })
const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
const channel = channelActor.VideoChannel

View file

@ -5,9 +5,12 @@ import {
ActivityMagnetUrlObject,
ActivityPlaylistSegmentHashesObject,
ActivityPlaylistUrlObject,
ActivitySensitiveTagObject,
ActivityTagObject,
ActivityUrlObject,
ActivityVideoUrlObject,
NSFWFlag,
stringToNSFWFlag,
VideoFileFormatFlag,
VideoFileStream,
VideoObject,
@ -28,7 +31,7 @@ import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoFileModel } from '@server/models/video/video-file.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { FilteredModelAttributes } from '@server/types/index.js'
import { MChannelId, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId, isStreamingPlaylist } from '@server/types/models/index.js'
import { isStreamingPlaylist, MChannelId, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models/index.js'
import { decode as magnetUriDecode } from 'magnet-uri'
import { basename, extname } from 'path'
import { getDurationFromActivityStream } from '../../activity.js'
@ -271,7 +274,14 @@ export function getVideoAttributesFromObject (videoChannel: MChannelId, videoObj
language,
description,
support,
nsfw: videoObject.sensitive,
nsfwSummary: videoObject.sensitive
? videoObject.summary
: null,
nsfwFlags: videoObject.sensitive
? getNSFWFlags(videoObject.tag)
: NSFWFlag.NONE,
commentsPolicy: videoObject.commentsPolicy,
@ -320,8 +330,12 @@ function isAPMagnetUrlObject (url: any): url is ActivityMagnetUrlObject {
return url && url.mediaType === 'application/x-bittorrent;x-scheme-handler/magnet'
}
function isAPHashTagObject (url: any): url is ActivityHashTagObject {
return url && url.type === 'Hashtag'
function isAPHashTagObject (tag: any): tag is ActivityHashTagObject {
return tag && tag.type === 'Hashtag'
}
function isAPSensitiveTagObject (tag: any): tag is ActivitySensitiveTagObject {
return tag && tag.type === 'SensitiveTag'
}
function getTorrentRelatedInfo (options: {
@ -361,3 +375,10 @@ function getTorrentRelatedInfo (options: {
infoHash: magnetParsed.infoHash
}
}
function getNSFWFlags (tags: ActivityTagObject[]) {
return tags.filter(t => isAPSensitiveTagObject(t))
.map(t => stringToNSFWFlag(t.name))
.filter(t => !!t)
.reduce((acc, t) => acc | t, 0)
}

View file

@ -122,6 +122,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
private updateVideo (channel: MChannelId, transaction?: Transaction, overrideTo?: string[]) {
const to = overrideTo || this.videoObject.to
const videoData = getVideoAttributesFromObject(channel, this.videoObject, to)
this.video.name = videoData.name
this.video.uuid = videoData.uuid
this.video.url = videoData.url
@ -131,6 +132,8 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
this.video.description = videoData.description
this.video.support = videoData.support
this.video.nsfw = videoData.nsfw
this.video.nsfwSummary = videoData.nsfwSummary
this.video.nsfwFlags = videoData.nsfwFlags
this.video.commentsPolicy = videoData.commentsPolicy
this.video.downloadEnabled = videoData.downloadEnabled
this.video.waitTranscoding = videoData.waitTranscoding