aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-28 11:16:08 +0100
committerChocobozzz <me@florianbigard.com>2017-12-28 11:16:08 +0100
commitda854ddd502cd70685ef779c673b9e63757b8aa0 (patch)
tree21501d170cceaa044a5f23449cbd2eb47fd6415d /server
parentf40bbe3146553ef45515ee6b6d93ce6028f045ca (diff)
downloadPeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.gz
PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.zst
PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.zip
Propagate old comment on new follow
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/client.ts27
-rw-r--r--server/controllers/activitypub/inbox.ts2
-rw-r--r--server/controllers/api/config.ts2
-rw-r--r--server/controllers/api/index.ts8
-rw-r--r--server/controllers/api/jobs.ts2
-rw-r--r--server/controllers/api/oauth-clients.ts5
-rw-r--r--server/controllers/api/server/follows.ts11
-rw-r--r--server/controllers/api/users.ts24
-rw-r--r--server/controllers/api/videos/abuse.ts14
-rw-r--r--server/controllers/api/videos/blacklist.ts16
-rw-r--r--server/controllers/api/videos/channel.ts16
-rw-r--r--server/controllers/api/videos/comment.ts3
-rw-r--r--server/controllers/api/videos/index.ts41
-rw-r--r--server/controllers/api/videos/rate.ts3
-rw-r--r--server/controllers/client.ts12
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts3
-rw-r--r--server/helpers/custom-validators/activitypub/announce.ts1
-rw-r--r--server/helpers/custom-validators/activitypub/index.ts8
-rw-r--r--server/helpers/index.ts9
-rw-r--r--server/helpers/requests.ts8
-rw-r--r--server/helpers/webfinger.ts2
-rw-r--r--server/initializers/checker.ts2
-rw-r--r--server/initializers/installer.ts3
-rw-r--r--server/initializers/migrations/0135-video-channel-actor.ts2
-rw-r--r--server/initializers/migrator.ts3
-rw-r--r--server/lib/activitypub/actor.ts28
-rw-r--r--server/lib/activitypub/process/misc.ts79
-rw-r--r--server/lib/activitypub/process/process-announce.ts3
-rw-r--r--server/lib/activitypub/process/process-create.ts13
-rw-r--r--server/lib/activitypub/process/process-delete.ts3
-rw-r--r--server/lib/activitypub/process/process-follow.ts3
-rw-r--r--server/lib/activitypub/process/process-like.ts2
-rw-r--r--server/lib/activitypub/process/process-undo.ts3
-rw-r--r--server/lib/activitypub/process/process-update.ts4
-rw-r--r--server/lib/activitypub/process/process.ts2
-rw-r--r--server/lib/activitypub/send/misc.ts2
-rw-r--r--server/lib/activitypub/send/send-create.ts2
-rw-r--r--server/lib/activitypub/share.ts2
-rw-r--r--server/lib/activitypub/url.ts2
-rw-r--r--server/lib/activitypub/videos.ts12
-rw-r--r--server/lib/cache/videos-preview-cache.ts3
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts3
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-fetcher-handler.ts6
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts4
-rw-r--r--server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts3
-rw-r--r--server/lib/jobs/job-scheduler.ts2
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts3
-rw-r--r--server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts2
-rw-r--r--server/lib/oauth-model.ts2
-rw-r--r--server/middlewares/activitypub.ts3
-rw-r--r--server/middlewares/oauth.ts3
-rw-r--r--server/middlewares/servers.ts2
-rw-r--r--server/middlewares/sort.ts2
-rw-r--r--server/middlewares/user-right.ts2
-rw-r--r--server/middlewares/validators/account.ts2
-rw-r--r--server/middlewares/validators/activitypub/activity.ts4
-rw-r--r--server/middlewares/validators/activitypub/signature.ts7
-rw-r--r--server/middlewares/validators/follows.ts4
-rw-r--r--server/middlewares/validators/oembed.ts3
-rw-r--r--server/middlewares/validators/pagination.ts2
-rw-r--r--server/middlewares/validators/sort.ts4
-rw-r--r--server/middlewares/validators/users.ts9
-rw-r--r--server/middlewares/validators/utils.ts2
-rw-r--r--server/middlewares/validators/video-blacklist.ts2
-rw-r--r--server/middlewares/validators/video-channels.ts5
-rw-r--r--server/middlewares/validators/video-comments.ts22
-rw-r--r--server/middlewares/validators/videos.ts17
-rw-r--r--server/middlewares/validators/webfinger.ts3
-rw-r--r--server/models/account/user.ts2
-rw-r--r--server/models/activitypub/actor.ts9
-rw-r--r--server/models/oauth/oauth-token.ts2
-rw-r--r--server/models/server/server.ts2
-rw-r--r--server/models/video/video-blacklist.ts2
-rw-r--r--server/models/video/video-comment.ts33
-rw-r--r--server/models/video/video.ts121
75 files changed, 380 insertions, 304 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 8c6294ff7..71e706346 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -1,14 +1,17 @@
1// Intercept ActivityPub client requests 1// Intercept ActivityPub client requests
2import * as express from 'express' 2import * as express from 'express'
3import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' 3import { activityPubCollectionPagination } from '../../helpers/activitypub'
4import { pageToStartAndCount } from '../../helpers/core-utils'
4import { ACTIVITY_PUB, CONFIG } from '../../initializers' 5import { ACTIVITY_PUB, CONFIG } from '../../initializers'
5import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' 6import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send'
6import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' 7import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
7import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' 8import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators'
9import { videoCommentGetValidator } from '../../middlewares/validators/video-comments'
8import { AccountModel } from '../../models/account/account' 10import { AccountModel } from '../../models/account/account'
9import { ActorFollowModel } from '../../models/activitypub/actor-follow' 11import { ActorFollowModel } from '../../models/activitypub/actor-follow'
10import { VideoModel } from '../../models/video/video' 12import { VideoModel } from '../../models/video/video'
11import { VideoChannelModel } from '../../models/video/video-channel' 13import { VideoChannelModel } from '../../models/video/video-channel'
14import { VideoCommentModel } from '../../models/video/video-comment'
12import { VideoShareModel } from '../../models/video/video-share' 15import { VideoShareModel } from '../../models/video/video-share'
13 16
14const activityPubClientRouter = express.Router() 17const activityPubClientRouter = express.Router()
@@ -30,7 +33,7 @@ activityPubClientRouter.get('/account/:name/following',
30 33
31activityPubClientRouter.get('/videos/watch/:id', 34activityPubClientRouter.get('/videos/watch/:id',
32 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 35 executeIfActivityPub(asyncMiddleware(videosGetValidator)),
33 executeIfActivityPub(videoController) 36 executeIfActivityPub(asyncMiddleware(videoController))
34) 37)
35 38
36activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', 39activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
@@ -38,6 +41,11 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
38 executeIfActivityPub(asyncMiddleware(videoAnnounceController)) 41 executeIfActivityPub(asyncMiddleware(videoAnnounceController))
39) 42)
40 43
44activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
45 executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
46 executeIfActivityPub(asyncMiddleware(videoCommentController))
47)
48
41activityPubClientRouter.get('/video-channels/:id', 49activityPubClientRouter.get('/video-channels/:id',
42 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)), 50 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)),
43 executeIfActivityPub(asyncMiddleware(videoChannelController)) 51 executeIfActivityPub(asyncMiddleware(videoChannelController))
@@ -54,7 +62,8 @@ export {
54function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { 62function accountController (req: express.Request, res: express.Response, next: express.NextFunction) {
55 const account: AccountModel = res.locals.account 63 const account: AccountModel = res.locals.account
56 64
57 return res.json(account.toActivityPubObject()).end() 65 return res.json(account.toActivityPubObject())
66 .end()
58} 67}
59 68
60async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 69async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -81,10 +90,12 @@ async function accountFollowingController (req: express.Request, res: express.Re
81 return res.json(activityPubResult) 90 return res.json(activityPubResult)
82} 91}
83 92
84function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 93async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
85 const video: VideoModel = res.locals.video 94 const video: VideoModel = res.locals.video
86 95
87 return res.json(video.toActivityPubObject()) 96 // We need more attributes
97 const videoAll = await VideoModel.loadAndPopulateAll(video.id)
98 return res.json(videoAll.toActivityPubObject())
88} 99}
89 100
90async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 101async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -99,3 +110,9 @@ async function videoChannelController (req: express.Request, res: express.Respon
99 110
100 return res.json(videoChannel.toActivityPubObject()) 111 return res.json(videoChannel.toActivityPubObject())
101} 112}
113
114async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) {
115 const videoComment: VideoCommentModel = res.locals.videoComment
116
117 return res.json(videoComment.toActivityPubObject())
118}
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index 8332eabb1..bfcb7b369 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' 2import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared'
3import { logger } from '../../helpers'
4import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' 3import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
4import { logger } from '../../helpers/logger'
5import { processActivities } from '../../lib/activitypub/process/process' 5import { processActivities } from '../../lib/activitypub/process/process'
6import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' 6import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 5f704f0ee..2f1132904 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { isSignupAllowed } from '../../helpers/utils'
2 3
3import { isSignupAllowed } from '../../helpers'
4import { CONFIG } from '../../initializers' 4import { CONFIG } from '../../initializers'
5import { asyncMiddleware } from '../../middlewares' 5import { asyncMiddleware } from '../../middlewares'
6import { ServerConfig } from '../../../shared' 6import { ServerConfig } from '../../../shared'
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index 737ea4602..1fd44ac11 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -1,13 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2 2import { badRequest } from '../../helpers/utils'
3import { badRequest } from '../../helpers'
4
5import { oauthClientsRouter } from './oauth-clients'
6import { configRouter } from './config' 3import { configRouter } from './config'
4import { jobsRouter } from './jobs'
5import { oauthClientsRouter } from './oauth-clients'
7import { serverRouter } from './server' 6import { serverRouter } from './server'
8import { usersRouter } from './users' 7import { usersRouter } from './users'
9import { videosRouter } from './videos' 8import { videosRouter } from './videos'
10import { jobsRouter } from './jobs'
11 9
12const apiRouter = express.Router() 10const apiRouter = express.Router()
13 11
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts
index 4e7cd1ee3..d9d6030a4 100644
--- a/server/controllers/api/jobs.ts
+++ b/server/controllers/api/jobs.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight } from '../../../shared/models/users' 2import { UserRight } from '../../../shared/models/users'
3import { getFormattedObjects } from '../../helpers' 3import { getFormattedObjects } from '../../helpers/utils'
4import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' 4import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares'
5import { paginationValidator } from '../../middlewares/validators' 5import { paginationValidator } from '../../middlewares/validators'
6import { JobModel } from '../../models/job/job' 6import { JobModel } from '../../models/job/job'
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
index bc02fce90..3dcc023e6 100644
--- a/server/controllers/api/oauth-clients.ts
+++ b/server/controllers/api/oauth-clients.ts
@@ -1,9 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2 2import { OAuthClientLocal } from '../../../shared'
3import { logger } from '../../helpers/logger'
3import { CONFIG } from '../../initializers' 4import { CONFIG } from '../../initializers'
4import { logger } from '../../helpers'
5import { asyncMiddleware } from '../../middlewares' 5import { asyncMiddleware } from '../../middlewares'
6import { OAuthClientLocal } from '../../../shared'
7import { OAuthClientModel } from '../../models/oauth/oauth-client' 6import { OAuthClientModel } from '../../models/oauth/oauth-client'
8 7
9const oauthClientsRouter = express.Router() 8const oauthClientsRouter = express.Router()
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index ae5413b75..c87107197 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -1,11 +1,12 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight } from '../../../../shared/models/users' 2import { UserRight } from '../../../../shared/models/users'
3import { 3import { sanitizeHost } from '../../../helpers/core-utils'
4 getFormattedObjects, getServerActor, loadActorUrlOrGetFromWebfinger, logger, retryTransactionWrapper, 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
5 sanitizeHost 5import { logger } from '../../../helpers/logger'
6} from '../../../helpers' 6import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
7import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
7import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' 8import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers'
8import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub' 9import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor'
9import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' 10import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send'
10import { 11import {
11 asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, 12 asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort,
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 3106df9b9..75393ad17 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -1,26 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' 2import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
3import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' 3import { retryTransactionWrapper } from '../../helpers/database-utils'
4import { logger } from '../../helpers/logger'
5import { getFormattedObjects } from '../../helpers/utils'
4import { CONFIG } from '../../initializers' 6import { CONFIG } from '../../initializers'
5import { createUserAccountAndChannel } from '../../lib/user' 7import { createUserAccountAndChannel } from '../../lib/user'
6import { 8import {
7 asyncMiddleware, 9 asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort,
8 authenticate, 10 setVideosSort, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator,
9 ensureUserHasRight, 11 usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator
10 ensureUserRegistrationAllowed,
11 paginationValidator,
12 setPagination,
13 setUsersSort,
14 setVideosSort,
15 token,
16 usersAddValidator,
17 usersGetValidator,
18 usersRegisterValidator,
19 usersRemoveValidator,
20 usersSortValidator,
21 usersUpdateMeValidator,
22 usersUpdateValidator,
23 usersVideoRatingValidator
24} from '../../middlewares' 12} from '../../middlewares'
25import { videosSortValidator } from '../../middlewares/validators' 13import { videosSortValidator } from '../../middlewares/validators'
26import { AccountVideoRateModel } from '../../models/account/account-video-rate' 14import { AccountVideoRateModel } from '../../models/account/account-video-rate'
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index fecdaf5a3..e78f0f6fc 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -1,17 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight, VideoAbuseCreate } from '../../../../shared' 2import { UserRight, VideoAbuseCreate } from '../../../../shared'
3import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
5import { getFormattedObjects } from '../../../helpers/utils'
4import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
5import { sendVideoAbuse } from '../../../lib/activitypub/send' 7import { sendVideoAbuse } from '../../../lib/activitypub/send'
6import { 8import {
7 asyncMiddleware, 9 asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setPagination, setVideoAbusesSort,
8 authenticate, 10 videoAbuseReportValidator, videoAbusesSortValidator
9 ensureUserHasRight,
10 paginationValidator,
11 setPagination,
12 setVideoAbusesSort,
13 videoAbuseReportValidator,
14 videoAbusesSortValidator
15} from '../../../middlewares' 11} from '../../../middlewares'
16import { AccountModel } from '../../../models/account/account' 12import { AccountModel } from '../../../models/account/account'
17import { VideoModel } from '../../../models/video/video' 13import { VideoModel } from '../../../models/video/video'
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index d08c6e13f..c9087fd97 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -1,17 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { logger, getFormattedObjects } from '../../../helpers' 2import { BlacklistedVideo, UserRight } from '../../../../shared'
3import { logger } from '../../../helpers/logger'
4import { getFormattedObjects } from '../../../helpers/utils'
3import { 5import {
4 authenticate, 6 asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setPagination,
5 ensureUserHasRight, 7 videosBlacklistAddValidator, videosBlacklistRemoveValidator
6 videosBlacklistAddValidator,
7 videosBlacklistRemoveValidator,
8 paginationValidator,
9 blacklistSortValidator,
10 setBlacklistSort,
11 setPagination,
12 asyncMiddleware
13} from '../../../middlewares' 8} from '../../../middlewares'
14import { BlacklistedVideo, UserRight } from '../../../../shared'
15import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 9import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
16 10
17const blacklistRouter = express.Router() 11const blacklistRouter = express.Router()
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts
index cc00d9f8d..7c62b5476 100644
--- a/server/controllers/api/videos/channel.ts
+++ b/server/controllers/api/videos/channel.ts
@@ -1,20 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' 2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared'
3import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
5import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils'
4import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
5import { setAsyncActorKeys } from '../../../lib/activitypub' 7import { setAsyncActorKeys } from '../../../lib/activitypub'
6import { createVideoChannel } from '../../../lib/video-channel' 8import { createVideoChannel } from '../../../lib/video-channel'
7import { 9import {
8 asyncMiddleware, 10 asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setPagination, setVideoChannelsSort,
9 authenticate, 11 videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator,
10 listVideoAccountChannelsValidator,
11 paginationValidator,
12 setPagination,
13 setVideoChannelsSort,
14 videoChannelsAddValidator,
15 videoChannelsGetValidator,
16 videoChannelsRemoveValidator,
17 videoChannelsSortValidator,
18 videoChannelsUpdateValidator 12 videoChannelsUpdateValidator
19} from '../../../middlewares' 13} from '../../../middlewares'
20import { AccountModel } from '../../../models/account/account' 14import { AccountModel } from '../../../models/account/account'
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 276948098..b11da2ef7 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 2import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
3import { getFormattedObjects, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { getFormattedObjects } from '../../../helpers/utils'
4import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
5import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' 6import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment'
6import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' 7import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares'
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 8e54d95ab..11e3da5cc 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -2,44 +2,21 @@ import * as express from 'express'
2import * as multer from 'multer' 2import * as multer from 'multer'
3import { extname, join } from 'path' 3import { extname, join } from 'path'
4import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' 4import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
5import { renamePromise } from '../../../helpers/core-utils'
6import { retryTransactionWrapper } from '../../../helpers/database-utils'
7import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils'
8import { logger } from '../../../helpers/logger'
9import { generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
5import { 10import {
6 generateRandomString, 11 CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT,
7 getFormattedObjects,
8 getVideoFileHeight,
9 logger,
10 renamePromise,
11 resetSequelizeInstance,
12 retryTransactionWrapper
13} from '../../../helpers'
14import { getServerActor } from '../../../helpers/utils'
15import {
16 CONFIG,
17 sequelizeTypescript,
18 VIDEO_CATEGORIES,
19 VIDEO_LANGUAGES,
20 VIDEO_LICENCES,
21 VIDEO_MIMETYPE_EXT,
22 VIDEO_PRIVACIES 12 VIDEO_PRIVACIES
23} from '../../../initializers' 13} from '../../../initializers'
24import { 14import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
25 fetchRemoteVideoDescription,
26 getVideoActivityPubUrl,
27 shareVideoByServerAndChannel
28} from '../../../lib/activitypub'
29import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' 15import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
30import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' 16import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler'
31import { 17import {
32 asyncMiddleware, 18 asyncMiddleware, authenticate, paginationValidator, setPagination, setVideosSort, videosAddValidator, videosGetValidator,
33 authenticate, 19 videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator
34 paginationValidator,
35 setPagination,
36 setVideosSort,
37 videosAddValidator,
38 videosGetValidator,
39 videosRemoveValidator,
40 videosSearchValidator,
41 videosSortValidator,
42 videosUpdateValidator
43} from '../../../middlewares' 20} from '../../../middlewares'
44import { TagModel } from '../../../models/video/tag' 21import { TagModel } from '../../../models/video/tag'
45import { VideoModel } from '../../../models/video/video' 22import { VideoModel } from '../../../models/video/video'
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index 48b744b0c..b470f27f6 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserVideoRateUpdate } from '../../../../shared' 2import { UserVideoRateUpdate } from '../../../../shared'
3import { logger, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
4import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' 5import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers'
5import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' 6import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub'
6import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' 7import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares'
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 9a72fe8e0..39e046727 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -1,15 +1,9 @@
1import * as Bluebird from 'bluebird'
1import * as express from 'express' 2import * as express from 'express'
2import { join } from 'path' 3import { join } from 'path'
3import * as validator from 'validator' 4import * as validator from 'validator'
4import * as Bluebird from 'bluebird' 5import { escapeHTML, readFileBufferPromise, root } from '../helpers/core-utils'
5import { 6import { CONFIG, EMBED_SIZE, OPENGRAPH_AND_OEMBED_COMMENT, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers'
6 CONFIG,
7 STATIC_PATHS,
8 STATIC_MAX_AGE,
9 OPENGRAPH_AND_OEMBED_COMMENT,
10 EMBED_SIZE
11} from '../initializers'
12import { root, readFileBufferPromise, escapeHTML } from '../helpers'
13import { asyncMiddleware } from '../middlewares' 7import { asyncMiddleware } from '../middlewares'
14import { VideoModel } from '../models/video/video' 8import { VideoModel } from '../models/video/video'
15 9
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index ec8da3350..630bace30 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -46,7 +46,8 @@ function isActorPrivateKeyValid (privateKey: string) {
46} 46}
47 47
48function isRemoteActorValid (remoteActor: any) { 48function isRemoteActorValid (remoteActor: any) {
49 return isActivityPubUrlValid(remoteActor.id) && 49 return exists(remoteActor) &&
50 isActivityPubUrlValid(remoteActor.id) &&
50 isActorTypeValid(remoteActor.type) && 51 isActorTypeValid(remoteActor.type) &&
51 isActivityPubUrlValid(remoteActor.following) && 52 isActivityPubUrlValid(remoteActor.following) &&
52 isActivityPubUrlValid(remoteActor.followers) && 53 isActivityPubUrlValid(remoteActor.followers) &&
diff --git a/server/helpers/custom-validators/activitypub/announce.ts b/server/helpers/custom-validators/activitypub/announce.ts
index 1baea4f60..7dd1d6988 100644
--- a/server/helpers/custom-validators/activitypub/announce.ts
+++ b/server/helpers/custom-validators/activitypub/announce.ts
@@ -2,7 +2,6 @@ import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
2import { isVideoTorrentCreateActivityValid } from './videos' 2import { isVideoTorrentCreateActivityValid } from './videos'
3 3
4function isAnnounceActivityValid (activity: any) { 4function isAnnounceActivityValid (activity: any) {
5 console.log(activity)
6 return isBaseActivityValid(activity, 'Announce') && 5 return isBaseActivityValid(activity, 'Announce') &&
7 ( 6 (
8 isVideoTorrentCreateActivityValid(activity.object) || 7 isVideoTorrentCreateActivityValid(activity.object) ||
diff --git a/server/helpers/custom-validators/activitypub/index.ts b/server/helpers/custom-validators/activitypub/index.ts
deleted file mode 100644
index ba411f1c6..000000000
--- a/server/helpers/custom-validators/activitypub/index.ts
+++ /dev/null
@@ -1,8 +0,0 @@
1export * from './actor'
2export * from './activity'
3export * from './misc'
4export * from './signature'
5export * from './undo'
6export * from './video-channels'
7export * from './videos'
8export * from './view'
diff --git a/server/helpers/index.ts b/server/helpers/index.ts
deleted file mode 100644
index d96bc48e9..000000000
--- a/server/helpers/index.ts
+++ /dev/null
@@ -1,9 +0,0 @@
1export * from './activitypub'
2export * from './core-utils'
3export * from './logger'
4export * from './ffmpeg-utils'
5export * from './database-utils'
6export * from './peertube-crypto'
7export * from './requests'
8export * from './utils'
9export * from './webfinger'
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 4b1deeadc..ce185a2c0 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -1,8 +1,14 @@
1import * as Promise from 'bluebird' 1import * as Promise from 'bluebird'
2import { createWriteStream } from 'fs' 2import { createWriteStream } from 'fs'
3import * as request from 'request' 3import * as request from 'request'
4import { ACTIVITY_PUB } from '../initializers'
5
6function doRequest (requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }) {
7 if (requestOptions.activityPub === true) {
8 if (!Array.isArray(requestOptions.headers)) requestOptions.headers = {}
9 requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER
10 }
4 11
5function doRequest (requestOptions: request.CoreOptions & request.UriOptions) {
6 return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { 12 return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => {
7 request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) 13 request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body }))
8 }) 14 })
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
index 76444fbe3..de8d52c9b 100644
--- a/server/helpers/webfinger.ts
+++ b/server/helpers/webfinger.ts
@@ -2,7 +2,7 @@ import * as WebFinger from 'webfinger.js'
2import { WebFingerData } from '../../shared' 2import { WebFingerData } from '../../shared'
3import { ActorModel } from '../models/activitypub/actor' 3import { ActorModel } from '../models/activitypub/actor'
4import { isTestInstance } from './core-utils' 4import { isTestInstance } from './core-utils'
5import { isActivityPubUrlValid } from './custom-validators/activitypub' 5import { isActivityPubUrlValid } from './custom-validators/activitypub/misc'
6 6
7const webfinger = new WebFinger({ 7const webfinger = new WebFinger({
8 webfist_fallback: false, 8 webfist_fallback: false,
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts
index 7e76990b5..45647ab1d 100644
--- a/server/initializers/checker.ts
+++ b/server/initializers/checker.ts
@@ -1,5 +1,5 @@
1import * as config from 'config' 1import * as config from 'config'
2import { promisify0 } from '../helpers' 2import { promisify0 } from '../helpers/core-utils'
3import { UserModel } from '../models/account/user' 3import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application' 4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index ee3c9dfd9..58713c2c4 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -1,6 +1,7 @@
1import * as passwordGenerator from 'password-generator' 1import * as passwordGenerator from 'password-generator'
2import { UserRole } from '../../shared' 2import { UserRole } from '../../shared'
3import { logger, mkdirpPromise, rimrafPromise } from '../helpers' 3import { mkdirpPromise, rimrafPromise } from '../helpers/core-utils'
4import { logger } from '../helpers/logger'
4import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' 5import { createApplicationActor, createUserAccountAndChannel } from '../lib/user'
5import { UserModel } from '../models/account/user' 6import { UserModel } from '../models/account/user'
6import { ApplicationModel } from '../models/application/application' 7import { ApplicationModel } from '../models/application/application'
diff --git a/server/initializers/migrations/0135-video-channel-actor.ts b/server/initializers/migrations/0135-video-channel-actor.ts
index 9b5acb338..033f43b68 100644
--- a/server/initializers/migrations/0135-video-channel-actor.ts
+++ b/server/initializers/migrations/0135-video-channel-actor.ts
@@ -1,6 +1,6 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { DataType } from 'sequelize-typescript' 2import { DataType } from 'sequelize-typescript'
3import { createPrivateAndPublicKeys } from '../../helpers' 3import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
4 4
5async function up (utils: { 5async function up (utils: {
6 transaction: Sequelize.Transaction, 6 transaction: Sequelize.Transaction,
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts
index bb2539fc8..29310b913 100644
--- a/server/initializers/migrator.ts
+++ b/server/initializers/migrator.ts
@@ -1,5 +1,6 @@
1import * as path from 'path' 1import * as path from 'path'
2import { logger, readdirPromise } from '../helpers' 2import { readdirPromise } from '../helpers/core-utils'
3import { logger } from '../helpers/logger'
3import { LAST_MIGRATION_VERSION } from './constants' 4import { LAST_MIGRATION_VERSION } from './constants'
4import { sequelizeTypescript } from './database' 5import { sequelizeTypescript } from './database'
5 6
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index ff0a291e8..e590dc72d 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -3,9 +3,12 @@ import { Transaction } from 'sequelize'
3import * as url from 'url' 3import * as url from 'url'
4import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' 4import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub'
5import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' 5import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects'
6import { createPrivateAndPublicKeys, doRequest, logger, retryTransactionWrapper } from '../../helpers' 6import { isRemoteActorValid } from '../../helpers/custom-validators/activitypub/actor'
7import { isRemoteActorValid } from '../../helpers/custom-validators/activitypub' 7import { retryTransactionWrapper } from '../../helpers/database-utils'
8import { ACTIVITY_PUB, CONFIG, sequelizeTypescript } from '../../initializers' 8import { logger } from '../../helpers/logger'
9import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
10import { doRequest } from '../../helpers/requests'
11import { CONFIG, sequelizeTypescript } from '../../initializers'
9import { AccountModel } from '../../models/account/account' 12import { AccountModel } from '../../models/account/account'
10import { ActorModel } from '../../models/activitypub/actor' 13import { ActorModel } from '../../models/activitypub/actor'
11import { ServerModel } from '../../models/server/server' 14import { ServerModel } from '../../models/server/server'
@@ -115,22 +118,15 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu
115 const options = { 118 const options = {
116 uri: actorUrl, 119 uri: actorUrl,
117 method: 'GET', 120 method: 'GET',
118 headers: { 121 json: true,
119 'Accept': ACTIVITY_PUB.ACCEPT_HEADER 122 activityPub: true
120 }
121 } 123 }
122 124
123 logger.info('Fetching remote actor %s.', actorUrl) 125 logger.info('Fetching remote actor %s.', actorUrl)
124 126
125 let requestResult 127 const requestResult = await doRequest(options)
126 try { 128 const actorJSON: ActivityPubActor = requestResult.body
127 requestResult = await doRequest(options)
128 } catch (err) {
129 logger.warn('Cannot fetch remote actor %s.', actorUrl, err)
130 return undefined
131 }
132 129
133 const actorJSON: ActivityPubActor = JSON.parse(requestResult.body)
134 if (isRemoteActorValid(actorJSON) === false) { 130 if (isRemoteActorValid(actorJSON) === false) {
135 logger.debug('Remote actor JSON is not valid.', { actorJSON: actorJSON }) 131 logger.debug('Remote actor JSON is not valid.', { actorJSON: actorJSON })
136 return undefined 132 return undefined
@@ -195,7 +191,9 @@ export {
195async function fetchActorTotalItems (url: string) { 191async function fetchActorTotalItems (url: string) {
196 const options = { 192 const options = {
197 uri: url, 193 uri: url,
198 method: 'GET' 194 method: 'GET',
195 json: true,
196 activityPub: true
199 } 197 }
200 198
201 let requestResult 199 let requestResult
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts
index a9c6f913c..f65395c99 100644
--- a/server/lib/activitypub/process/misc.ts
+++ b/server/lib/activitypub/process/misc.ts
@@ -1,11 +1,15 @@
1import * as magnetUtil from 'magnet-uri' 1import * as magnetUtil from 'magnet-uri'
2import { VideoTorrentObject } from '../../../../shared' 2import { VideoTorrentObject } from '../../../../shared'
3import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object'
3import { VideoPrivacy } from '../../../../shared/models/videos' 4import { VideoPrivacy } from '../../../../shared/models/videos'
4import { doRequest } from '../../../helpers'
5import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' 5import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos'
6import { logger } from '../../../helpers/logger'
7import { doRequest } from '../../../helpers/requests'
6import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' 8import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers'
9import { ActorModel } from '../../../models/activitypub/actor'
7import { VideoModel } from '../../../models/video/video' 10import { VideoModel } from '../../../models/video/video'
8import { VideoChannelModel } from '../../../models/video/video-channel' 11import { VideoChannelModel } from '../../../models/video/video-channel'
12import { VideoCommentModel } from '../../../models/video/video-comment'
9import { VideoShareModel } from '../../../models/video/video-share' 13import { VideoShareModel } from '../../../models/video/video-share'
10import { getOrCreateActorAndServerAndModel } from '../actor' 14import { getOrCreateActorAndServerAndModel } from '../actor'
11 15
@@ -97,14 +101,43 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
97 return attributes 101 return attributes
98} 102}
99 103
100async function addVideoShares (instance: VideoModel, shares: string[]) { 104async function videoCommentActivityObjectToDBAttributes (video: VideoModel, actor: ActorModel, comment: VideoCommentObject) {
101 for (const share of shares) { 105 let originCommentId: number = null
106 let inReplyToCommentId: number = null
107
108 // If this is not a reply to the video (thread), create or get the parent comment
109 if (video.url !== comment.inReplyTo) {
110 const [ parent ] = await addVideoComment(video, comment.inReplyTo)
111 if (!parent) {
112 logger.warn('Cannot fetch or get parent comment %s of comment %s.', comment.inReplyTo, comment.id)
113 return undefined
114 }
115
116 originCommentId = parent.originCommentId || parent.id
117 inReplyToCommentId = parent.id
118 }
119
120 return {
121 url: comment.url,
122 text: comment.content,
123 videoId: video.id,
124 accountId: actor.Account.id,
125 inReplyToCommentId,
126 originCommentId,
127 createdAt: new Date(comment.published),
128 updatedAt: new Date(comment.updated)
129 }
130}
131
132async function addVideoShares (instance: VideoModel, shareUrls: string[]) {
133 for (const shareUrl of shareUrls) {
102 // Fetch url 134 // Fetch url
103 const json = await doRequest({ 135 const { body } = await doRequest({
104 uri: share, 136 uri: shareUrl,
105 json: true 137 json: true,
138 activityPub: true
106 }) 139 })
107 const actorUrl = json['actor'] 140 const actorUrl = body.actor
108 if (!actorUrl) continue 141 if (!actorUrl) continue
109 142
110 const actor = await getOrCreateActorAndServerAndModel(actorUrl) 143 const actor = await getOrCreateActorAndServerAndModel(actorUrl)
@@ -121,10 +154,40 @@ async function addVideoShares (instance: VideoModel, shares: string[]) {
121 } 154 }
122} 155}
123 156
157async function addVideoComments (instance: VideoModel, commentUrls: string[]) {
158 for (const commentUrl of commentUrls) {
159 await addVideoComment(instance, commentUrl)
160 }
161}
162
163async function addVideoComment (instance: VideoModel, commentUrl: string) {
164 // Fetch url
165 const { body } = await doRequest({
166 uri: commentUrl,
167 json: true,
168 activityPub: true
169 })
170
171 const actorUrl = body.attributedTo
172 if (!actorUrl) return []
173
174 const actor = await getOrCreateActorAndServerAndModel(actorUrl)
175 const entry = await videoCommentActivityObjectToDBAttributes(instance, actor, body)
176 if (!entry) return []
177
178 return VideoCommentModel.findOrCreate({
179 where: {
180 url: body.id
181 },
182 defaults: entry
183 })
184}
185
124// --------------------------------------------------------------------------- 186// ---------------------------------------------------------------------------
125 187
126export { 188export {
127 videoFileActivityUrlToDBAttributes, 189 videoFileActivityUrlToDBAttributes,
128 videoActivityObjectToDBAttributes, 190 videoActivityObjectToDBAttributes,
129 addVideoShares 191 addVideoShares,
192 addVideoComments
130} 193}
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 55f8a62d2..9adb40e01 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -1,5 +1,6 @@
1import { ActivityAnnounce } from '../../../../shared/models/activitypub' 1import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { logger } from '../../../helpers/logger'
3import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index 628942a58..ffd20fe74 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -3,7 +3,8 @@ import { ActivityCreate, VideoTorrentObject } from '../../../../shared'
3import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' 3import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects'
4import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' 4import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object'
5import { VideoRateType } from '../../../../shared/models/videos' 5import { VideoRateType } from '../../../../shared/models/videos'
6import { logger, retryTransactionWrapper } from '../../../helpers' 6import { retryTransactionWrapper } from '../../../helpers/database-utils'
7import { logger } from '../../../helpers/logger'
7import { sequelizeTypescript } from '../../../initializers' 8import { sequelizeTypescript } from '../../../initializers'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 9import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { ActorModel } from '../../../models/activitypub/actor' 10import { ActorModel } from '../../../models/activitypub/actor'
@@ -15,7 +16,7 @@ import { VideoFileModel } from '../../../models/video/video-file'
15import { getOrCreateActorAndServerAndModel } from '../actor' 16import { getOrCreateActorAndServerAndModel } from '../actor'
16import { forwardActivity } from '../send/misc' 17import { forwardActivity } from '../send/misc'
17import { generateThumbnailFromUrl } from '../videos' 18import { generateThumbnailFromUrl } from '../videos'
18import { addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' 19import { addVideoComments, addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
19 20
20async function processCreateActivity (activity: ActivityCreate) { 21async function processCreateActivity (activity: ActivityCreate) {
21 const activityObject = activity.object 22 const activityObject = activity.object
@@ -66,17 +67,25 @@ async function processCreateVideo (
66 67
67 // Process outside the transaction because we could fetch remote data 68 // Process outside the transaction because we could fetch remote data
68 if (videoToCreateData.likes && Array.isArray(videoToCreateData.likes.orderedItems)) { 69 if (videoToCreateData.likes && Array.isArray(videoToCreateData.likes.orderedItems)) {
70 logger.info('Adding likes of video %s.', video.uuid)
69 await createRates(videoToCreateData.likes.orderedItems, video, 'like') 71 await createRates(videoToCreateData.likes.orderedItems, video, 'like')
70 } 72 }
71 73
72 if (videoToCreateData.dislikes && Array.isArray(videoToCreateData.dislikes.orderedItems)) { 74 if (videoToCreateData.dislikes && Array.isArray(videoToCreateData.dislikes.orderedItems)) {
75 logger.info('Adding dislikes of video %s.', video.uuid)
73 await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike') 76 await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike')
74 } 77 }
75 78
76 if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) { 79 if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) {
80 logger.info('Adding shares of video %s.', video.uuid)
77 await addVideoShares(video, videoToCreateData.shares.orderedItems) 81 await addVideoShares(video, videoToCreateData.shares.orderedItems)
78 } 82 }
79 83
84 if (videoToCreateData.comments && Array.isArray(videoToCreateData.comments.orderedItems)) {
85 logger.info('Adding comments of video %s.', video.uuid)
86 await addVideoComments(video, videoToCreateData.comments.orderedItems)
87 }
88
80 return video 89 return video
81} 90}
82 91
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 65a4e5bcc..523a31822 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -1,5 +1,6 @@
1import { ActivityDelete } from '../../../../shared/models/activitypub' 1import { ActivityDelete } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { logger } from '../../../helpers/logger'
3import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
4import { AccountModel } from '../../../models/account/account' 5import { AccountModel } from '../../../models/account/account'
5import { ActorModel } from '../../../models/activitypub/actor' 6import { ActorModel } from '../../../models/activitypub/actor'
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index e78005dd0..5085c5da9 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -1,5 +1,6 @@
1import { ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { logger } from '../../../helpers/logger'
3import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
5import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index a7fcec21c..77fadabe1 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,5 +1,5 @@
1import { ActivityLike } from '../../../../shared/models/activitypub' 1import { ActivityLike } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 4import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index 4a0181137..9cad59233 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -1,6 +1,7 @@
1import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' 1import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub'
2import { DislikeObject } from '../../../../shared/models/activitypub/objects' 2import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { logger, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
4import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
5import { AccountModel } from '../../../models/account/account' 6import { AccountModel } from '../../../models/account/account'
6import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 7import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 35912ee87..a5ad406cb 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,6 +1,8 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { ActivityUpdate } from '../../../../shared/models/activitypub' 2import { ActivityUpdate } from '../../../../shared/models/activitypub'
3import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
5import { resetSequelizeInstance } from '../../../helpers/utils'
4import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor' 7import { ActorModel } from '../../../models/activitypub/actor'
6import { TagModel } from '../../../models/video/tag' 8import { TagModel } from '../../../models/video/tag'
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts
index dfb60c1bf..62d310f21 100644
--- a/server/lib/activitypub/process/process.ts
+++ b/server/lib/activitypub/process/process.ts
@@ -1,5 +1,5 @@
1import { Activity, ActivityType } from '../../../../shared/models/activitypub' 1import { Activity, ActivityType } from '../../../../shared/models/activitypub'
2import { logger } from '../../../helpers' 2import { logger } from '../../../helpers/logger'
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { processAcceptActivity } from './process-accept' 4import { processAcceptActivity } from './process-accept'
5import { processAnnounceActivity } from './process-announce' 5import { processAnnounceActivity } from './process-announce'
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts
index 2dc8d3d59..05f327b29 100644
--- a/server/lib/activitypub/send/misc.ts
+++ b/server/lib/activitypub/send/misc.ts
@@ -1,6 +1,6 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' 2import { Activity, ActivityAudience } from '../../../../shared/models/activitypub'
3import { logger } from '../../../helpers' 3import { logger } from '../../../helpers/logger'
4import { ACTIVITY_PUB } from '../../../initializers' 4import { ACTIVITY_PUB } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index ca50460be..2f5cdc8c5 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -1,7 +1,7 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
3import { VideoPrivacy } from '../../../../shared/models/videos' 3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { getServerActor } from '../../../helpers' 4import { getServerActor } from '../../../helpers/utils'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
7import { VideoAbuseModel } from '../../../models/video/video-abuse' 7import { VideoAbuseModel } from '../../../models/video/video-abuse'
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index 294a6838d..fd374d03d 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -1,6 +1,6 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { VideoPrivacy } from '../../../shared/models/videos' 2import { VideoPrivacy } from '../../../shared/models/videos'
3import { getServerActor } from '../../helpers' 3import { getServerActor } from '../../helpers/utils'
4import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
5import { VideoShareModel } from '../../models/video/video-share' 5import { VideoShareModel } from '../../models/video/video-share'
6import { sendVideoAnnounceToFollowers } from './send' 6import { sendVideoAnnounceToFollowers } from './send'
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 729bb8dda..3d5f0523c 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -10,7 +10,7 @@ function getVideoActivityPubUrl (video: VideoModel) {
10} 10}
11 11
12function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) { 12function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) {
13 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '#comment-' + videoComment.id 13 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
14} 14}
15 15
16function getVideoChannelActivityPubUrl (videoChannelUUID: string) { 16function getVideoChannelActivityPubUrl (videoChannelUUID: string) {
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 83f3e9933..8bc928b93 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -2,19 +2,13 @@ import { join } from 'path'
2import * as request from 'request' 2import * as request from 'request'
3import { Transaction } from 'sequelize' 3import { Transaction } from 'sequelize'
4import { ActivityIconObject } from '../../../shared/index' 4import { ActivityIconObject } from '../../../shared/index'
5import { doRequest, doRequestAndSaveToFile } from '../../helpers' 5import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
6import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers' 6import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers'
7import { AccountModel } from '../../models/account/account' 7import { AccountModel } from '../../models/account/account'
8import { VideoModel } from '../../models/video/video' 8import { VideoModel } from '../../models/video/video'
9import { 9import {
10 sendCreateDislikeToOrigin, 10 sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, sendLikeToOrigin, sendLikeToVideoFollowers, sendUndoDislikeToOrigin,
11 sendCreateDislikeToVideoFollowers, 11 sendUndoDislikeToVideoFollowers, sendUndoLikeToOrigin, sendUndoLikeToVideoFollowers
12 sendLikeToOrigin,
13 sendLikeToVideoFollowers,
14 sendUndoDislikeToOrigin,
15 sendUndoDislikeToVideoFollowers,
16 sendUndoLikeToOrigin,
17 sendUndoLikeToVideoFollowers
18} from './send' 12} from './send'
19 13
20function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { 14function fetchRemoteVideoPreview (video: VideoModel, reject: Function) {
diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/cache/videos-preview-cache.ts
index 930298dbe..d09d55e11 100644
--- a/server/lib/cache/videos-preview-cache.ts
+++ b/server/lib/cache/videos-preview-cache.ts
@@ -1,7 +1,8 @@
1import * as asyncLRU from 'async-lru' 1import * as asyncLRU from 'async-lru'
2import { createWriteStream } from 'fs' 2import { createWriteStream } from 'fs'
3import { join } from 'path' 3import { join } from 'path'
4import { logger, unlinkPromise } from '../../helpers' 4import { unlinkPromise } from '../../helpers/core-utils'
5import { logger } from '../../helpers/logger'
5import { CACHE, CONFIG } from '../../initializers' 6import { CACHE, CONFIG } from '../../initializers'
6import { VideoModel } from '../../models/video/video' 7import { VideoModel } from '../../models/video/video'
7import { fetchRemoteVideoPreview } from '../activitypub' 8import { fetchRemoteVideoPreview } from '../activitypub'
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
index 3c4d5556f..c20a48a4e 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts
@@ -1,4 +1,5 @@
1import { doRequest, logger } from '../../../helpers' 1import { logger } from '../../../helpers/logger'
2import { doRequest } from '../../../helpers/requests'
2import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' 3import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
3 4
4async function process (payload: ActivityPubHttpPayload, jobId: number) { 5async function process (payload: ActivityPubHttpPayload, jobId: number) {
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-fetcher-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-fetcher-handler.ts
index 638150202..a7b5aabd0 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-fetcher-handler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-fetcher-handler.ts
@@ -1,4 +1,5 @@
1import { doRequest, logger } from '../../../helpers' 1import { logger } from '../../../helpers/logger'
2import { doRequest } from '../../../helpers/requests'
2import { ACTIVITY_PUB } from '../../../initializers' 3import { ACTIVITY_PUB } from '../../../initializers'
3import { processActivities } from '../../activitypub/process' 4import { processActivities } from '../../activitypub/process'
4import { ActivityPubHttpPayload } from './activitypub-http-job-scheduler' 5import { ActivityPubHttpPayload } from './activitypub-http-job-scheduler'
@@ -9,7 +10,8 @@ async function process (payload: ActivityPubHttpPayload, jobId: number) {
9 const options = { 10 const options = {
10 method: 'GET', 11 method: 'GET',
11 uri: '', 12 uri: '',
12 json: true 13 json: true,
14 activityPub: true
13 } 15 }
14 16
15 for (const uri of payload.uris) { 17 for (const uri of payload.uris) {
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts
index 88885cf97..d576cd42e 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts
@@ -1,5 +1,7 @@
1import { JobCategory } from '../../../../shared' 1import { JobCategory } from '../../../../shared'
2import { buildSignedActivity, getServerActor, logger } from '../../../helpers' 2import { buildSignedActivity } from '../../../helpers/activitypub'
3import { logger } from '../../../helpers/logger'
4import { getServerActor } from '../../../helpers/utils'
3import { ACTIVITY_PUB } from '../../../initializers' 5import { ACTIVITY_PUB } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor' 6import { ActorModel } from '../../../models/activitypub/actor'
5import { JobHandler, JobScheduler } from '../job-scheduler' 7import { JobHandler, JobScheduler } from '../job-scheduler'
diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
index 7a5caa679..175ec6642 100644
--- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
+++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
@@ -1,4 +1,5 @@
1import { doRequest, logger } from '../../../helpers' 1import { logger } from '../../../helpers/logger'
2import { doRequest } from '../../../helpers/requests'
2import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' 3import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler'
3 4
4async function process (payload: ActivityPubHttpPayload, jobId: number) { 5async function process (payload: ActivityPubHttpPayload, jobId: number) {
diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts
index 88fe8a4a3..9d55880e6 100644
--- a/server/lib/jobs/job-scheduler.ts
+++ b/server/lib/jobs/job-scheduler.ts
@@ -1,7 +1,7 @@
1import { AsyncQueue, forever, queue } from 'async' 1import { AsyncQueue, forever, queue } from 'async'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3import { JobCategory } from '../../../shared' 3import { JobCategory } from '../../../shared'
4import { logger } from '../../helpers' 4import { logger } from '../../helpers/logger'
5import { JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' 5import { JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers'
6import { JobModel } from '../../models/job/job' 6import { JobModel } from '../../models/job/job'
7 7
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
index d905882be..23677e8d5 100644
--- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
+++ b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
@@ -1,6 +1,7 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { VideoPrivacy } from '../../../../shared/models/videos' 2import { VideoPrivacy } from '../../../../shared/models/videos'
3import { computeResolutionsToTranscode, logger } from '../../../helpers' 3import { logger } from '../../../helpers/logger'
4import { computeResolutionsToTranscode } from '../../../helpers/utils'
4import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
5import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
6import { shareVideoByServerAndChannel } from '../../activitypub' 7import { shareVideoByServerAndChannel } from '../../activitypub'
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
index 409123bfe..883d3eba8 100644
--- a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
+++ b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts
@@ -1,6 +1,6 @@
1import { VideoResolution } from '../../../../shared' 1import { VideoResolution } from '../../../../shared'
2import { VideoPrivacy } from '../../../../shared/models/videos' 2import { VideoPrivacy } from '../../../../shared/models/videos'
3import { logger } from '../../../helpers' 3import { logger } from '../../../helpers/logger'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { sendUpdateVideo } from '../../activitypub/send' 5import { sendUpdateVideo } from '../../activitypub/send'
6 6
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index dce71e83b..b3cc75590 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -1,4 +1,4 @@
1import { logger } from '../helpers' 1import { logger } from '../helpers/logger'
2import { UserModel } from '../models/account/user' 2import { UserModel } from '../models/account/user'
3import { OAuthClientModel } from '../models/oauth/oauth-client' 3import { OAuthClientModel } from '../models/oauth/oauth-client'
4import { OAuthTokenModel } from '../models/oauth/oauth-token' 4import { OAuthTokenModel } from '../models/oauth/oauth-token'
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index c00a6affa..1488b42ab 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -1,7 +1,8 @@
1import { eachSeries } from 'async' 1import { eachSeries } from 'async'
2import { NextFunction, Request, RequestHandler, Response } from 'express' 2import { NextFunction, Request, RequestHandler, Response } from 'express'
3import { ActivityPubSignature } from '../../shared' 3import { ActivityPubSignature } from '../../shared'
4import { isSignatureVerified, logger } from '../helpers' 4import { logger } from '../helpers/logger'
5import { isSignatureVerified } from '../helpers/peertube-crypto'
5import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers' 6import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers'
6import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' 7import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'
7import { ActorModel } from '../models/activitypub/actor' 8import { ActorModel } from '../models/activitypub/actor'
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 3faecdbcc..e59168ea8 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -1,9 +1,8 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import * as OAuthServer from 'express-oauth-server' 3import * as OAuthServer from 'express-oauth-server'
4 4import { logger } from '../helpers/logger'
5import { OAUTH_LIFETIME } from '../initializers' 5import { OAUTH_LIFETIME } from '../initializers'
6import { logger } from '../helpers'
7 6
8const oAuthServer = new OAuthServer({ 7const oAuthServer = new OAuthServer({
9 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, 8 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
index e16bc4a86..a9dcad2d4 100644
--- a/server/middlewares/servers.ts
+++ b/server/middlewares/servers.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { getHostWithPort } from '../helpers' 3import { getHostWithPort } from '../helpers/utils'
4 4
5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.body.hosts) return next() 6 if (!req.body.hosts) return next()
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 0eb50db89..fdd6d419f 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { SortType } from '../helpers' 3import { SortType } from '../helpers/utils'
4 4
5function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.query.sort) req.query.sort = '-createdAt' 6 if (!req.query.sort) req.query.sort = '-createdAt'
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts
index 5d63ebaf4..5bb5bdfbd 100644
--- a/server/middlewares/user-right.ts
+++ b/server/middlewares/user-right.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { UserRight } from '../../shared' 3import { UserRight } from '../../shared'
4import { logger } from '../helpers' 4import { logger } from '../helpers/logger'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6 6
7function ensureUserHasRight (userRight: UserRight) { 7function ensureUserHasRight (userRight: UserRight) {
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 6951dfc80..3573a9a50 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' 3import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6 6
7const localAccountValidator = [ 7const localAccountValidator = [
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index e0225f30c..208e23f86 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { logger } from '../../../helpers' 3import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
4import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6 6
7const activityPubValidator = [ 7const activityPubValidator = [
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts
index d41bb6a8d..4efe9aafa 100644
--- a/server/middlewares/validators/activitypub/signature.ts
+++ b/server/middlewares/validators/activitypub/signature.ts
@@ -1,8 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { logger } from '../../../helpers' 3import {
4import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' 4 isSignatureCreatorValid, isSignatureTypeValid,
5 isSignatureValueValid
6} from '../../../helpers/custom-validators/activitypub/signature'
5import { isDateValid } from '../../../helpers/custom-validators/misc' 7import { isDateValid } from '../../../helpers/custom-validators/misc'
8import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils' 9import { areValidationErrors } from '../utils'
7 10
8const signatureValidator = [ 11const signatureValidator = [
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 2240d30db..7dadf6a19 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -1,7 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { getServerActor, isTestInstance, logger } from '../../helpers' 3import { isTestInstance } from '../../helpers/core-utils'
4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' 4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
5import { logger } from '../../helpers/logger'
6import { getServerActor } from '../../helpers/utils'
5import { CONFIG } from '../../initializers' 7import { CONFIG } from '../../initializers'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 8import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index fb7b726e5..cd9b27b16 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -1,9 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { join } from 'path' 3import { join } from 'path'
4import { isTestInstance, logger } from '../../helpers' 4import { isTestInstance } from '../../helpers/core-utils'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 6import { isVideoExist } from '../../helpers/custom-validators/videos'
7import { logger } from '../../helpers/logger'
7import { CONFIG } from '../../initializers' 8import { CONFIG } from '../../initializers'
8import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
9 10
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index 25debfa6e..e1ed8cd65 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5 5
6const paginationValidator = [ 6const paginationValidator = [
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index 56855bda0..e1d8d7d1b 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,6 +1,6 @@
1import { query } from 'express-validator/check'
2import * as express from 'express' 1import * as express from 'express'
3import { logger } from '../../helpers' 2import { query } from 'express-validator/check'
3import { logger } from '../../helpers/logger'
4import { SORTABLE_COLUMNS } from '../../initializers' 4import { SORTABLE_COLUMNS } from '../../initializers'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6 6
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index a6fdbe268..db40a5c88 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,17 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param } from 'express-validator/check'
4import { isSignupAllowed, logger } from '../../helpers'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { 5import {
7 isUserDisplayNSFWValid, 6 isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid,
8 isUserAutoPlayVideoValid,
9 isUserPasswordValid,
10 isUserRoleValid,
11 isUserUsernameValid,
12 isUserVideoQuotaValid 7 isUserVideoQuotaValid
13} from '../../helpers/custom-validators/users' 8} from '../../helpers/custom-validators/users'
14import { isVideoExist } from '../../helpers/custom-validators/videos' 9import { isVideoExist } from '../../helpers/custom-validators/videos'
10import { logger } from '../../helpers/logger'
11import { isSignupAllowed } from '../../helpers/utils'
15import { UserModel } from '../../models/account/user' 12import { UserModel } from '../../models/account/user'
16import { areValidationErrors } from './utils' 13import { areValidationErrors } from './utils'
17 14
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index 61f76b457..55b140103 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { validationResult } from 'express-validator/check' 2import { validationResult } from 'express-validator/check'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers/logger'
4 4
5function areValidationErrors (req: express.Request, res: express.Response) { 5function areValidationErrors (req: express.Request, res: express.Response) {
6 const errors = validationResult(req) 6 const errors = validationResult(req)
diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts
index 98099fe3f..3c1ef1b4e 100644
--- a/server/middlewares/validators/video-blacklist.ts
+++ b/server/middlewares/validators/video-blacklist.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../helpers/custom-validators/videos' 4import { isVideoExist } from '../../helpers/custom-validators/videos'
5import { logger } from '../../helpers/logger'
6import { VideoModel } from '../../models/video/video' 6import { VideoModel } from '../../models/video/video'
7import { VideoBlacklistModel } from '../../models/video/video-blacklist' 7import { VideoBlacklistModel } from '../../models/video/video-blacklist'
8import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 0e6eff493..86bddde82 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,14 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { logger } from '../../helpers'
5import { isAccountIdExist } from '../../helpers/custom-validators/accounts' 4import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
6import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
7import { 6import {
8 isVideoChannelDescriptionValid, 7 isVideoChannelDescriptionValid, isVideoChannelExist,
9 isVideoChannelExist,
10 isVideoChannelNameValid 8 isVideoChannelNameValid
11} from '../../helpers/custom-validators/video-channels' 9} from '../../helpers/custom-validators/video-channels'
10import { logger } from '../../helpers/logger'
12import { UserModel } from '../../models/account/user' 11import { UserModel } from '../../models/account/user'
13import { VideoChannelModel } from '../../models/video/video-channel' 12import { VideoChannelModel } from '../../models/video/video-channel'
14import { areValidationErrors } from './utils' 13import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts
index 1d19fac58..fdd092571 100644
--- a/server/middlewares/validators/video-comments.ts
+++ b/server/middlewares/validators/video-comments.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' 4import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 5import { isVideoExist } from '../../helpers/custom-validators/videos'
6import { logger } from '../../helpers/logger'
7import { VideoModel } from '../../models/video/video' 7import { VideoModel } from '../../models/video/video'
8import { VideoCommentModel } from '../../models/video/video-comment' 8import { VideoCommentModel } from '../../models/video/video-comment'
9import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [
66 } 66 }
67] 67]
68 68
69const videoCommentGetValidator = [
70 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
71 param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'),
72
73 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
74 logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
75
76 if (areValidationErrors(req, res)) return
77 if (!await isVideoExist(req.params.videoId, res)) return
78 if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return
79
80 return next()
81 }
82]
83
69// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
70 85
71export { 86export {
72 listVideoCommentThreadsValidator, 87 listVideoCommentThreadsValidator,
73 listVideoThreadCommentsValidator, 88 listVideoThreadCommentsValidator,
74 addVideoCommentThreadValidator, 89 addVideoCommentThreadValidator,
75 addVideoCommentReplyValidator 90 addVideoCommentReplyValidator,
91 videoCommentGetValidator
76} 92}
77 93
78// --------------------------------------------------------------------------- 94// ---------------------------------------------------------------------------
@@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex
109} 125}
110 126
111async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { 127async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) {
112 const videoComment = await VideoCommentModel.loadById(id) 128 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
113 129
114 if (!videoComment) { 130 if (!videoComment) {
115 res.status(404) 131 res.status(404)
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index b52d5f285..bffc50322 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -2,22 +2,13 @@ import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param, query } from 'express-validator/check' 3import { body, param, query } from 'express-validator/check'
4import { UserRight, VideoPrivacy } from '../../../shared' 4import { UserRight, VideoPrivacy } from '../../../shared'
5import { getDurationFromVideoFile, logger } from '../../helpers'
6import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
7import { 6import {
8 isVideoAbuseReasonValid, 7 isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid,
9 isVideoCategoryValid, 8 isVideoLicenceValid, isVideoNameValid, isVideoNSFWValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid
10 isVideoDescriptionValid,
11 isVideoExist,
12 isVideoFile,
13 isVideoLanguageValid,
14 isVideoLicenceValid,
15 isVideoNameValid,
16 isVideoNSFWValid,
17 isVideoPrivacyValid,
18 isVideoRatingTypeValid,
19 isVideoTagsValid
20} from '../../helpers/custom-validators/videos' 9} from '../../helpers/custom-validators/videos'
10import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
11import { logger } from '../../helpers/logger'
21import { CONSTRAINTS_FIELDS } from '../../initializers' 12import { CONSTRAINTS_FIELDS } from '../../initializers'
22import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
23import { VideoModel } from '../../models/video/video' 14import { VideoModel } from '../../models/video/video'
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 894c72498..3dbec6e44 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -1,7 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { getHostWithPort, logger } from '../../helpers'
4import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' 3import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
4import { logger } from '../../helpers/logger'
5import { getHostWithPort } from '../../helpers/utils'
5import { ActorModel } from '../../models/activitypub/actor' 6import { ActorModel } from '../../models/activitypub/actor'
6import { areValidationErrors } from './utils' 7import { areValidationErrors } from './utils'
7 8
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 1d5759ea3..d7e09e328 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -4,11 +4,11 @@ import {
4 Scopes, Table, UpdatedAt 4 Scopes, Table, UpdatedAt
5} from 'sequelize-typescript' 5} from 'sequelize-typescript'
6import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' 6import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
7import { comparePassword, cryptPassword } from '../../helpers'
8import { 7import {
9 isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, 8 isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid,
10 isUserVideoQuotaValid 9 isUserVideoQuotaValid
11} from '../../helpers/custom-validators/users' 10} from '../../helpers/custom-validators/users'
11import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
12import { OAuthTokenModel } from '../oauth/oauth-token' 12import { OAuthTokenModel } from '../oauth/oauth-token'
13import { getSort, throwIfNotValid } from '../utils' 13import { getSort, throwIfNotValid } from '../utils'
14import { VideoChannelModel } from '../video/video-channel' 14import { VideoChannelModel } from '../video/video-channel'
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index e7eb35e2c..3d96b3706 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -7,11 +7,12 @@ import {
7} from 'sequelize-typescript' 7} from 'sequelize-typescript'
8import { ActivityPubActorType } from '../../../shared/models/activitypub' 8import { ActivityPubActorType } from '../../../shared/models/activitypub'
9import { Avatar } from '../../../shared/models/avatars/avatar.model' 9import { Avatar } from '../../../shared/models/avatars/avatar.model'
10import { activityPubContextify } from '../../helpers' 10import { activityPubContextify } from '../../helpers/activitypub'
11import { 11import {
12 isActivityPubUrlValid, isActorFollowersCountValid, isActorFollowingCountValid, isActorPreferredUsernameValid, 12 isActorFollowersCountValid, isActorFollowingCountValid, isActorPreferredUsernameValid, isActorPrivateKeyValid,
13 isActorPrivateKeyValid, isActorPublicKeyValid 13 isActorPublicKeyValid
14} from '../../helpers/custom-validators/activitypub' 14} from '../../helpers/custom-validators/activitypub/actor'
15import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
15import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 16import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
16import { AccountModel } from '../account/account' 17import { AccountModel } from '../account/account'
17import { AvatarModel } from '../avatar/avatar' 18import { AvatarModel } from '../avatar/avatar'
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index 995fa33d5..9d1b63813 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -1,5 +1,5 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { logger } from '../../helpers' 2import { logger } from '../../helpers/logger'
3import { AccountModel } from '../account/account' 3import { AccountModel } from '../account/account'
4import { UserModel } from '../account/user' 4import { UserModel } from '../account/user'
5import { OAuthClientModel } from './oauth-client' 5import { OAuthClientModel } from './oauth-client'
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
index edfd8010b..d35aa0ca4 100644
--- a/server/models/server/server.ts
+++ b/server/models/server/server.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { AllowNull, Column, CreatedAt, Default, Is, IsInt, Max, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, Column, CreatedAt, Default, Is, IsInt, Max, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { logger } from '../../helpers'
4import { isHostValid } from '../../helpers/custom-validators/servers' 3import { isHostValid } from '../../helpers/custom-validators/servers'
4import { logger } from '../../helpers/logger'
5import { SERVERS_SCORE } from '../../initializers' 5import { SERVERS_SCORE } from '../../initializers'
6import { throwIfNotValid } from '../utils' 6import { throwIfNotValid } from '../utils'
7 7
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 6db562719..3adcec149 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -1,5 +1,5 @@
1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { SortType } from '../../helpers' 2import { SortType } from '../../helpers/utils'
3import { getSortOnModel } from '../utils' 3import { getSortOnModel } from '../utils'
4import { VideoModel } from './video' 4import { VideoModel } from './video'
5 5
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 8ceeb563a..1992c2dd8 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -5,7 +5,7 @@ import {
5} from 'sequelize-typescript' 5} from 'sequelize-typescript'
6import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 6import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
7import { VideoComment } from '../../../shared/models/videos/video-comment.model' 7import { VideoComment } from '../../../shared/models/videos/video-comment.model'
8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' 8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
9import { CONSTRAINTS_FIELDS } from '../../initializers' 9import { CONSTRAINTS_FIELDS } from '../../initializers'
10import { AccountModel } from '../account/account' 10import { AccountModel } from '../account/account'
11import { ActorModel } from '../activitypub/actor' 11import { ActorModel } from '../activitypub/actor'
@@ -16,6 +16,7 @@ import { VideoModel } from './video'
16enum ScopeNames { 16enum ScopeNames {
17 WITH_ACCOUNT = 'WITH_ACCOUNT', 17 WITH_ACCOUNT = 'WITH_ACCOUNT',
18 WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', 18 WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO',
19 WITH_VIDEO = 'WITH_VIDEO',
19 ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API' 20 ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API'
20} 21}
21 22
@@ -56,7 +57,15 @@ enum ScopeNames {
56 include: [ 57 include: [
57 { 58 {
58 model: () => VideoCommentModel, 59 model: () => VideoCommentModel,
59 as: 'InReplyTo' 60 as: 'InReplyToVideoComment'
61 }
62 ]
63 },
64 [ScopeNames.WITH_VIDEO]: {
65 include: [
66 {
67 model: () => VideoModel,
68 required: false
60 } 69 }
61 ] 70 ]
62 } 71 }
@@ -108,7 +117,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
108 foreignKey: { 117 foreignKey: {
109 allowNull: true 118 allowNull: true
110 }, 119 },
111 as: 'InReplyTo', 120 as: 'InReplyToVideoComment',
112 onDelete: 'CASCADE' 121 onDelete: 'CASCADE'
113 }) 122 })
114 InReplyToVideoComment: VideoCommentModel 123 InReplyToVideoComment: VideoCommentModel
@@ -155,6 +164,20 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
155 return VideoCommentModel.findOne(query) 164 return VideoCommentModel.findOne(query)
156 } 165 }
157 166
167 static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Sequelize.Transaction) {
168 const query: IFindOptions<VideoCommentModel> = {
169 where: {
170 id
171 }
172 }
173
174 if (t !== undefined) query.transaction = t
175
176 return VideoCommentModel
177 .scope([ ScopeNames.WITH_VIDEO, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_IN_REPLY_TO ])
178 .findOne(query)
179 }
180
158 static loadByUrl (url: string, t?: Sequelize.Transaction) { 181 static loadByUrl (url: string, t?: Sequelize.Transaction) {
159 const query: IFindOptions<VideoCommentModel> = { 182 const query: IFindOptions<VideoCommentModel> = {
160 where: { 183 where: {
@@ -238,8 +261,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
238 id: this.url, 261 id: this.url,
239 content: this.text, 262 content: this.text,
240 inReplyTo, 263 inReplyTo,
264 updated: this.updatedAt.toISOString(),
241 published: this.createdAt.toISOString(), 265 published: this.createdAt.toISOString(),
242 url: this.url 266 url: this.url,
267 attributedTo: this.Account.Actor.url
243 } 268 }
244 } 269 }
245} 270}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b6a2ce6b5..2504ae58a 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -5,65 +5,25 @@ import * as parseTorrent from 'parse-torrent'
5import { join } from 'path' 5import { join } from 'path'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7import { 7import {
8 AfterDestroy, 8 AfterDestroy, AllowNull, BelongsTo, BelongsToMany, Column, CreatedAt, DataType, Default, ForeignKey, HasMany, IFindOptions, Is,
9 AllowNull, 9 IsInt, IsUUID, Min, Model, Scopes, Table, UpdatedAt
10 BelongsTo,
11 BelongsToMany,
12 Column,
13 CreatedAt,
14 DataType,
15 Default,
16 ForeignKey,
17 HasMany,
18 IFindOptions,
19 Is,
20 IsInt,
21 IsUUID,
22 Min,
23 Model,
24 Scopes,
25 Table,
26 UpdatedAt
27} from 'sequelize-typescript' 10} from 'sequelize-typescript'
28import { IIncludeOptions } from 'sequelize-typescript/lib/interfaces/IIncludeOptions' 11import { IIncludeOptions } from 'sequelize-typescript/lib/interfaces/IIncludeOptions'
29import { VideoPrivacy, VideoResolution } from '../../../shared' 12import { VideoPrivacy, VideoResolution } from '../../../shared'
30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 13import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
31import { Video, VideoDetails } from '../../../shared/models/videos' 14import { Video, VideoDetails } from '../../../shared/models/videos'
15import { activityPubCollection } from '../../helpers/activitypub'
16import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
17import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
32import { 18import {
33 activityPubCollection, 19 isVideoCategoryValid, isVideoDescriptionValid, isVideoDurationValid, isVideoLanguageValid, isVideoLicenceValid, isVideoNameValid,
34 createTorrentPromise, 20 isVideoNSFWValid, isVideoPrivacyValid
35 generateImageFromVideoFile,
36 getVideoFileHeight,
37 logger,
38 renamePromise,
39 statPromise,
40 transcode,
41 unlinkPromise,
42 writeFilePromise
43} from '../../helpers'
44import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
45import {
46 isVideoCategoryValid,
47 isVideoDescriptionValid,
48 isVideoDurationValid,
49 isVideoLanguageValid,
50 isVideoLicenceValid,
51 isVideoNameValid,
52 isVideoNSFWValid,
53 isVideoPrivacyValid
54} from '../../helpers/custom-validators/videos' 21} from '../../helpers/custom-validators/videos'
22import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils'
23import { logger } from '../../helpers/logger'
55import { 24import {
56 API_VERSION, 25 API_VERSION, CONFIG, CONSTRAINTS_FIELDS, PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_PATHS, THUMBNAILS_SIZE, VIDEO_CATEGORIES,
57 CONFIG, 26 VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES
58 CONSTRAINTS_FIELDS,
59 PREVIEWS_SIZE,
60 REMOTE_SCHEME,
61 STATIC_PATHS,
62 THUMBNAILS_SIZE,
63 VIDEO_CATEGORIES,
64 VIDEO_LANGUAGES,
65 VIDEO_LICENCES,
66 VIDEO_PRIVACIES
67} from '../../initializers' 27} from '../../initializers'
68import { getAnnounceActivityPubUrl } from '../../lib/activitypub' 28import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
69import { sendDeleteVideo } from '../../lib/activitypub/send' 29import { sendDeleteVideo } from '../../lib/activitypub/send'
@@ -75,6 +35,7 @@ import { getSort, throwIfNotValid } from '../utils'
75import { TagModel } from './tag' 35import { TagModel } from './tag'
76import { VideoAbuseModel } from './video-abuse' 36import { VideoAbuseModel } from './video-abuse'
77import { VideoChannelModel } from './video-channel' 37import { VideoChannelModel } from './video-channel'
38import { VideoCommentModel } from './video-comment'
78import { VideoFileModel } from './video-file' 39import { VideoFileModel } from './video-file'
79import { VideoShareModel } from './video-share' 40import { VideoShareModel } from './video-share'
80import { VideoTagModel } from './video-tag' 41import { VideoTagModel } from './video-tag'
@@ -85,7 +46,8 @@ enum ScopeNames {
85 WITH_TAGS = 'WITH_TAGS', 46 WITH_TAGS = 'WITH_TAGS',
86 WITH_FILES = 'WITH_FILES', 47 WITH_FILES = 'WITH_FILES',
87 WITH_SHARES = 'WITH_SHARES', 48 WITH_SHARES = 'WITH_SHARES',
88 WITH_RATES = 'WITH_RATES' 49 WITH_RATES = 'WITH_RATES',
50 WITH_COMMENTS = 'WITH_COMMENTS'
89} 51}
90 52
91@Scopes({ 53@Scopes({
@@ -151,6 +113,13 @@ enum ScopeNames {
151 include: [ () => AccountModel ] 113 include: [ () => AccountModel ]
152 } 114 }
153 ] 115 ]
116 },
117 [ScopeNames.WITH_COMMENTS]: {
118 include: [
119 {
120 model: () => VideoCommentModel
121 }
122 ]
154 } 123 }
155}) 124})
156@Table({ 125@Table({
@@ -322,6 +291,15 @@ export class VideoModel extends Model<VideoModel> {
322 }) 291 })
323 AccountVideoRates: AccountVideoRateModel[] 292 AccountVideoRates: AccountVideoRateModel[]
324 293
294 @HasMany(() => VideoCommentModel, {
295 foreignKey: {
296 name: 'videoId',
297 allowNull: false
298 },
299 onDelete: 'cascade'
300 })
301 VideoComments: VideoCommentModel[]
302
325 @AfterDestroy 303 @AfterDestroy
326 static removeFilesAndSendDelete (instance: VideoModel) { 304 static removeFilesAndSendDelete (instance: VideoModel) {
327 const tasks = [] 305 const tasks = []
@@ -417,7 +395,8 @@ export class VideoModel extends Model<VideoModel> {
417 include: [ AccountModel ] 395 include: [ AccountModel ]
418 }, 396 },
419 VideoFileModel, 397 VideoFileModel,
420 TagModel 398 TagModel,
399 VideoCommentModel
421 ] 400 ]
422 } 401 }
423 402
@@ -536,7 +515,7 @@ export class VideoModel extends Model<VideoModel> {
536 } 515 }
537 516
538 return VideoModel 517 return VideoModel
539 .scope([ ScopeNames.WITH_RATES, ScopeNames.WITH_SHARES, ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ]) 518 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
540 .findById(id, options) 519 .findById(id, options)
541 } 520 }
542 521
@@ -561,7 +540,27 @@ export class VideoModel extends Model<VideoModel> {
561 } 540 }
562 541
563 return VideoModel 542 return VideoModel
564 .scope([ ScopeNames.WITH_RATES, ScopeNames.WITH_SHARES, ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ]) 543 .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
544 .findOne(options)
545 }
546
547 static loadAndPopulateAll (id: number) {
548 const options = {
549 order: [ [ 'Tags', 'name', 'ASC' ] ],
550 where: {
551 id
552 }
553 }
554
555 return VideoModel
556 .scope([
557 ScopeNames.WITH_RATES,
558 ScopeNames.WITH_SHARES,
559 ScopeNames.WITH_TAGS,
560 ScopeNames.WITH_FILES,
561 ScopeNames.WITH_ACCOUNT,
562 ScopeNames.WITH_COMMENTS
563 ])
565 .findOne(options) 564 .findOne(options)
566 } 565 }
567 566
@@ -865,6 +864,17 @@ export class VideoModel extends Model<VideoModel> {
865 sharesObject = activityPubCollection(shares) 864 sharesObject = activityPubCollection(shares)
866 } 865 }
867 866
867 let commentsObject
868 if (Array.isArray(this.VideoComments)) {
869 const comments: string[] = []
870
871 for (const videoComment of this.VideoComments) {
872 comments.push(videoComment.url)
873 }
874
875 commentsObject = activityPubCollection(comments)
876 }
877
868 const url = [] 878 const url = []
869 for (const file of this.VideoFiles) { 879 for (const file of this.VideoFiles) {
870 url.push({ 880 url.push({
@@ -925,6 +935,7 @@ export class VideoModel extends Model<VideoModel> {
925 likes: likesObject, 935 likes: likesObject,
926 dislikes: dislikesObject, 936 dislikes: dislikesObject,
927 shares: sharesObject, 937 shares: sharesObject,
938 comments: commentsObject,
928 attributedTo: [ 939 attributedTo: [
929 { 940 {
930 type: 'Group', 941 type: 'Group',