diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
commit | da854ddd502cd70685ef779c673b9e63757b8aa0 (patch) | |
tree | 21501d170cceaa044a5f23449cbd2eb47fd6415d | |
parent | f40bbe3146553ef45515ee6b6d93ce6028f045ca (diff) | |
download | PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.gz PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.zst PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.zip |
Propagate old comment on new follow
78 files changed, 384 insertions, 305 deletions
diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 4551a4702..3fb5f1972 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { getServerActor } from '../server/helpers' | 1 | import { getServerActor } from '../server/helpers/utils' |
2 | import { initDatabaseModels } from '../server/initializers' | 2 | import { initDatabaseModels } from '../server/initializers' |
3 | import { ActorFollowModel } from '../server/models/activitypub/actor-follow' | 3 | import { ActorFollowModel } from '../server/models/activitypub/actor-follow' |
4 | import { VideoModel } from '../server/models/video/video' | 4 | import { VideoModel } from '../server/models/video/video' |
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 |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' | 3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | ||
4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' | 5 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
5 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' | 6 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' |
6 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' | 7 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' |
7 | import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' | 8 | import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' |
9 | import { videoCommentGetValidator } from '../../middlewares/validators/video-comments' | ||
8 | import { AccountModel } from '../../models/account/account' | 10 | import { AccountModel } from '../../models/account/account' |
9 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 11 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
10 | import { VideoModel } from '../../models/video/video' | 12 | import { VideoModel } from '../../models/video/video' |
11 | import { VideoChannelModel } from '../../models/video/video-channel' | 13 | import { VideoChannelModel } from '../../models/video/video-channel' |
14 | import { VideoCommentModel } from '../../models/video/video-comment' | ||
12 | import { VideoShareModel } from '../../models/video/video-share' | 15 | import { VideoShareModel } from '../../models/video/video-share' |
13 | 16 | ||
14 | const activityPubClientRouter = express.Router() | 17 | const activityPubClientRouter = express.Router() |
@@ -30,7 +33,7 @@ activityPubClientRouter.get('/account/:name/following', | |||
30 | 33 | ||
31 | activityPubClientRouter.get('/videos/watch/:id', | 34 | activityPubClientRouter.get('/videos/watch/:id', |
32 | executeIfActivityPub(asyncMiddleware(videosGetValidator)), | 35 | executeIfActivityPub(asyncMiddleware(videosGetValidator)), |
33 | executeIfActivityPub(videoController) | 36 | executeIfActivityPub(asyncMiddleware(videoController)) |
34 | ) | 37 | ) |
35 | 38 | ||
36 | activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', | 39 | activityPubClientRouter.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 | ||
44 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', | ||
45 | executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)), | ||
46 | executeIfActivityPub(asyncMiddleware(videoCommentController)) | ||
47 | ) | ||
48 | |||
41 | activityPubClientRouter.get('/video-channels/:id', | 49 | activityPubClientRouter.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 { | |||
54 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 62 | function 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 | ||
60 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { | 69 | async 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 | ||
84 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 93 | async 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 | ||
90 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 101 | async 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 | |||
114 | async 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' | 2 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' |
3 | import { logger } from '../../helpers' | ||
4 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | 3 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { processActivities } from '../../lib/activitypub/process/process' | 5 | import { processActivities } from '../../lib/activitypub/process/process' |
6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | 6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' |
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { isSignupAllowed } from '../../helpers/utils' | ||
2 | 3 | ||
3 | import { isSignupAllowed } from '../../helpers' | ||
4 | import { CONFIG } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
5 | import { asyncMiddleware } from '../../middlewares' | 5 | import { asyncMiddleware } from '../../middlewares' |
6 | import { ServerConfig } from '../../../shared' | 6 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | import { badRequest } from '../../helpers/utils' | |
3 | import { badRequest } from '../../helpers' | ||
4 | |||
5 | import { oauthClientsRouter } from './oauth-clients' | ||
6 | import { configRouter } from './config' | 3 | import { configRouter } from './config' |
4 | import { jobsRouter } from './jobs' | ||
5 | import { oauthClientsRouter } from './oauth-clients' | ||
7 | import { serverRouter } from './server' | 6 | import { serverRouter } from './server' |
8 | import { usersRouter } from './users' | 7 | import { usersRouter } from './users' |
9 | import { videosRouter } from './videos' | 8 | import { videosRouter } from './videos' |
10 | import { jobsRouter } from './jobs' | ||
11 | 9 | ||
12 | const apiRouter = express.Router() | 10 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../shared/models/users' | 2 | import { UserRight } from '../../../shared/models/users' |
3 | import { getFormattedObjects } from '../../helpers' | 3 | import { getFormattedObjects } from '../../helpers/utils' |
4 | import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' | 4 | import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' |
5 | import { paginationValidator } from '../../middlewares/validators' | 5 | import { paginationValidator } from '../../middlewares/validators' |
6 | import { JobModel } from '../../models/job/job' | 6 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | import { OAuthClientLocal } from '../../../shared' | |
3 | import { logger } from '../../helpers/logger' | ||
3 | import { CONFIG } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
4 | import { logger } from '../../helpers' | ||
5 | import { asyncMiddleware } from '../../middlewares' | 5 | import { asyncMiddleware } from '../../middlewares' |
6 | import { OAuthClientLocal } from '../../../shared' | ||
7 | import { OAuthClientModel } from '../../models/oauth/oauth-client' | 6 | import { OAuthClientModel } from '../../models/oauth/oauth-client' |
8 | 7 | ||
9 | const oauthClientsRouter = express.Router() | 8 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../../shared/models/users' | 2 | import { UserRight } from '../../../../shared/models/users' |
3 | import { | 3 | import { sanitizeHost } from '../../../helpers/core-utils' |
4 | getFormattedObjects, getServerActor, loadActorUrlOrGetFromWebfinger, logger, retryTransactionWrapper, | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
5 | sanitizeHost | 5 | import { logger } from '../../../helpers/logger' |
6 | } from '../../../helpers' | 6 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
7 | import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' | ||
7 | import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' | 8 | import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' |
8 | import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub' | 9 | import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' |
9 | import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' | 10 | import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' |
10 | import { | 11 | import { |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' | 2 | import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' |
3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' | 3 | import { retryTransactionWrapper } from '../../helpers/database-utils' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { getFormattedObjects } from '../../helpers/utils' | ||
4 | import { CONFIG } from '../../initializers' | 6 | import { CONFIG } from '../../initializers' |
5 | import { createUserAccountAndChannel } from '../../lib/user' | 7 | import { createUserAccountAndChannel } from '../../lib/user' |
6 | import { | 8 | import { |
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' |
25 | import { videosSortValidator } from '../../middlewares/validators' | 13 | import { videosSortValidator } from '../../middlewares/validators' |
26 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 14 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' | 2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' |
3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { getFormattedObjects } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | 7 | import { sendVideoAbuse } from '../../../lib/activitypub/send' |
6 | import { | 8 | import { |
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' |
16 | import { AccountModel } from '../../../models/account/account' | 12 | import { AccountModel } from '../../../models/account/account' |
17 | import { VideoModel } from '../../../models/video/video' | 13 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { logger, getFormattedObjects } from '../../../helpers' | 2 | import { BlacklistedVideo, UserRight } from '../../../../shared' |
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { getFormattedObjects } from '../../../helpers/utils' | ||
3 | import { | 5 | import { |
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' |
14 | import { BlacklistedVideo, UserRight } from '../../../../shared' | ||
15 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 9 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
16 | 10 | ||
17 | const blacklistRouter = express.Router() | 11 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' |
3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { setAsyncActorKeys } from '../../../lib/activitypub' | 7 | import { setAsyncActorKeys } from '../../../lib/activitypub' |
6 | import { createVideoChannel } from '../../../lib/video-channel' | 8 | import { createVideoChannel } from '../../../lib/video-channel' |
7 | import { | 9 | import { |
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' |
20 | import { AccountModel } from '../../../models/account/account' | 14 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 2 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
3 | import { getFormattedObjects, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' | 6 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' |
6 | import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' | 7 | import { 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' | |||
2 | import * as multer from 'multer' | 2 | import * as multer from 'multer' |
3 | import { extname, join } from 'path' | 3 | import { extname, join } from 'path' |
4 | import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' | 4 | import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' |
5 | import { renamePromise } from '../../../helpers/core-utils' | ||
6 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
7 | import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils' | ||
8 | import { logger } from '../../../helpers/logger' | ||
9 | import { generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' | ||
5 | import { | 10 | import { |
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' | ||
14 | import { getServerActor } from '../../../helpers/utils' | ||
15 | import { | ||
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' |
24 | import { | 14 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' |
25 | fetchRemoteVideoDescription, | ||
26 | getVideoActivityPubUrl, | ||
27 | shareVideoByServerAndChannel | ||
28 | } from '../../../lib/activitypub' | ||
29 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' | 15 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' |
30 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' | 16 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' |
31 | import { | 17 | import { |
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' |
44 | import { TagModel } from '../../../models/video/tag' | 21 | import { TagModel } from '../../../models/video/tag' |
45 | import { VideoModel } from '../../../models/video/video' | 22 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserVideoRateUpdate } from '../../../../shared' | 2 | import { UserVideoRateUpdate } from '../../../../shared' |
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
4 | import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' | 5 | import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' |
5 | import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' | 6 | import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' |
6 | import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' | 7 | import { 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
2 | import { join } from 'path' | 3 | import { join } from 'path' |
3 | import * as validator from 'validator' | 4 | import * as validator from 'validator' |
4 | import * as Bluebird from 'bluebird' | 5 | import { escapeHTML, readFileBufferPromise, root } from '../helpers/core-utils' |
5 | import { | 6 | import { 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' | ||
12 | import { root, readFileBufferPromise, escapeHTML } from '../helpers' | ||
13 | import { asyncMiddleware } from '../middlewares' | 7 | import { asyncMiddleware } from '../middlewares' |
14 | import { VideoModel } from '../models/video/video' | 8 | import { 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 | ||
48 | function isRemoteActorValid (remoteActor: any) { | 48 | function 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' | |||
2 | import { isVideoTorrentCreateActivityValid } from './videos' | 2 | import { isVideoTorrentCreateActivityValid } from './videos' |
3 | 3 | ||
4 | function isAnnounceActivityValid (activity: any) { | 4 | function 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 @@ | |||
1 | export * from './actor' | ||
2 | export * from './activity' | ||
3 | export * from './misc' | ||
4 | export * from './signature' | ||
5 | export * from './undo' | ||
6 | export * from './video-channels' | ||
7 | export * from './videos' | ||
8 | export * 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 @@ | |||
1 | export * from './activitypub' | ||
2 | export * from './core-utils' | ||
3 | export * from './logger' | ||
4 | export * from './ffmpeg-utils' | ||
5 | export * from './database-utils' | ||
6 | export * from './peertube-crypto' | ||
7 | export * from './requests' | ||
8 | export * from './utils' | ||
9 | export * 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 @@ | |||
1 | import * as Promise from 'bluebird' | 1 | import * as Promise from 'bluebird' |
2 | import { createWriteStream } from 'fs' | 2 | import { createWriteStream } from 'fs' |
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB } from '../initializers' | ||
5 | |||
6 | function 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 | ||
5 | function 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' | |||
2 | import { WebFingerData } from '../../shared' | 2 | import { WebFingerData } from '../../shared' |
3 | import { ActorModel } from '../models/activitypub/actor' | 3 | import { ActorModel } from '../models/activitypub/actor' |
4 | import { isTestInstance } from './core-utils' | 4 | import { isTestInstance } from './core-utils' |
5 | import { isActivityPubUrlValid } from './custom-validators/activitypub' | 5 | import { isActivityPubUrlValid } from './custom-validators/activitypub/misc' |
6 | 6 | ||
7 | const webfinger = new WebFinger({ | 7 | const 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 @@ | |||
1 | import * as config from 'config' | 1 | import * as config from 'config' |
2 | import { promisify0 } from '../helpers' | 2 | import { promisify0 } from '../helpers/core-utils' |
3 | import { UserModel } from '../models/account/user' | 3 | import { UserModel } from '../models/account/user' |
4 | import { ApplicationModel } from '../models/application/application' | 4 | import { ApplicationModel } from '../models/application/application' |
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 5 | import { 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 @@ | |||
1 | import * as passwordGenerator from 'password-generator' | 1 | import * as passwordGenerator from 'password-generator' |
2 | import { UserRole } from '../../shared' | 2 | import { UserRole } from '../../shared' |
3 | import { logger, mkdirpPromise, rimrafPromise } from '../helpers' | 3 | import { mkdirpPromise, rimrafPromise } from '../helpers/core-utils' |
4 | import { logger } from '../helpers/logger' | ||
4 | import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' | 5 | import { createApplicationActor, createUserAccountAndChannel } from '../lib/user' |
5 | import { UserModel } from '../models/account/user' | 6 | import { UserModel } from '../models/account/user' |
6 | import { ApplicationModel } from '../models/application/application' | 7 | import { 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { DataType } from 'sequelize-typescript' | 2 | import { DataType } from 'sequelize-typescript' |
3 | import { createPrivateAndPublicKeys } from '../../helpers' | 3 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' |
4 | 4 | ||
5 | async function up (utils: { | 5 | async 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 @@ | |||
1 | import * as path from 'path' | 1 | import * as path from 'path' |
2 | import { logger, readdirPromise } from '../helpers' | 2 | import { readdirPromise } from '../helpers/core-utils' |
3 | import { logger } from '../helpers/logger' | ||
3 | import { LAST_MIGRATION_VERSION } from './constants' | 4 | import { LAST_MIGRATION_VERSION } from './constants' |
4 | import { sequelizeTypescript } from './database' | 5 | import { 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' | |||
3 | import * as url from 'url' | 3 | import * as url from 'url' |
4 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' | 4 | import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' |
5 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' | 5 | import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' |
6 | import { createPrivateAndPublicKeys, doRequest, logger, retryTransactionWrapper } from '../../helpers' | 6 | import { isRemoteActorValid } from '../../helpers/custom-validators/activitypub/actor' |
7 | import { isRemoteActorValid } from '../../helpers/custom-validators/activitypub' | 7 | import { retryTransactionWrapper } from '../../helpers/database-utils' |
8 | import { ACTIVITY_PUB, CONFIG, sequelizeTypescript } from '../../initializers' | 8 | import { logger } from '../../helpers/logger' |
9 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' | ||
10 | import { doRequest } from '../../helpers/requests' | ||
11 | import { CONFIG, sequelizeTypescript } from '../../initializers' | ||
9 | import { AccountModel } from '../../models/account/account' | 12 | import { AccountModel } from '../../models/account/account' |
10 | import { ActorModel } from '../../models/activitypub/actor' | 13 | import { ActorModel } from '../../models/activitypub/actor' |
11 | import { ServerModel } from '../../models/server/server' | 14 | import { 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 { | |||
195 | async function fetchActorTotalItems (url: string) { | 191 | async 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 @@ | |||
1 | import * as magnetUtil from 'magnet-uri' | 1 | import * as magnetUtil from 'magnet-uri' |
2 | import { VideoTorrentObject } from '../../../../shared' | 2 | import { VideoTorrentObject } from '../../../../shared' |
3 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | ||
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | 4 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { doRequest } from '../../../helpers' | ||
5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | ||
7 | import { doRequest } from '../../../helpers/requests' | ||
6 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' | 8 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | ||
7 | import { VideoModel } from '../../../models/video/video' | 10 | import { VideoModel } from '../../../models/video/video' |
8 | import { VideoChannelModel } from '../../../models/video/video-channel' | 11 | import { VideoChannelModel } from '../../../models/video/video-channel' |
12 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
9 | import { VideoShareModel } from '../../../models/video/video-share' | 13 | import { VideoShareModel } from '../../../models/video/video-share' |
10 | import { getOrCreateActorAndServerAndModel } from '../actor' | 14 | import { getOrCreateActorAndServerAndModel } from '../actor' |
11 | 15 | ||
@@ -97,14 +101,43 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje | |||
97 | return attributes | 101 | return attributes |
98 | } | 102 | } |
99 | 103 | ||
100 | async function addVideoShares (instance: VideoModel, shares: string[]) { | 104 | async 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 | |||
132 | async 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 | ||
157 | async function addVideoComments (instance: VideoModel, commentUrls: string[]) { | ||
158 | for (const commentUrl of commentUrls) { | ||
159 | await addVideoComment(instance, commentUrl) | ||
160 | } | ||
161 | } | ||
162 | |||
163 | async 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 | ||
126 | export { | 188 | export { |
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 @@ | |||
1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { VideoModel } from '../../../models/video/video' | 6 | import { 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' | |||
3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' | 3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
5 | import { VideoRateType } from '../../../../shared/models/videos' | 5 | import { VideoRateType } from '../../../../shared/models/videos' |
6 | import { logger, retryTransactionWrapper } from '../../../helpers' | 6 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
7 | import { logger } from '../../../helpers/logger' | ||
7 | import { sequelizeTypescript } from '../../../initializers' | 8 | import { sequelizeTypescript } from '../../../initializers' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | 10 | import { ActorModel } from '../../../models/activitypub/actor' |
@@ -15,7 +16,7 @@ import { VideoFileModel } from '../../../models/video/video-file' | |||
15 | import { getOrCreateActorAndServerAndModel } from '../actor' | 16 | import { getOrCreateActorAndServerAndModel } from '../actor' |
16 | import { forwardActivity } from '../send/misc' | 17 | import { forwardActivity } from '../send/misc' |
17 | import { generateThumbnailFromUrl } from '../videos' | 18 | import { generateThumbnailFromUrl } from '../videos' |
18 | import { addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | 19 | import { addVideoComments, addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' |
19 | 20 | ||
20 | async function processCreateActivity (activity: ActivityCreate) { | 21 | async 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 @@ | |||
1 | import { ActivityDelete } from '../../../../shared/models/activitypub' | 1 | import { ActivityDelete } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountModel } from '../../../models/account/account' | 5 | import { AccountModel } from '../../../models/account/account' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 6 | import { 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 @@ | |||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { 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 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { 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 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { AccountModel } from '../../../models/account/account' | 6 | import { AccountModel } from '../../../models/account/account' |
6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 7 | import { 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' | 2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { resetSequelizeInstance } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 7 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { TagModel } from '../../../models/video/tag' | 8 | import { 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 @@ | |||
1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
2 | import { logger } from '../../../helpers' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { processAcceptActivity } from './process-accept' | 4 | import { processAcceptActivity } from './process-accept' |
5 | import { processAnnounceActivity } from './process-announce' | 5 | import { 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' | 2 | import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' |
3 | import { logger } from '../../../helpers' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { ACTIVITY_PUB } from '../../../initializers' | 4 | import { ACTIVITY_PUB } from '../../../initializers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { getServerActor } from '../../../helpers' | 4 | import { getServerActor } from '../../../helpers/utils' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 7 | import { 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { VideoPrivacy } from '../../../shared/models/videos' | 2 | import { VideoPrivacy } from '../../../shared/models/videos' |
3 | import { getServerActor } from '../../helpers' | 3 | import { getServerActor } from '../../helpers/utils' |
4 | import { VideoModel } from '../../models/video/video' | 4 | import { VideoModel } from '../../models/video/video' |
5 | import { VideoShareModel } from '../../models/video/video-share' | 5 | import { VideoShareModel } from '../../models/video/video-share' |
6 | import { sendVideoAnnounceToFollowers } from './send' | 6 | import { 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 | ||
12 | function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) { | 12 | function 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 | ||
16 | function getVideoChannelActivityPubUrl (videoChannelUUID: string) { | 16 | function 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' | |||
2 | import * as request from 'request' | 2 | import * as request from 'request' |
3 | import { Transaction } from 'sequelize' | 3 | import { Transaction } from 'sequelize' |
4 | import { ActivityIconObject } from '../../../shared/index' | 4 | import { ActivityIconObject } from '../../../shared/index' |
5 | import { doRequest, doRequestAndSaveToFile } from '../../helpers' | 5 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' |
6 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers' | 6 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers' |
7 | import { AccountModel } from '../../models/account/account' | 7 | import { AccountModel } from '../../models/account/account' |
8 | import { VideoModel } from '../../models/video/video' | 8 | import { VideoModel } from '../../models/video/video' |
9 | import { | 9 | import { |
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 | ||
20 | function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { | 14 | function 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 @@ | |||
1 | import * as asyncLRU from 'async-lru' | 1 | import * as asyncLRU from 'async-lru' |
2 | import { createWriteStream } from 'fs' | 2 | import { createWriteStream } from 'fs' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { logger, unlinkPromise } from '../../helpers' | 4 | import { unlinkPromise } from '../../helpers/core-utils' |
5 | import { logger } from '../../helpers/logger' | ||
5 | import { CACHE, CONFIG } from '../../initializers' | 6 | import { CACHE, CONFIG } from '../../initializers' |
6 | import { VideoModel } from '../../models/video/video' | 7 | import { VideoModel } from '../../models/video/video' |
7 | import { fetchRemoteVideoPreview } from '../activitypub' | 8 | import { 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 @@ | |||
1 | import { doRequest, logger } from '../../../helpers' | 1 | import { logger } from '../../../helpers/logger' |
2 | import { doRequest } from '../../../helpers/requests' | ||
2 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | 3 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
3 | 4 | ||
4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 5 | async 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 @@ | |||
1 | import { doRequest, logger } from '../../../helpers' | 1 | import { logger } from '../../../helpers/logger' |
2 | import { doRequest } from '../../../helpers/requests' | ||
2 | import { ACTIVITY_PUB } from '../../../initializers' | 3 | import { ACTIVITY_PUB } from '../../../initializers' |
3 | import { processActivities } from '../../activitypub/process' | 4 | import { processActivities } from '../../activitypub/process' |
4 | import { ActivityPubHttpPayload } from './activitypub-http-job-scheduler' | 5 | import { 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 @@ | |||
1 | import { JobCategory } from '../../../../shared' | 1 | import { JobCategory } from '../../../../shared' |
2 | import { buildSignedActivity, getServerActor, logger } from '../../../helpers' | 2 | import { buildSignedActivity } from '../../../helpers/activitypub' |
3 | import { logger } from '../../../helpers/logger' | ||
4 | import { getServerActor } from '../../../helpers/utils' | ||
3 | import { ACTIVITY_PUB } from '../../../initializers' | 5 | import { ACTIVITY_PUB } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 6 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { JobHandler, JobScheduler } from '../job-scheduler' | 7 | import { 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 @@ | |||
1 | import { doRequest, logger } from '../../../helpers' | 1 | import { logger } from '../../../helpers/logger' |
2 | import { doRequest } from '../../../helpers/requests' | ||
2 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' | 3 | import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' |
3 | 4 | ||
4 | async function process (payload: ActivityPubHttpPayload, jobId: number) { | 5 | async 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 @@ | |||
1 | import { AsyncQueue, forever, queue } from 'async' | 1 | import { AsyncQueue, forever, queue } from 'async' |
2 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | import { JobCategory } from '../../../shared' | 3 | import { JobCategory } from '../../../shared' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers/logger' |
5 | import { JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' | 5 | import { JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' |
6 | import { JobModel } from '../../models/job/job' | 6 | import { 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | 2 | import { VideoPrivacy } from '../../../../shared/models/videos' |
3 | import { computeResolutionsToTranscode, logger } from '../../../helpers' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { computeResolutionsToTranscode } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
6 | import { shareVideoByServerAndChannel } from '../../activitypub' | 7 | import { 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 @@ | |||
1 | import { VideoResolution } from '../../../../shared' | 1 | import { VideoResolution } from '../../../../shared' |
2 | import { VideoPrivacy } from '../../../../shared/models/videos' | 2 | import { VideoPrivacy } from '../../../../shared/models/videos' |
3 | import { logger } from '../../../helpers' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { sendUpdateVideo } from '../../activitypub/send' | 5 | import { 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 @@ | |||
1 | import { logger } from '../helpers' | 1 | import { logger } from '../helpers/logger' |
2 | import { UserModel } from '../models/account/user' | 2 | import { UserModel } from '../models/account/user' |
3 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 3 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
4 | import { OAuthTokenModel } from '../models/oauth/oauth-token' | 4 | import { 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 @@ | |||
1 | import { eachSeries } from 'async' | 1 | import { eachSeries } from 'async' |
2 | import { NextFunction, Request, RequestHandler, Response } from 'express' | 2 | import { NextFunction, Request, RequestHandler, Response } from 'express' |
3 | import { ActivityPubSignature } from '../../shared' | 3 | import { ActivityPubSignature } from '../../shared' |
4 | import { isSignatureVerified, logger } from '../helpers' | 4 | import { logger } from '../helpers/logger' |
5 | import { isSignatureVerified } from '../helpers/peertube-crypto' | ||
5 | import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers' | 6 | import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers' |
6 | import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' | 7 | import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' |
7 | import { ActorModel } from '../models/activitypub/actor' | 8 | import { 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 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import * as OAuthServer from 'express-oauth-server' | 3 | import * as OAuthServer from 'express-oauth-server' |
4 | 4 | import { logger } from '../helpers/logger' | |
5 | import { OAUTH_LIFETIME } from '../initializers' | 5 | import { OAUTH_LIFETIME } from '../initializers' |
6 | import { logger } from '../helpers' | ||
7 | 6 | ||
8 | const oAuthServer = new OAuthServer({ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { getHostWithPort } from '../helpers' | 3 | import { getHostWithPort } from '../helpers/utils' |
4 | 4 | ||
5 | function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { | 5 | function 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { SortType } from '../helpers' | 3 | import { SortType } from '../helpers/utils' |
4 | 4 | ||
5 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { | 5 | function 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { UserRight } from '../../shared' | 3 | import { UserRight } from '../../shared' |
4 | import { logger } from '../helpers' | 4 | import { logger } from '../helpers/logger' |
5 | import { UserModel } from '../models/account/user' | 5 | import { UserModel } from '../models/account/user' |
6 | 6 | ||
7 | function ensureUserHasRight (userRight: UserRight) { | 7 | function 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | 6 | ||
7 | const localAccountValidator = [ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator/check' |
3 | import { logger } from '../../../helpers' | 3 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' |
4 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | 6 | ||
7 | const activityPubValidator = [ | 7 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator/check' |
3 | import { logger } from '../../../helpers' | 3 | import { |
4 | import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' | 4 | isSignatureCreatorValid, isSignatureTypeValid, |
5 | isSignatureValueValid | ||
6 | } from '../../../helpers/custom-validators/activitypub/signature' | ||
5 | import { isDateValid } from '../../../helpers/custom-validators/misc' | 7 | import { isDateValid } from '../../../helpers/custom-validators/misc' |
8 | import { logger } from '../../../helpers/logger' | ||
6 | import { areValidationErrors } from '../utils' | 9 | import { areValidationErrors } from '../utils' |
7 | 10 | ||
8 | const signatureValidator = [ | 11 | const 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { getServerActor, isTestInstance, logger } from '../../helpers' | 3 | import { isTestInstance } from '../../helpers/core-utils' |
4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | ||
6 | import { getServerActor } from '../../helpers/utils' | ||
5 | import { CONFIG } from '../../initializers' | 7 | import { CONFIG } from '../../initializers' |
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
7 | import { areValidationErrors } from './utils' | 9 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestInstance, logger } from '../../helpers' | 4 | import { isTestInstance } from '../../helpers/core-utils' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 6 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
7 | import { logger } from '../../helpers/logger' | ||
7 | import { CONFIG } from '../../initializers' | 8 | import { CONFIG } from '../../initializers' |
8 | import { areValidationErrors } from './utils' | 9 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | 5 | ||
6 | const paginationValidator = [ | 6 | const 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 @@ | |||
1 | import { query } from 'express-validator/check' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { logger } from '../../helpers' | 2 | import { query } from 'express-validator/check' |
3 | import { logger } from '../../helpers/logger' | ||
4 | import { SORTABLE_COLUMNS } from '../../initializers' | 4 | import { SORTABLE_COLUMNS } from '../../initializers' |
5 | import { areValidationErrors } from './utils' | 5 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { isSignupAllowed, logger } from '../../helpers' | ||
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { | 5 | import { |
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' |
14 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 9 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
10 | import { logger } from '../../helpers/logger' | ||
11 | import { isSignupAllowed } from '../../helpers/utils' | ||
15 | import { UserModel } from '../../models/account/user' | 12 | import { UserModel } from '../../models/account/user' |
16 | import { areValidationErrors } from './utils' | 13 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { validationResult } from 'express-validator/check' | 2 | import { validationResult } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers/logger' |
4 | 4 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 5 | function 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 4 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
5 | import { logger } from '../../helpers/logger' | ||
6 | import { VideoModel } from '../../models/video/video' | 6 | import { VideoModel } from '../../models/video/video' |
7 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | 7 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' |
8 | import { areValidationErrors } from './utils' | 8 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { logger } from '../../helpers' | ||
5 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' |
6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
7 | import { | 6 | import { |
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' |
10 | import { logger } from '../../helpers/logger' | ||
12 | import { UserModel } from '../../models/account/user' | 11 | import { UserModel } from '../../models/account/user' |
13 | import { VideoChannelModel } from '../../models/video/video-channel' | 12 | import { VideoChannelModel } from '../../models/video/video-channel' |
14 | import { areValidationErrors } from './utils' | 13 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' | 4 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' |
6 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 5 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
6 | import { logger } from '../../helpers/logger' | ||
7 | import { VideoModel } from '../../models/video/video' | 7 | import { VideoModel } from '../../models/video/video' |
8 | import { VideoCommentModel } from '../../models/video/video-comment' | 8 | import { VideoCommentModel } from '../../models/video/video-comment' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [ | |||
66 | } | 66 | } |
67 | ] | 67 | ] |
68 | 68 | ||
69 | const 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 | ||
71 | export { | 86 | export { |
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 | ||
111 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { | 127 | async 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' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { getDurationFromVideoFile, logger } from '../../helpers' | ||
6 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
7 | import { | 6 | import { |
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' |
10 | import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils' | ||
11 | import { logger } from '../../helpers/logger' | ||
21 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 12 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
22 | import { UserModel } from '../../models/account/user' | 13 | import { UserModel } from '../../models/account/user' |
23 | import { VideoModel } from '../../models/video/video' | 14 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { getHostWithPort, logger } from '../../helpers' | ||
4 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' | 3 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { getHostWithPort } from '../../helpers/utils' | ||
5 | import { ActorModel } from '../../models/activitypub/actor' | 6 | import { ActorModel } from '../../models/activitypub/actor' |
6 | import { areValidationErrors } from './utils' | 7 | import { 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' |
6 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' | 6 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' |
7 | import { comparePassword, cryptPassword } from '../../helpers' | ||
8 | import { | 7 | import { |
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' |
11 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | ||
12 | import { OAuthTokenModel } from '../oauth/oauth-token' | 12 | import { OAuthTokenModel } from '../oauth/oauth-token' |
13 | import { getSort, throwIfNotValid } from '../utils' | 13 | import { getSort, throwIfNotValid } from '../utils' |
14 | import { VideoChannelModel } from '../video/video-channel' | 14 | import { 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' |
8 | import { ActivityPubActorType } from '../../../shared/models/activitypub' | 8 | import { ActivityPubActorType } from '../../../shared/models/activitypub' |
9 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | 9 | import { Avatar } from '../../../shared/models/avatars/avatar.model' |
10 | import { activityPubContextify } from '../../helpers' | 10 | import { activityPubContextify } from '../../helpers/activitypub' |
11 | import { | 11 | import { |
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' |
15 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
15 | import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' | 16 | import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' |
16 | import { AccountModel } from '../account/account' | 17 | import { AccountModel } from '../account/account' |
17 | import { AvatarModel } from '../avatar/avatar' | 18 | import { 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 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { logger } from '../../helpers' | 2 | import { logger } from '../../helpers/logger' |
3 | import { AccountModel } from '../account/account' | 3 | import { AccountModel } from '../account/account' |
4 | import { UserModel } from '../account/user' | 4 | import { UserModel } from '../account/user' |
5 | import { OAuthClientModel } from './oauth-client' | 5 | import { 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { AllowNull, Column, CreatedAt, Default, Is, IsInt, Max, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, Column, CreatedAt, Default, Is, IsInt, Max, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { logger } from '../../helpers' | ||
4 | import { isHostValid } from '../../helpers/custom-validators/servers' | 3 | import { isHostValid } from '../../helpers/custom-validators/servers' |
4 | import { logger } from '../../helpers/logger' | ||
5 | import { SERVERS_SCORE } from '../../initializers' | 5 | import { SERVERS_SCORE } from '../../initializers' |
6 | import { throwIfNotValid } from '../utils' | 6 | import { 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 @@ | |||
1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { SortType } from '../../helpers' | 2 | import { SortType } from '../../helpers/utils' |
3 | import { getSortOnModel } from '../utils' | 3 | import { getSortOnModel } from '../utils' |
4 | import { VideoModel } from './video' | 4 | import { 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' |
6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' | 8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
9 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 9 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
10 | import { AccountModel } from '../account/account' | 10 | import { AccountModel } from '../account/account' |
11 | import { ActorModel } from '../activitypub/actor' | 11 | import { ActorModel } from '../activitypub/actor' |
@@ -16,6 +16,7 @@ import { VideoModel } from './video' | |||
16 | enum ScopeNames { | 16 | enum 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' | |||
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import * as Sequelize from 'sequelize' | 6 | import * as Sequelize from 'sequelize' |
7 | import { | 7 | import { |
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' |
28 | import { IIncludeOptions } from 'sequelize-typescript/lib/interfaces/IIncludeOptions' | 11 | import { IIncludeOptions } from 'sequelize-typescript/lib/interfaces/IIncludeOptions' |
29 | import { VideoPrivacy, VideoResolution } from '../../../shared' | 12 | import { VideoPrivacy, VideoResolution } from '../../../shared' |
30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 13 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
31 | import { Video, VideoDetails } from '../../../shared/models/videos' | 14 | import { Video, VideoDetails } from '../../../shared/models/videos' |
15 | import { activityPubCollection } from '../../helpers/activitypub' | ||
16 | import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | ||
17 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
32 | import { | 18 | import { |
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' | ||
44 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' | ||
45 | import { | ||
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' |
22 | import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' | ||
23 | import { logger } from '../../helpers/logger' | ||
55 | import { | 24 | import { |
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' |
68 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub' | 28 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub' |
69 | import { sendDeleteVideo } from '../../lib/activitypub/send' | 29 | import { sendDeleteVideo } from '../../lib/activitypub/send' |
@@ -75,6 +35,7 @@ import { getSort, throwIfNotValid } from '../utils' | |||
75 | import { TagModel } from './tag' | 35 | import { TagModel } from './tag' |
76 | import { VideoAbuseModel } from './video-abuse' | 36 | import { VideoAbuseModel } from './video-abuse' |
77 | import { VideoChannelModel } from './video-channel' | 37 | import { VideoChannelModel } from './video-channel' |
38 | import { VideoCommentModel } from './video-comment' | ||
78 | import { VideoFileModel } from './video-file' | 39 | import { VideoFileModel } from './video-file' |
79 | import { VideoShareModel } from './video-share' | 40 | import { VideoShareModel } from './video-share' |
80 | import { VideoTagModel } from './video-tag' | 41 | import { 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', |
diff --git a/shared/models/activitypub/objects/video-comment-object.ts b/shared/models/activitypub/objects/video-comment-object.ts index fc2a9e837..785fbbc0d 100644 --- a/shared/models/activitypub/objects/video-comment-object.ts +++ b/shared/models/activitypub/objects/video-comment-object.ts | |||
@@ -4,5 +4,7 @@ export interface VideoCommentObject { | |||
4 | content: string | 4 | content: string |
5 | inReplyTo: string | 5 | inReplyTo: string |
6 | published: string | 6 | published: string |
7 | updated: string | ||
7 | url: string | 8 | url: string |
9 | attributedTo: string | ||
8 | } | 10 | } |
diff --git a/shared/models/activitypub/objects/video-torrent-object.ts b/shared/models/activitypub/objects/video-torrent-object.ts index 1405f7748..5ccc80bcb 100644 --- a/shared/models/activitypub/objects/video-torrent-object.ts +++ b/shared/models/activitypub/objects/video-torrent-object.ts | |||
@@ -27,5 +27,6 @@ export interface VideoTorrentObject { | |||
27 | likes?: ActivityPubOrderedCollection<string> | 27 | likes?: ActivityPubOrderedCollection<string> |
28 | dislikes?: ActivityPubOrderedCollection<string> | 28 | dislikes?: ActivityPubOrderedCollection<string> |
29 | shares?: ActivityPubOrderedCollection<string> | 29 | shares?: ActivityPubOrderedCollection<string> |
30 | comments?: ActivityPubOrderedCollection<string> | ||
30 | attributedTo: ActivityPubAttributedTo[] | 31 | attributedTo: ActivityPubAttributedTo[] |
31 | } | 32 | } |