From 156c50af3085468a47b8ae73fe8cfcae46b42398 Mon Sep 17 00:00:00 2001 From: Lucas Declercq Date: Sat, 6 Oct 2018 19:17:21 +0200 Subject: Add downloadingEnabled property to video model --- server/controllers/api/videos/import.ts | 1 + server/controllers/api/videos/index.ts | 2 ++ 2 files changed, 3 insertions(+) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 398fd5a7f..a5cddba89 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -171,6 +171,7 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You licence: body.licence || importData.licence, language: body.language || undefined, commentsEnabled: body.commentsEnabled || true, + downloadingEnabled: body.downloadingEnabled || true, waitTranscoding: body.waitTranscoding || false, state: VideoState.TO_IMPORT, nsfw: body.nsfw || importData.nsfw || false, diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 6a73e13d0..ec25006e8 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -179,6 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) { licence: videoInfo.licence, language: videoInfo.language, commentsEnabled: videoInfo.commentsEnabled || false, + downloadingEnabled: videoInfo.downloadingEnabled || false, waitTranscoding: videoInfo.waitTranscoding || false, state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, nsfw: videoInfo.nsfw || false, @@ -322,6 +323,7 @@ async function updateVideo (req: express.Request, res: express.Response) { if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) + if (videoInfoToUpdate.downloadingEnabled !== undefined) videoInstance.set('downloadingEnabled', videoInfoToUpdate.downloadingEnabled) if (videoInfoToUpdate.privacy !== undefined) { const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) videoInstance.set('privacy', newPrivacy) -- cgit v1.2.3 From 4ffdcfc63b8c804a0aea20609544c859ab57318b Mon Sep 17 00:00:00 2001 From: Lucas Declercq Date: Mon, 8 Oct 2018 14:42:55 +0200 Subject: Fix some defaults values + indentation --- server/controllers/api/videos/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index ec25006e8..4b6d1b847 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -179,7 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) { licence: videoInfo.licence, language: videoInfo.language, commentsEnabled: videoInfo.commentsEnabled || false, - downloadingEnabled: videoInfo.downloadingEnabled || false, + downloadingEnabled: videoInfo.downloadingEnabled || true, waitTranscoding: videoInfo.waitTranscoding || false, state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, nsfw: videoInfo.nsfw || false, -- cgit v1.2.3 From 7f2cfe3a792856f7de6f1d13688aa3d06ec1bf70 Mon Sep 17 00:00:00 2001 From: Lucas Declercq Date: Mon, 8 Oct 2018 14:45:22 +0200 Subject: Rename downloadingEnabled property to downloadEnabled --- server/controllers/api/videos/import.ts | 2 +- server/controllers/api/videos/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index a5cddba89..9e51e2000 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -171,7 +171,7 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You licence: body.licence || importData.licence, language: body.language || undefined, commentsEnabled: body.commentsEnabled || true, - downloadingEnabled: body.downloadingEnabled || true, + downloadEnabled: body.downloadEnabled || true, waitTranscoding: body.waitTranscoding || false, state: VideoState.TO_IMPORT, nsfw: body.nsfw || importData.nsfw || false, diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 4b6d1b847..7d55f06b6 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -179,7 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) { licence: videoInfo.licence, language: videoInfo.language, commentsEnabled: videoInfo.commentsEnabled || false, - downloadingEnabled: videoInfo.downloadingEnabled || true, + downloadEnabled: videoInfo.downloadEnabled || true, waitTranscoding: videoInfo.waitTranscoding || false, state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, nsfw: videoInfo.nsfw || false, @@ -323,7 +323,7 @@ async function updateVideo (req: express.Request, res: express.Response) { if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) - if (videoInfoToUpdate.downloadingEnabled !== undefined) videoInstance.set('downloadingEnabled', videoInfoToUpdate.downloadingEnabled) + if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) if (videoInfoToUpdate.privacy !== undefined) { const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) videoInstance.set('privacy', newPrivacy) -- cgit v1.2.3 From 5abb9fbbd12e7097e348d6a38622d364b1fa47ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jan 2019 15:39:51 +0100 Subject: Add ability to unfederate a local video (on blacklist) --- server/controllers/api/videos/blacklist.ts | 17 +++++++++++++++-- server/controllers/api/videos/index.ts | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 9ef08812b..43b0516e7 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -18,6 +18,8 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { sequelizeTypescript } from '../../../initializers' import { Notifier } from '../../../lib/notifier' import { VideoModel } from '../../../models/video/video' +import { sendCreateVideo, sendDeleteVideo, sendUpdateVideo } from '../../../lib/activitypub/send' +import { federateVideoIfNeeded } from '../../../lib/activitypub' const blacklistRouter = express.Router() @@ -66,12 +68,17 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) const toCreate = { videoId: videoInstance.id, + unfederated: body.unfederate === true, reason: body.reason } const blacklist = await VideoBlacklistModel.create(toCreate) blacklist.Video = videoInstance + if (body.unfederate === true) { + await sendDeleteVideo(videoInstance, undefined) + } + Notifier.Instance.notifyOnVideoBlacklist(blacklist) logger.info('Video %s blacklisted.', res.locals.video.uuid) @@ -101,8 +108,14 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel const video: VideoModel = res.locals.video - await sequelizeTypescript.transaction(t => { - return videoBlacklist.destroy({ transaction: t }) + await sequelizeTypescript.transaction(async t => { + const unfederated = videoBlacklist.unfederated + await videoBlacklist.destroy({ transaction: t }) + + // Re federate the video + if (unfederated === true) { + await federateVideoIfNeeded(video, true, t) + } }) Notifier.Instance.notifyOnVideoUnblacklist(video) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 33521a8c1..28ac26598 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -364,7 +364,11 @@ async function updateVideo (req: express.Request, res: express.Response) { } const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE - await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) + + // Don't send update if the video was unfederated + if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) { + await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) + } auditLogger.update( getAuditIdFromRes(res), -- cgit v1.2.3 From 744d0eca195bce7dafeb4a958d0eb3c0046be32d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Jan 2019 11:30:15 +0100 Subject: Refresh remote actors on GET enpoints --- server/controllers/api/videos/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 28ac26598..2b2dfa7ca 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -399,7 +399,7 @@ function getVideo (req: express.Request, res: express.Response) { const videoInstance = res.locals.video if (videoInstance.isOutdated()) { - JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } }) + JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoInstance.url } }) .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) } -- cgit v1.2.3 From 1e7eb25f6cb6893db8f99ff40ef0509aa2a16614 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Jan 2019 14:52:33 +0100 Subject: Correctly send Flag/Dislike/View activities --- server/controllers/api/videos/abuse.ts | 2 +- server/controllers/api/videos/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index fe0a95cd5..32f9c4793 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -3,7 +3,6 @@ import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' -import { sendVideoAbuse } from '../../../lib/activitypub/send' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -23,6 +22,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' import { UserModel } from '../../../models/account/user' import { Notifier } from '../../../lib/notifier' +import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' const auditLogger = auditLoggerFactory('abuse') const abuseVideoRouter = express.Router() diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 2b2dfa7ca..8414ca42c 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -23,7 +23,6 @@ import { fetchRemoteVideoDescription, getVideoActivityPubUrl } from '../../../lib/activitypub' -import { sendCreateView } from '../../../lib/activitypub/send' import { JobQueue } from '../../../lib/job-queue' import { Redis } from '../../../lib/redis' import { @@ -59,6 +58,7 @@ import { resetSequelizeInstance } from '../../../helpers/database-utils' import { move } from 'fs-extra' import { watchingRouter } from './watching' import { Notifier } from '../../../lib/notifier' +import { sendView } from '../../../lib/activitypub/send/send-view' const auditLogger = auditLoggerFactory('videos') const videosRouter = express.Router() @@ -422,7 +422,7 @@ async function viewVideo (req: express.Request, res: express.Response) { ]) const serverActor = await getServerActor() - await sendCreateView(serverActor, videoInstance, undefined) + await sendView(serverActor, videoInstance, undefined) return res.status(204).end() } -- cgit v1.2.3 From 092092969633bbcf6d4891a083ea497a7d5c3154 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 29 Jan 2019 08:37:25 +0100 Subject: Add hls support on server --- server/controllers/api/videos/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 2b2dfa7ca..e04fc8186 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -37,6 +37,7 @@ import { setDefaultPagination, setDefaultSort, videosAddValidator, + videosCustomGetValidator, videosGetValidator, videosRemoveValidator, videosSortValidator, @@ -123,9 +124,9 @@ videosRouter.get('/:id/description', ) videosRouter.get('/:id', optionalAuthenticate, - asyncMiddleware(videosGetValidator), + asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), asyncMiddleware(checkVideoFollowConstraints), - getVideo + asyncMiddleware(getVideo) ) videosRouter.post('/:id/views', asyncMiddleware(videosGetValidator), @@ -395,15 +396,17 @@ async function updateVideo (req: express.Request, res: express.Response) { return res.type('json').status(204).end() } -function getVideo (req: express.Request, res: express.Response) { - const videoInstance = res.locals.video +async function getVideo (req: express.Request, res: express.Response) { + // We need more attributes + const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null + const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) - if (videoInstance.isOutdated()) { - JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoInstance.url } }) - .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) + if (video.isOutdated()) { + JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) + .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err })) } - return res.json(videoInstance.toFormattedDetailsJSON()) + return res.json(video.toFormattedDetailsJSON()) } async function viewVideo (req: express.Request, res: express.Response) { -- cgit v1.2.3