diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/users/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/users/my-notifications.ts | 84 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 14 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 10 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 2 | ||||
-rw-r--r-- | server/controllers/tracker.ts | 4 |
8 files changed, 116 insertions, 6 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index bc24792a2..98be46ea2 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -39,6 +39,7 @@ import { meRouter } from './me' | |||
39 | import { deleteUserToken } from '../../../lib/oauth-model' | 39 | import { deleteUserToken } from '../../../lib/oauth-model' |
40 | import { myBlocklistRouter } from './my-blocklist' | 40 | import { myBlocklistRouter } from './my-blocklist' |
41 | import { myVideosHistoryRouter } from './my-history' | 41 | import { myVideosHistoryRouter } from './my-history' |
42 | import { myNotificationsRouter } from './my-notifications' | ||
42 | 43 | ||
43 | const auditLogger = auditLoggerFactory('users') | 44 | const auditLogger = auditLoggerFactory('users') |
44 | 45 | ||
@@ -55,6 +56,7 @@ const askSendEmailLimiter = new RateLimit({ | |||
55 | }) | 56 | }) |
56 | 57 | ||
57 | const usersRouter = express.Router() | 58 | const usersRouter = express.Router() |
59 | usersRouter.use('/', myNotificationsRouter) | ||
58 | usersRouter.use('/', myBlocklistRouter) | 60 | usersRouter.use('/', myBlocklistRouter) |
59 | usersRouter.use('/', myVideosHistoryRouter) | 61 | usersRouter.use('/', myVideosHistoryRouter) |
60 | usersRouter.use('/', meRouter) | 62 | usersRouter.use('/', meRouter) |
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts new file mode 100644 index 000000000..cef1d237c --- /dev/null +++ b/server/controllers/api/users/my-notifications.ts | |||
@@ -0,0 +1,84 @@ | |||
1 | import * as express from 'express' | ||
2 | import 'multer' | ||
3 | import { | ||
4 | asyncMiddleware, | ||
5 | asyncRetryTransactionMiddleware, | ||
6 | authenticate, | ||
7 | paginationValidator, | ||
8 | setDefaultPagination, | ||
9 | setDefaultSort, | ||
10 | userNotificationsSortValidator | ||
11 | } from '../../../middlewares' | ||
12 | import { UserModel } from '../../../models/account/user' | ||
13 | import { getFormattedObjects } from '../../../helpers/utils' | ||
14 | import { UserNotificationModel } from '../../../models/account/user-notification' | ||
15 | import { meRouter } from './me' | ||
16 | import { | ||
17 | markAsReadUserNotificationsValidator, | ||
18 | updateNotificationSettingsValidator | ||
19 | } from '../../../middlewares/validators/user-notifications' | ||
20 | import { UserNotificationSetting } from '../../../../shared/models/users' | ||
21 | import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting' | ||
22 | |||
23 | const myNotificationsRouter = express.Router() | ||
24 | |||
25 | meRouter.put('/me/notification-settings', | ||
26 | authenticate, | ||
27 | updateNotificationSettingsValidator, | ||
28 | asyncRetryTransactionMiddleware(updateNotificationSettings) | ||
29 | ) | ||
30 | |||
31 | myNotificationsRouter.get('/me/notifications', | ||
32 | authenticate, | ||
33 | paginationValidator, | ||
34 | userNotificationsSortValidator, | ||
35 | setDefaultSort, | ||
36 | setDefaultPagination, | ||
37 | asyncMiddleware(listUserNotifications) | ||
38 | ) | ||
39 | |||
40 | myNotificationsRouter.post('/me/notifications/read', | ||
41 | authenticate, | ||
42 | markAsReadUserNotificationsValidator, | ||
43 | asyncMiddleware(markAsReadUserNotifications) | ||
44 | ) | ||
45 | |||
46 | export { | ||
47 | myNotificationsRouter | ||
48 | } | ||
49 | |||
50 | // --------------------------------------------------------------------------- | ||
51 | |||
52 | async function updateNotificationSettings (req: express.Request, res: express.Response) { | ||
53 | const user: UserModel = res.locals.oauth.token.User | ||
54 | const body: UserNotificationSetting = req.body | ||
55 | |||
56 | const query = { | ||
57 | where: { | ||
58 | userId: user.id | ||
59 | } | ||
60 | } | ||
61 | |||
62 | await UserNotificationSettingModel.update({ | ||
63 | newVideoFromSubscription: body.newVideoFromSubscription, | ||
64 | newCommentOnMyVideo: body.newCommentOnMyVideo | ||
65 | }, query) | ||
66 | |||
67 | return res.status(204).end() | ||
68 | } | ||
69 | |||
70 | async function listUserNotifications (req: express.Request, res: express.Response) { | ||
71 | const user: UserModel = res.locals.oauth.token.User | ||
72 | |||
73 | const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort) | ||
74 | |||
75 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
76 | } | ||
77 | |||
78 | async function markAsReadUserNotifications (req: express.Request, res: express.Response) { | ||
79 | const user: UserModel = res.locals.oauth.token.User | ||
80 | |||
81 | await UserNotificationModel.markAsRead(user.id, req.body.ids) | ||
82 | |||
83 | return res.status(204).end() | ||
84 | } | ||
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index d0c81804b..fe0a95cd5 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -22,6 +22,7 @@ import { VideoModel } from '../../../models/video/video' | |||
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
24 | import { UserModel } from '../../../models/account/user' | 24 | import { UserModel } from '../../../models/account/user' |
25 | import { Notifier } from '../../../lib/notifier' | ||
25 | 26 | ||
26 | const auditLogger = auditLoggerFactory('abuse') | 27 | const auditLogger = auditLoggerFactory('abuse') |
27 | const abuseVideoRouter = express.Router() | 28 | const abuseVideoRouter = express.Router() |
@@ -117,6 +118,8 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
117 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance) | 118 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance) |
118 | } | 119 | } |
119 | 120 | ||
121 | Notifier.Instance.notifyOnNewVideoAbuse(videoAbuseInstance) | ||
122 | |||
120 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) | 123 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) |
121 | 124 | ||
122 | return videoAbuseInstance | 125 | return videoAbuseInstance |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 7f803c8e9..9ef08812b 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -16,6 +16,8 @@ import { | |||
16 | } from '../../../middlewares' | 16 | } from '../../../middlewares' |
17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 17 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
18 | import { sequelizeTypescript } from '../../../initializers' | 18 | import { sequelizeTypescript } from '../../../initializers' |
19 | import { Notifier } from '../../../lib/notifier' | ||
20 | import { VideoModel } from '../../../models/video/video' | ||
19 | 21 | ||
20 | const blacklistRouter = express.Router() | 22 | const blacklistRouter = express.Router() |
21 | 23 | ||
@@ -67,13 +69,18 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
67 | reason: body.reason | 69 | reason: body.reason |
68 | } | 70 | } |
69 | 71 | ||
70 | await VideoBlacklistModel.create(toCreate) | 72 | const blacklist = await VideoBlacklistModel.create(toCreate) |
73 | blacklist.Video = videoInstance | ||
74 | |||
75 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | ||
76 | |||
77 | logger.info('Video %s blacklisted.', res.locals.video.uuid) | ||
78 | |||
71 | return res.type('json').status(204).end() | 79 | return res.type('json').status(204).end() |
72 | } | 80 | } |
73 | 81 | ||
74 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | 82 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { |
75 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 83 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel |
76 | logger.info(videoBlacklist) | ||
77 | 84 | ||
78 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason | 85 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason |
79 | 86 | ||
@@ -92,11 +99,14 @@ async function listBlacklist (req: express.Request, res: express.Response, next: | |||
92 | 99 | ||
93 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | 100 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { |
94 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 101 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel |
102 | const video: VideoModel = res.locals.video | ||
95 | 103 | ||
96 | await sequelizeTypescript.transaction(t => { | 104 | await sequelizeTypescript.transaction(t => { |
97 | return videoBlacklist.destroy({ transaction: t }) | 105 | return videoBlacklist.destroy({ transaction: t }) |
98 | }) | 106 | }) |
99 | 107 | ||
108 | Notifier.Instance.notifyOnVideoUnblacklist(video) | ||
109 | |||
100 | logger.info('Video %s removed from blacklist.', res.locals.video.uuid) | 110 | logger.info('Video %s removed from blacklist.', res.locals.video.uuid) |
101 | 111 | ||
102 | return res.type('json').status(204).end() | 112 | return res.type('json').status(204).end() |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 3875c8f79..70c1148ba 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -26,6 +26,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' | |||
26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
27 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
28 | import { UserModel } from '../../../models/account/user' | 28 | import { UserModel } from '../../../models/account/user' |
29 | import { Notifier } from '../../../lib/notifier' | ||
29 | 30 | ||
30 | const auditLogger = auditLoggerFactory('comments') | 31 | const auditLogger = auditLoggerFactory('comments') |
31 | const videoCommentRouter = express.Router() | 32 | const videoCommentRouter = express.Router() |
@@ -119,6 +120,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
119 | }, t) | 120 | }, t) |
120 | }) | 121 | }) |
121 | 122 | ||
123 | Notifier.Instance.notifyOnNewComment(comment) | ||
122 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 124 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
123 | 125 | ||
124 | return res.json({ | 126 | return res.json({ |
@@ -140,6 +142,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
140 | }, t) | 142 | }, t) |
141 | }) | 143 | }) |
142 | 144 | ||
145 | Notifier.Instance.notifyOnNewComment(comment) | ||
143 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 146 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
144 | 147 | ||
145 | return res.json({ comment: comment.toFormattedJSON() }).end() | 148 | return res.json({ comment: comment.toFormattedJSON() }).end() |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 00a1302d1..94ed08fed 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -7,7 +7,8 @@ import { logger } from '../../../helpers/logger' | |||
7 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 7 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
8 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' | 8 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
9 | import { | 9 | import { |
10 | CONFIG, MIMETYPES, | 10 | CONFIG, |
11 | MIMETYPES, | ||
11 | PREVIEWS_SIZE, | 12 | PREVIEWS_SIZE, |
12 | sequelizeTypescript, | 13 | sequelizeTypescript, |
13 | THUMBNAILS_SIZE, | 14 | THUMBNAILS_SIZE, |
@@ -57,6 +58,7 @@ import { videoImportsRouter } from './import' | |||
57 | import { resetSequelizeInstance } from '../../../helpers/database-utils' | 58 | import { resetSequelizeInstance } from '../../../helpers/database-utils' |
58 | import { move } from 'fs-extra' | 59 | import { move } from 'fs-extra' |
59 | import { watchingRouter } from './watching' | 60 | import { watchingRouter } from './watching' |
61 | import { Notifier } from '../../../lib/notifier' | ||
60 | 62 | ||
61 | const auditLogger = auditLoggerFactory('videos') | 63 | const auditLogger = auditLoggerFactory('videos') |
62 | const videosRouter = express.Router() | 64 | const videosRouter = express.Router() |
@@ -262,6 +264,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
262 | } | 264 | } |
263 | 265 | ||
264 | await federateVideoIfNeeded(video, true, t) | 266 | await federateVideoIfNeeded(video, true, t) |
267 | Notifier.Instance.notifyOnNewVideo(video) | ||
265 | 268 | ||
266 | auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) | 269 | auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) |
267 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) | 270 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) |
@@ -293,6 +296,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
293 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | 296 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) |
294 | const videoInfoToUpdate: VideoUpdate = req.body | 297 | const videoInfoToUpdate: VideoUpdate = req.body |
295 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE | 298 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE |
299 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED | ||
296 | 300 | ||
297 | // Process thumbnail or create it from the video | 301 | // Process thumbnail or create it from the video |
298 | if (req.files && req.files['thumbnailfile']) { | 302 | if (req.files && req.files['thumbnailfile']) { |
@@ -363,6 +367,10 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
363 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE | 367 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE |
364 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | 368 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) |
365 | 369 | ||
370 | if (wasUnlistedVideo || wasPrivateVideo) { | ||
371 | Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated) | ||
372 | } | ||
373 | |||
366 | auditLogger.update( | 374 | auditLogger.update( |
367 | getAuditIdFromRes(res), | 375 | getAuditIdFromRes(res), |
368 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), | 376 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), |
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index ccb9b6029..960085af1 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -56,7 +56,7 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res | |||
56 | 56 | ||
57 | // Adding video items to the feed, one at a time | 57 | // Adding video items to the feed, one at a time |
58 | comments.forEach(comment => { | 58 | comments.forEach(comment => { |
59 | const link = CONFIG.WEBSERVER.URL + '/videos/watch/' + comment.Video.uuid + ';threadId=' + comment.getThreadId() | 59 | const link = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() |
60 | 60 | ||
61 | feed.addItem({ | 61 | feed.addItem({ |
62 | title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`, | 62 | title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`, |
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts index 9bc7586d1..53f1653b5 100644 --- a/server/controllers/tracker.ts +++ b/server/controllers/tracker.ts | |||
@@ -59,7 +59,7 @@ const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) | |||
59 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) | 59 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) |
60 | trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' })) | 60 | trackerRouter.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' })) |
61 | 61 | ||
62 | function createWebsocketServer (app: express.Application) { | 62 | function createWebsocketTrackerServer (app: express.Application) { |
63 | const server = http.createServer(app) | 63 | const server = http.createServer(app) |
64 | const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) | 64 | const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) |
65 | wss.on('connection', function (ws, req) { | 65 | wss.on('connection', function (ws, req) { |
@@ -76,7 +76,7 @@ function createWebsocketServer (app: express.Application) { | |||
76 | 76 | ||
77 | export { | 77 | export { |
78 | trackerRouter, | 78 | trackerRouter, |
79 | createWebsocketServer | 79 | createWebsocketTrackerServer |
80 | } | 80 | } |
81 | 81 | ||
82 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |