From da854ddd502cd70685ef779c673b9e63757b8aa0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 11:16:08 +0100 Subject: Propagate old comment on new follow --- server/controllers/activitypub/client.ts | 27 ++++++++++++++++---- server/controllers/activitypub/inbox.ts | 2 +- server/controllers/api/config.ts | 2 +- server/controllers/api/index.ts | 8 +++--- server/controllers/api/jobs.ts | 2 +- server/controllers/api/oauth-clients.ts | 5 ++-- server/controllers/api/server/follows.ts | 11 ++++---- server/controllers/api/users.ts | 24 +++++------------ server/controllers/api/videos/abuse.ts | 14 ++++------ server/controllers/api/videos/blacklist.ts | 16 ++++-------- server/controllers/api/videos/channel.ts | 16 ++++-------- server/controllers/api/videos/comment.ts | 3 ++- server/controllers/api/videos/index.ts | 41 +++++++----------------------- server/controllers/api/videos/rate.ts | 3 ++- server/controllers/client.ts | 12 +++------ 15 files changed, 73 insertions(+), 113 deletions(-) (limited to 'server/controllers') 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 @@ // Intercept ActivityPub client requests import * as express from 'express' -import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' +import { activityPubCollectionPagination } from '../../helpers/activitypub' +import { pageToStartAndCount } from '../../helpers/core-utils' import { ACTIVITY_PUB, CONFIG } from '../../initializers' import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' +import { videoCommentGetValidator } from '../../middlewares/validators/video-comments' import { AccountModel } from '../../models/account/account' import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { VideoModel } from '../../models/video/video' import { VideoChannelModel } from '../../models/video/video-channel' +import { VideoCommentModel } from '../../models/video/video-comment' import { VideoShareModel } from '../../models/video/video-share' const activityPubClientRouter = express.Router() @@ -30,7 +33,7 @@ activityPubClientRouter.get('/account/:name/following', activityPubClientRouter.get('/videos/watch/:id', executeIfActivityPub(asyncMiddleware(videosGetValidator)), - executeIfActivityPub(videoController) + executeIfActivityPub(asyncMiddleware(videoController)) ) activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', @@ -38,6 +41,11 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', executeIfActivityPub(asyncMiddleware(videoAnnounceController)) ) +activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', + executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)), + executeIfActivityPub(asyncMiddleware(videoCommentController)) +) + activityPubClientRouter.get('/video-channels/:id', executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)), executeIfActivityPub(asyncMiddleware(videoChannelController)) @@ -54,7 +62,8 @@ export { function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { const account: AccountModel = res.locals.account - return res.json(account.toActivityPubObject()).end() + return res.json(account.toActivityPubObject()) + .end() } 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 return res.json(activityPubResult) } -function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { const video: VideoModel = res.locals.video - return res.json(video.toActivityPubObject()) + // We need more attributes + const videoAll = await VideoModel.loadAndPopulateAll(video.id) + return res.json(videoAll.toActivityPubObject()) } 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 return res.json(videoChannel.toActivityPubObject()) } + +async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { + const videoComment: VideoCommentModel = res.locals.videoComment + + return res.json(videoComment.toActivityPubObject()) +} 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 @@ import * as express from 'express' import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' -import { logger } from '../../helpers' import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' +import { logger } from '../../helpers/logger' import { processActivities } from '../../lib/activitypub/process/process' import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' 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 @@ import * as express from 'express' +import { isSignupAllowed } from '../../helpers/utils' -import { isSignupAllowed } from '../../helpers' import { CONFIG } from '../../initializers' import { asyncMiddleware } from '../../middlewares' 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 @@ import * as express from 'express' - -import { badRequest } from '../../helpers' - -import { oauthClientsRouter } from './oauth-clients' +import { badRequest } from '../../helpers/utils' import { configRouter } from './config' +import { jobsRouter } from './jobs' +import { oauthClientsRouter } from './oauth-clients' import { serverRouter } from './server' import { usersRouter } from './users' import { videosRouter } from './videos' -import { jobsRouter } from './jobs' const apiRouter = express.Router() 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 @@ import * as express from 'express' import { UserRight } from '../../../shared/models/users' -import { getFormattedObjects } from '../../helpers' +import { getFormattedObjects } from '../../helpers/utils' import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' import { paginationValidator } from '../../middlewares/validators' 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 @@ import * as express from 'express' - +import { OAuthClientLocal } from '../../../shared' +import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers' -import { logger } from '../../helpers' import { asyncMiddleware } from '../../middlewares' -import { OAuthClientLocal } from '../../../shared' import { OAuthClientModel } from '../../models/oauth/oauth-client' 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 @@ import * as express from 'express' import { UserRight } from '../../../../shared/models/users' -import { - getFormattedObjects, getServerActor, loadActorUrlOrGetFromWebfinger, logger, retryTransactionWrapper, - sanitizeHost -} from '../../../helpers' +import { sanitizeHost } from '../../../helpers/core-utils' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { logger } from '../../../helpers/logger' +import { getFormattedObjects, getServerActor } from '../../../helpers/utils' +import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' -import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub' +import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' import { 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 @@ import * as express from 'express' import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' -import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' +import { retryTransactionWrapper } from '../../helpers/database-utils' +import { logger } from '../../helpers/logger' +import { getFormattedObjects } from '../../helpers/utils' import { CONFIG } from '../../initializers' import { createUserAccountAndChannel } from '../../lib/user' import { - asyncMiddleware, - authenticate, - ensureUserHasRight, - ensureUserRegistrationAllowed, - paginationValidator, - setPagination, - setUsersSort, - setVideosSort, - token, - usersAddValidator, - usersGetValidator, - usersRegisterValidator, - usersRemoveValidator, - usersSortValidator, - usersUpdateMeValidator, - usersUpdateValidator, - usersVideoRatingValidator + asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort, + setVideosSort, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, + usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator } from '../../middlewares' import { videosSortValidator } from '../../middlewares/validators' 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 @@ import * as express from 'express' import { UserRight, VideoAbuseCreate } from '../../../../shared' -import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { logger } from '../../../helpers/logger' +import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' import { sendVideoAbuse } from '../../../lib/activitypub/send' import { - asyncMiddleware, - authenticate, - ensureUserHasRight, - paginationValidator, - setPagination, - setVideoAbusesSort, - videoAbuseReportValidator, - videoAbusesSortValidator + asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setPagination, setVideoAbusesSort, + videoAbuseReportValidator, videoAbusesSortValidator } from '../../../middlewares' import { AccountModel } from '../../../models/account/account' 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 @@ import * as express from 'express' -import { logger, getFormattedObjects } from '../../../helpers' +import { BlacklistedVideo, UserRight } from '../../../../shared' +import { logger } from '../../../helpers/logger' +import { getFormattedObjects } from '../../../helpers/utils' import { - authenticate, - ensureUserHasRight, - videosBlacklistAddValidator, - videosBlacklistRemoveValidator, - paginationValidator, - blacklistSortValidator, - setBlacklistSort, - setPagination, - asyncMiddleware + asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setPagination, + videosBlacklistAddValidator, videosBlacklistRemoveValidator } from '../../../middlewares' -import { BlacklistedVideo, UserRight } from '../../../../shared' import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 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 @@ import * as express from 'express' import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' -import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { logger } from '../../../helpers/logger' +import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' import { setAsyncActorKeys } from '../../../lib/activitypub' import { createVideoChannel } from '../../../lib/video-channel' import { - asyncMiddleware, - authenticate, - listVideoAccountChannelsValidator, - paginationValidator, - setPagination, - setVideoChannelsSort, - videoChannelsAddValidator, - videoChannelsGetValidator, - videoChannelsRemoveValidator, - videoChannelsSortValidator, + asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setPagination, setVideoChannelsSort, + videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, videoChannelsUpdateValidator } from '../../../middlewares' 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 @@ import * as express from 'express' import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' -import { getFormattedObjects, retryTransactionWrapper } from '../../../helpers' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' 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' import * as multer from 'multer' import { extname, join } from 'path' import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' +import { renamePromise } from '../../../helpers/core-utils' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils' +import { logger } from '../../../helpers/logger' +import { generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' import { - generateRandomString, - getFormattedObjects, - getVideoFileHeight, - logger, - renamePromise, - resetSequelizeInstance, - retryTransactionWrapper -} from '../../../helpers' -import { getServerActor } from '../../../helpers/utils' -import { - CONFIG, - sequelizeTypescript, - VIDEO_CATEGORIES, - VIDEO_LANGUAGES, - VIDEO_LICENCES, - VIDEO_MIMETYPE_EXT, + CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' -import { - fetchRemoteVideoDescription, - getVideoActivityPubUrl, - shareVideoByServerAndChannel -} from '../../../lib/activitypub' +import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' import { - asyncMiddleware, - authenticate, - paginationValidator, - setPagination, - setVideosSort, - videosAddValidator, - videosGetValidator, - videosRemoveValidator, - videosSearchValidator, - videosSortValidator, - videosUpdateValidator + asyncMiddleware, authenticate, paginationValidator, setPagination, setVideosSort, videosAddValidator, videosGetValidator, + videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator } from '../../../middlewares' import { TagModel } from '../../../models/video/tag' 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 @@ import * as express from 'express' import { UserVideoRateUpdate } from '../../../../shared' -import { logger, retryTransactionWrapper } from '../../../helpers' +import { retryTransactionWrapper } from '../../../helpers/database-utils' +import { logger } from '../../../helpers/logger' import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' import { sendVideoRateChangeToFollowers, sendVideoRateChangeToOrigin } from '../../../lib/activitypub' 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 @@ +import * as Bluebird from 'bluebird' import * as express from 'express' import { join } from 'path' import * as validator from 'validator' -import * as Bluebird from 'bluebird' -import { - CONFIG, - STATIC_PATHS, - STATIC_MAX_AGE, - OPENGRAPH_AND_OEMBED_COMMENT, - EMBED_SIZE -} from '../initializers' -import { root, readFileBufferPromise, escapeHTML } from '../helpers' +import { escapeHTML, readFileBufferPromise, root } from '../helpers/core-utils' +import { CONFIG, EMBED_SIZE, OPENGRAPH_AND_OEMBED_COMMENT, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers' import { asyncMiddleware } from '../middlewares' import { VideoModel } from '../models/video/video' -- cgit v1.2.3