aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts4
-rw-r--r--server/controllers/api/config.ts12
-rw-r--r--server/controllers/api/users/index.ts1
-rw-r--r--server/controllers/api/users/me.ts6
-rw-r--r--server/controllers/api/video-channel.ts6
-rw-r--r--server/controllers/api/videos/import.ts6
-rw-r--r--server/controllers/api/videos/index.ts24
7 files changed, 32 insertions, 27 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 86ef2aed1..a69a83acf 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -74,10 +74,10 @@ async function listVideoAccountChannels (req: express.Request, res: express.Resp
74 74
75async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 75async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
76 const account: AccountModel = res.locals.account 76 const account: AccountModel = res.locals.account
77 const actorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 77 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
78 78
79 const resultList = await VideoModel.listForApi({ 79 const resultList = await VideoModel.listForApi({
80 actorId, 80 followerActorId,
81 start: req.query.start, 81 start: req.query.start,
82 count: req.query.count, 82 count: req.query.count,
83 sort: req.query.sort, 83 sort: req.query.sort,
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 03c1cec7b..d65e321e9 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -10,7 +10,8 @@ import { customConfigUpdateValidator } from '../../middlewares/validators/config
10import { ClientHtml } from '../../lib/client-html' 10import { ClientHtml } from '../../lib/client-html'
11import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' 11import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
12import { remove, writeJSON } from 'fs-extra' 12import { remove, writeJSON } from 'fs-extra'
13import { getVersion } from '../../helpers/utils' 13import { getServerCommit } from '../../helpers/utils'
14import { Emailer } from '../../lib/emailer'
14 15
15const packageJSON = require('../../../../package.json') 16const packageJSON = require('../../../../package.json')
16const configRouter = express.Router() 17const configRouter = express.Router()
@@ -40,11 +41,11 @@ configRouter.delete('/custom',
40) 41)
41 42
42let serverCommit: string 43let serverCommit: string
43async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 44async function getConfig (req: express.Request, res: express.Response) {
44 const allowed = await isSignupAllowed() 45 const allowed = await isSignupAllowed()
45 const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) 46 const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
46 serverCommit = (serverCommit) ? serverCommit : await getVersion() 47
47 if (serverCommit === packageJSON.version) serverCommit = '' 48 if (serverCommit === undefined) serverCommit = await getServerCommit()
48 49
49 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) 50 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
50 .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true) 51 .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
@@ -61,6 +62,9 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
61 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS 62 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
62 } 63 }
63 }, 64 },
65 email: {
66 enabled: Emailer.Instance.isEnabled()
67 },
64 serverVersion: packageJSON.version, 68 serverVersion: packageJSON.version,
65 serverCommit, 69 serverCommit,
66 signup: { 70 signup: {
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 9fcb8077f..87fab4a40 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -262,6 +262,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
262 const roleChanged = body.role !== undefined && body.role !== userToUpdate.role 262 const roleChanged = body.role !== undefined && body.role !== userToUpdate.role
263 263
264 if (body.email !== undefined) userToUpdate.email = body.email 264 if (body.email !== undefined) userToUpdate.email = body.email
265 if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified
265 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota 266 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota
266 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily 267 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
267 if (body.role !== undefined) userToUpdate.role = body.role 268 if (body.role !== undefined) userToUpdate.role = body.role
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 82299747d..d2456346b 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -42,7 +42,7 @@ import { AccountModel } from '../../../models/account/account'
42 42
43const auditLogger = auditLoggerFactory('users-me') 43const auditLogger = auditLoggerFactory('users-me')
44 44
45const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) 45const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
46 46
47const meRouter = express.Router() 47const meRouter = express.Router()
48 48
@@ -238,7 +238,7 @@ async function getUserSubscriptionVideos (req: express.Request, res: express.Res
238 nsfw: buildNSFWFilter(res, req.query.nsfw), 238 nsfw: buildNSFWFilter(res, req.query.nsfw),
239 filter: req.query.filter as VideoFilter, 239 filter: req.query.filter as VideoFilter,
240 withFiles: false, 240 withFiles: false,
241 actorId: user.Account.Actor.id, 241 followerActorId: user.Account.Actor.id,
242 user 242 user
243 }) 243 })
244 244
@@ -348,7 +348,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
348 return res.sendStatus(204) 348 return res.sendStatus(204)
349} 349}
350 350
351async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) { 351async function updateMyAvatar (req: express.Request, res: express.Response) {
352 const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] 352 const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
353 const user: UserModel = res.locals.oauth.token.user 353 const user: UserModel = res.locals.oauth.token.user
354 const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) 354 const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 9bf3c5fd8..fd143a139 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -32,7 +32,7 @@ import { resetSequelizeInstance } from '../../helpers/database-utils'
32import { UserModel } from '../../models/account/user' 32import { UserModel } from '../../models/account/user'
33 33
34const auditLogger = auditLoggerFactory('channels') 34const auditLogger = auditLoggerFactory('channels')
35const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) 35const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
36 36
37const videoChannelRouter = express.Router() 37const videoChannelRouter = express.Router()
38 38
@@ -202,10 +202,10 @@ async function getVideoChannel (req: express.Request, res: express.Response, nex
202 202
203async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 203async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
204 const videoChannelInstance: VideoChannelModel = res.locals.videoChannel 204 const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
205 const actorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 205 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
206 206
207 const resultList = await VideoModel.listForApi({ 207 const resultList = await VideoModel.listForApi({
208 actorId, 208 followerActorId,
209 start: req.query.start, 209 start: req.query.start,
210 count: req.query.count, 210 count: req.query.count,
211 sort: req.query.sort, 211 sort: req.query.sort,
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 398fd5a7f..f27d648c7 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -37,9 +37,9 @@ const reqVideoFileImport = createReqFiles(
37 [ 'thumbnailfile', 'previewfile', 'torrentfile' ], 37 [ 'thumbnailfile', 'previewfile', 'torrentfile' ],
38 Object.assign({}, TORRENT_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT), 38 Object.assign({}, TORRENT_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT),
39 { 39 {
40 thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, 40 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
41 previewfile: CONFIG.STORAGE.PREVIEWS_DIR, 41 previewfile: CONFIG.STORAGE.TMP_DIR,
42 torrentfile: CONFIG.STORAGE.TORRENTS_DIR 42 torrentfile: CONFIG.STORAGE.TMP_DIR
43 } 43 }
44) 44)
45 45
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 89fd0432f..4e4697ef4 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -67,17 +67,17 @@ const reqVideoFileAdd = createReqFiles(
67 [ 'videofile', 'thumbnailfile', 'previewfile' ], 67 [ 'videofile', 'thumbnailfile', 'previewfile' ],
68 Object.assign({}, VIDEO_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT), 68 Object.assign({}, VIDEO_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT),
69 { 69 {
70 videofile: CONFIG.STORAGE.VIDEOS_DIR, 70 videofile: CONFIG.STORAGE.TMP_DIR,
71 thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, 71 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
72 previewfile: CONFIG.STORAGE.PREVIEWS_DIR 72 previewfile: CONFIG.STORAGE.TMP_DIR
73 } 73 }
74) 74)
75const reqVideoFileUpdate = createReqFiles( 75const reqVideoFileUpdate = createReqFiles(
76 [ 'thumbnailfile', 'previewfile' ], 76 [ 'thumbnailfile', 'previewfile' ],
77 IMAGE_MIMETYPE_EXT, 77 IMAGE_MIMETYPE_EXT,
78 { 78 {
79 thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR, 79 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
80 previewfile: CONFIG.STORAGE.PREVIEWS_DIR 80 previewfile: CONFIG.STORAGE.TMP_DIR
81 } 81 }
82) 82)
83 83
@@ -387,6 +387,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
387function getVideo (req: express.Request, res: express.Response) { 387function getVideo (req: express.Request, res: express.Response) {
388 const videoInstance = res.locals.video 388 const videoInstance = res.locals.video
389 389
390 if (videoInstance.isOutdated()) {
391 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } })
392 .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err }))
393 }
394
390 return res.json(videoInstance.toFormattedDetailsJSON()) 395 return res.json(videoInstance.toFormattedDetailsJSON())
391} 396}
392 397
@@ -406,12 +411,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
406 ]) 411 ])
407 412
408 const serverActor = await getServerActor() 413 const serverActor = await getServerActor()
409 414 await sendCreateView(serverActor, videoInstance, undefined)
410 // Send the event to the origin server
411 // If we own the video, we'll send an update event when we'll process the views (in our job queue)
412 if (videoInstance.isOwned() === false) {
413 await sendCreateView(serverActor, videoInstance, undefined)
414 }
415 415
416 return res.status(204).end() 416 return res.status(204).end()
417} 417}
@@ -429,7 +429,7 @@ async function getVideoDescription (req: express.Request, res: express.Response)
429 return res.json({ description }) 429 return res.json({ description })
430} 430}
431 431
432async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 432async function listVideos (req: express.Request, res: express.Response) {
433 const resultList = await VideoModel.listForApi({ 433 const resultList = await VideoModel.listForApi({
434 start: req.query.start, 434 start: req.query.start,
435 count: req.query.count, 435 count: req.query.count,