aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-20 19:05:31 +0200
committerChocobozzz <me@florianbigard.com>2019-08-20 19:23:10 +0200
commit1ca9f7c3f7afac2af4c4c25b98426731f7e789c6 (patch)
tree27fe65c4ea5e9250d2523033d5c65b315bfca23d /server/controllers/api
parent0283eaac2a8e73006c66df3cf5bb9012e37450e5 (diff)
downloadPeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.gz
PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.zst
PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.zip
Type toFormattedJSON
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/index.ts2
-rw-r--r--server/controllers/api/users/me.ts11
-rw-r--r--server/controllers/api/video-channel.ts4
-rw-r--r--server/controllers/api/videos/import.ts10
4 files changed, 8 insertions, 19 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index e6b678f3a..27351c1a9 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -196,7 +196,7 @@ async function createUser (req: express.Request, res: express.Response) {
196 videoQuota: body.videoQuota, 196 videoQuota: body.videoQuota,
197 videoQuotaDaily: body.videoQuotaDaily, 197 videoQuotaDaily: body.videoQuotaDaily,
198 adminFlags: body.adminFlags || UserAdminFlag.NONE 198 adminFlags: body.adminFlags || UserAdminFlag.NONE
199 }) 199 }) as MUser
200 200
201 const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate }) 201 const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })
202 202
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index af054f620..78e1e7fa3 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -23,15 +23,12 @@ import { createReqFiles } from '../../../helpers/express-utils'
23import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' 23import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
24import { updateAvatarValidator } from '../../../middlewares/validators/avatar' 24import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
25import { updateActorAvatarFile } from '../../../lib/avatar' 25import { updateActorAvatarFile } from '../../../lib/avatar'
26import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
27import { VideoImportModel } from '../../../models/video/video-import' 26import { VideoImportModel } from '../../../models/video/video-import'
28import { AccountModel } from '../../../models/account/account' 27import { AccountModel } from '../../../models/account/account'
29import { CONFIG } from '../../../initializers/config' 28import { CONFIG } from '../../../initializers/config'
30import { sequelizeTypescript } from '../../../initializers/database' 29import { sequelizeTypescript } from '../../../initializers/database'
31import { sendVerifyUserEmail } from '../../../lib/user' 30import { sendVerifyUserEmail } from '../../../lib/user'
32 31
33const auditLogger = auditLoggerFactory('users-me')
34
35const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 32const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
36 33
37const meRouter = express.Router() 34const meRouter = express.Router()
@@ -165,8 +162,6 @@ async function deleteMe (req: express.Request, res: express.Response) {
165 162
166 await user.destroy() 163 await user.destroy()
167 164
168 auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})))
169
170 return res.sendStatus(204) 165 return res.sendStatus(204)
171} 166}
172 167
@@ -175,7 +170,6 @@ async function updateMe (req: express.Request, res: express.Response) {
175 let sendVerificationEmail = false 170 let sendVerificationEmail = false
176 171
177 const user = res.locals.oauth.token.user 172 const user = res.locals.oauth.token.user
178 const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
179 173
180 if (body.password !== undefined) user.password = body.password 174 if (body.password !== undefined) user.password = body.password
181 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy 175 if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
@@ -204,8 +198,6 @@ async function updateMe (req: express.Request, res: express.Response) {
204 await userAccount.save({ transaction: t }) 198 await userAccount.save({ transaction: t })
205 199
206 await sendUpdateActor(userAccount, t) 200 await sendUpdateActor(userAccount, t)
207
208 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
209 }) 201 })
210 202
211 if (sendVerificationEmail === true) { 203 if (sendVerificationEmail === true) {
@@ -218,13 +210,10 @@ async function updateMe (req: express.Request, res: express.Response) {
218async function updateMyAvatar (req: express.Request, res: express.Response) { 210async function updateMyAvatar (req: express.Request, res: express.Response) {
219 const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] 211 const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
220 const user = res.locals.oauth.token.user 212 const user = res.locals.oauth.token.user
221 const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
222 213
223 const userAccount = await AccountModel.load(user.Account.id) 214 const userAccount = await AccountModel.load(user.Account.id)
224 215
225 const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) 216 const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount)
226 217
227 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
228
229 return res.json({ avatar: avatar.toFormattedJSON() }) 218 return res.json({ avatar: avatar.toFormattedJSON() })
230} 219}
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 2b6184a83..d4ca7a0af 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel'
19import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' 19import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
20import { sendUpdateActor } from '../../lib/activitypub/send' 20import { sendUpdateActor } from '../../lib/activitypub/send'
21import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' 21import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
22import { createVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' 22import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
23import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 23import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
24import { setAsyncActorKeys } from '../../lib/activitypub' 24import { setAsyncActorKeys } from '../../lib/activitypub'
25import { AccountModel } from '../../models/account/account' 25import { AccountModel } from '../../models/account/account'
@@ -139,7 +139,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) {
139 const videoChannelCreated = await sequelizeTypescript.transaction(async t => { 139 const videoChannelCreated = await sequelizeTypescript.transaction(async t => {
140 const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) 140 const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
141 141
142 return createVideoChannel(videoChannelInfo, account, t) 142 return createLocalVideoChannel(videoChannelInfo, account, t)
143 }) 143 })
144 144
145 setAsyncActorKeys(videoChannelCreated.Actor) 145 setAsyncActorKeys(videoChannelCreated.Actor)
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index e7adcc35a..8879f3442 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as magnetUtil from 'magnet-uri' 2import * as magnetUtil from 'magnet-uri'
3import 'multer'
4import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 3import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
5import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' 4import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
6import { MIMETYPES } from '../../../initializers/constants' 5import { MIMETYPES } from '../../../initializers/constants'
@@ -28,11 +27,12 @@ import {
28 MChannelAccountDefault, 27 MChannelAccountDefault,
29 MThumbnail, 28 MThumbnail,
30 MUser, 29 MUser,
30 MVideoAccountDefault,
31 MVideoTag, 31 MVideoTag,
32 MVideoThumbnailAccountDefault, 32 MVideoThumbnailAccountDefault,
33 MVideoWithBlacklistLight 33 MVideoWithBlacklistLight
34} from '@server/typings/models' 34} from '@server/typings/models'
35import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' 35import { MVideoImport, MVideoImportFormattable } from '@server/typings/models/video/video-import'
36 36
37const auditLogger = auditLoggerFactory('video-imports') 37const auditLogger = auditLoggerFactory('video-imports')
38const videoImportsRouter = express.Router() 38const videoImportsRouter = express.Router()
@@ -238,14 +238,14 @@ function insertIntoDB (parameters: {
238 tags: string[], 238 tags: string[],
239 videoImportAttributes: Partial<MVideoImport>, 239 videoImportAttributes: Partial<MVideoImport>,
240 user: MUser 240 user: MUser
241}): Bluebird<MVideoImportVideo> { 241}): Bluebird<MVideoImportFormattable> {
242 const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters 242 const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
243 243
244 return sequelizeTypescript.transaction(async t => { 244 return sequelizeTypescript.transaction(async t => {
245 const sequelizeOptions = { transaction: t } 245 const sequelizeOptions = { transaction: t }
246 246
247 // Save video object in database 247 // Save video object in database
248 const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag) 248 const videoCreated = await video.save(sequelizeOptions) as (MVideoAccountDefault & MVideoWithBlacklistLight & MVideoTag)
249 videoCreated.VideoChannel = videoChannel 249 videoCreated.VideoChannel = videoChannel
250 250
251 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 251 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
@@ -274,7 +274,7 @@ function insertIntoDB (parameters: {
274 const videoImport = await VideoImportModel.create( 274 const videoImport = await VideoImportModel.create(
275 Object.assign({ videoId: videoCreated.id }, videoImportAttributes), 275 Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
276 sequelizeOptions 276 sequelizeOptions
277 ) as MVideoImportVideo 277 ) as MVideoImportFormattable
278 videoImport.Video = videoCreated 278 videoImport.Video = videoCreated
279 279
280 return videoImport 280 return videoImport