aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/activitypub/client.ts12
-rw-r--r--server/middlewares/cache.ts7
-rw-r--r--server/models/redundancy/video-redundancy.ts7
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts5
4 files changed, 28 insertions, 3 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index ffbf1ba19..a342a48d4 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -39,6 +39,7 @@ import {
39import { VideoCaptionModel } from '../../models/video/video-caption' 39import { VideoCaptionModel } from '../../models/video/video-caption'
40import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy' 40import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy'
41import { getServerActor } from '../../helpers/utils' 41import { getServerActor } from '../../helpers/utils'
42import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
42 43
43const activityPubClientRouter = express.Router() 44const activityPubClientRouter = express.Router()
44 45
@@ -164,6 +165,8 @@ function getAccountVideoRate (rateType: VideoRateType) {
164async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 165async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
165 const video: VideoModel = res.locals.video 166 const video: VideoModel = res.locals.video
166 167
168 if (video.isOwned() === false) return res.redirect(video.url)
169
167 // We need captions to render AP object 170 // We need captions to render AP object
168 video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id) 171 video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id)
169 172
@@ -180,6 +183,9 @@ async function videoController (req: express.Request, res: express.Response, nex
180 183
181async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 184async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
182 const share = res.locals.videoShare as VideoShareModel 185 const share = res.locals.videoShare as VideoShareModel
186
187 if (share.Actor.isOwned() === false) return res.redirect(share.url)
188
183 const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined) 189 const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined)
184 190
185 return activityPubResponse(activityPubContextify(activity), res) 191 return activityPubResponse(activityPubContextify(activity), res)
@@ -252,6 +258,8 @@ async function videoChannelFollowingController (req: express.Request, res: expre
252async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { 258async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) {
253 const videoComment: VideoCommentModel = res.locals.videoComment 259 const videoComment: VideoCommentModel = res.locals.videoComment
254 260
261 if (videoComment.isOwned() === false) return res.redirect(videoComment.url)
262
255 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) 263 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
256 const isPublic = true // Comments are always public 264 const isPublic = true // Comments are always public
257 const audience = getAudience(videoComment.Account.Actor, isPublic) 265 const audience = getAudience(videoComment.Account.Actor, isPublic)
@@ -267,7 +275,9 @@ async function videoCommentController (req: express.Request, res: express.Respon
267} 275}
268 276
269async function videoRedundancyController (req: express.Request, res: express.Response) { 277async function videoRedundancyController (req: express.Request, res: express.Response) {
270 const videoRedundancy = res.locals.videoRedundancy 278 const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy
279 if (videoRedundancy.isOwned() === false) return res.redirect(videoRedundancy.url)
280
271 const serverActor = await getServerActor() 281 const serverActor = await getServerActor()
272 282
273 const audience = getAudience(serverActor) 283 const audience = getAudience(serverActor)
diff --git a/server/middlewares/cache.ts b/server/middlewares/cache.ts
index 1e00fc731..8ffe75700 100644
--- a/server/middlewares/cache.ts
+++ b/server/middlewares/cache.ts
@@ -19,6 +19,7 @@ function cacheRoute (lifetimeArg: string | number) {
19 logger.debug('No cached results for route %s.', req.originalUrl) 19 logger.debug('No cached results for route %s.', req.originalUrl)
20 20
21 const sendSave = res.send.bind(res) 21 const sendSave = res.send.bind(res)
22 const redirectSave = res.redirect.bind(res)
22 23
23 res.send = (body) => { 24 res.send = (body) => {
24 if (res.statusCode >= 200 && res.statusCode < 400) { 25 if (res.statusCode >= 200 && res.statusCode < 400) {
@@ -38,6 +39,12 @@ function cacheRoute (lifetimeArg: string | number) {
38 return sendSave(body) 39 return sendSave(body)
39 } 40 }
40 41
42 res.redirect = url => {
43 done()
44
45 return redirectSave(url)
46 }
47
41 return next() 48 return next()
42 } 49 }
43 50
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index 35e0cd3b1..9de4356b4 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -117,8 +117,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
117 117
118 @BeforeDestroy 118 @BeforeDestroy
119 static async removeFile (instance: VideoRedundancyModel) { 119 static async removeFile (instance: VideoRedundancyModel) {
120 // Not us 120 if (!instance.isOwned()) return
121 if (!instance.strategy) return
122 121
123 const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId) 122 const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId)
124 123
@@ -404,6 +403,10 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
404 })) 403 }))
405 } 404 }
406 405
406 isOwned () {
407 return !!this.strategy
408 }
409
407 toActivityPubObject (): CacheFileObject { 410 toActivityPubObject (): CacheFileObject {
408 return { 411 return {
409 id: this.url, 412 id: this.url,
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 9fba99ac8..6af7ed43b 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -15,6 +15,7 @@ import {
15 userLogin 15 userLogin
16} from '../../utils' 16} from '../../utils'
17import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 17import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18import { waitJobs } from '../../utils/server/jobs'
18 19
19describe('Test user subscriptions API validators', function () { 20describe('Test user subscriptions API validators', function () {
20 const path = '/api/v1/users/me/subscriptions' 21 const path = '/api/v1/users/me/subscriptions'
@@ -141,6 +142,8 @@ describe('Test user subscriptions API validators', function () {
141 }) 142 })
142 143
143 it('Should succeed with the correct parameters', async function () { 144 it('Should succeed with the correct parameters', async function () {
145 this.timeout(20000)
146
144 await makePostBodyRequest({ 147 await makePostBodyRequest({
145 url: server.url, 148 url: server.url,
146 path, 149 path,
@@ -148,6 +151,8 @@ describe('Test user subscriptions API validators', function () {
148 fields: { uri: 'user1_channel@localhost:9001' }, 151 fields: { uri: 'user1_channel@localhost:9001' },
149 statusCodeExpected: 204 152 statusCodeExpected: 204
150 }) 153 })
154
155 await waitJobs([ server ])
151 }) 156 })
152 }) 157 })
153 158