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

Implement auto tag on comments and videos

* Comments and videos can be automatically tagged using core rules or
   watched word lists
 * These tags can be used to automatically filter videos and comments
 * Introduce a new video comment policy where comments must be approved
   first
 * Comments may have to be approved if the user auto block them using
   core rules or watched word lists
 * Implement FEP-5624 to federate reply control policies
This commit is contained in:
Chocobozzz 2024-03-29 14:25:03 +01:00 committed by Chocobozzz
parent b3e39df59e
commit 29329d6c45
241 changed files with 8090 additions and 1399 deletions

View file

@ -1,8 +1,10 @@
import { forceNumber } from '@peertube/peertube-core-utils'
import { HttpStatusCode, ThumbnailType, VideoPrivacy, VideoPrivacyType, VideoUpdate } from '@peertube/peertube-models'
import { HttpStatusCode, ThumbnailType, VideoCommentPolicy, VideoPrivacy, VideoPrivacyType, VideoUpdate } from '@peertube/peertube-models'
import { exists } from '@server/helpers/custom-validators/misc.js'
import { changeVideoChannelShare } from '@server/lib/activitypub/share.js'
import { isNewVideoPrivacyForFederation, isPrivacyForFederation } from '@server/lib/activitypub/videos/federate.js'
import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
import { setAndSaveVideoAutomaticTags } from '@server/lib/automatic-tags/automatic-tags.js'
import { updateLocalVideoMiniatureFromExisting } from '@server/lib/thumbnail.js'
import { replaceChaptersFromDescriptionIfNeeded } from '@server/lib/video-chapters.js'
import { addVideoJobsAfterUpdate } from '@server/lib/video-jobs.js'
@ -65,6 +67,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
// Refresh video since thumbnails to prevent concurrent updates
const video = await VideoModel.loadFull(videoFromReq.id, t)
const oldName = video.name
const oldDescription = video.description
const oldVideoChannel = video.VideoChannel
@ -77,7 +80,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
'waitTranscoding',
'support',
'description',
'commentsEnabled',
'downloadEnabled'
]
@ -85,6 +87,15 @@ async function updateVideo (req: express.Request, res: express.Response) {
if (videoInfoToUpdate[key] !== undefined) video.set(key, videoInfoToUpdate[key])
}
// Special treatment for comments policy to support deprecated commentsEnabled attribute
if (videoInfoToUpdate.commentsPolicy !== undefined) {
video.commentsPolicy = videoInfoToUpdate.commentsPolicy
} else if (videoInfoToUpdate.commentsEnabled === true) {
video.commentsPolicy = VideoCommentPolicy.ENABLED
} else if (videoInfoToUpdate.commentsEnabled === false) {
video.commentsPolicy = VideoCommentPolicy.DISABLED
}
if (videoInfoToUpdate.originallyPublishedAt !== undefined) {
video.originallyPublishedAt = videoInfoToUpdate.originallyPublishedAt
? new Date(videoInfoToUpdate.originallyPublishedAt)
@ -142,6 +153,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
})
}
if (oldName !== video.name || oldDescription !== video.description) {
const automaticTags = await new AutomaticTagger().buildVideoAutomaticTags({ video, transaction: t })
await setAndSaveVideoAutomaticTags({ video, automaticTags, transaction: t })
}
await autoBlacklistVideoIfNeeded({
video: videoInstanceUpdated,
user: res.locals.oauth.token.User,