aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/audience.ts6
-rw-r--r--server/lib/activitypub/videos.ts16
-rw-r--r--server/lib/emailer.ts3
-rw-r--r--server/lib/job-queue/handlers/utils/activitypub-http-utils.ts2
-rw-r--r--server/lib/job-queue/handlers/video-file.ts6
-rw-r--r--server/lib/job-queue/job-queue.ts2
-rw-r--r--server/lib/redis.ts15
-rw-r--r--server/lib/user.ts9
-rw-r--r--server/lib/video-comment.ts8
9 files changed, 37 insertions, 30 deletions
diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts
index 7164135b6..7b4067c11 100644
--- a/server/lib/activitypub/audience.ts
+++ b/server/lib/activitypub/audience.ts
@@ -20,7 +20,7 @@ function getVideoCommentAudience (
20 isOrigin = false 20 isOrigin = false
21) { 21) {
22 const to = [ ACTIVITY_PUB.PUBLIC ] 22 const to = [ ACTIVITY_PUB.PUBLIC ]
23 const cc = [] 23 const cc: string[] = []
24 24
25 // Owner of the video we comment 25 // Owner of the video we comment
26 if (isOrigin === false) { 26 if (isOrigin === false) {
@@ -60,8 +60,8 @@ function getAudience (actorSender: ActorModel, isPublic = true) {
60} 60}
61 61
62function buildAudience (followerUrls: string[], isPublic = true) { 62function buildAudience (followerUrls: string[], isPublic = true) {
63 let to = [] 63 let to: string[] = []
64 let cc = [] 64 let cc: string[] = []
65 65
66 if (isPublic) { 66 if (isPublic) {
67 to = [ ACTIVITY_PUB.PUBLIC ] 67 to = [ ACTIVITY_PUB.PUBLIC ]
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index fdc082b61..2944cb729 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -88,17 +88,17 @@ async function videoActivityObjectToDBAttributes (
88 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED 88 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED
89 const duration = videoObject.duration.replace(/[^\d]+/, '') 89 const duration = videoObject.duration.replace(/[^\d]+/, '')
90 90
91 let language: string = null 91 let language: string | undefined
92 if (videoObject.language) { 92 if (videoObject.language) {
93 language = videoObject.language.identifier 93 language = videoObject.language.identifier
94 } 94 }
95 95
96 let category: number = null 96 let category: number | undefined
97 if (videoObject.category) { 97 if (videoObject.category) {
98 category = parseInt(videoObject.category.identifier, 10) 98 category = parseInt(videoObject.category.identifier, 10)
99 } 99 }
100 100
101 let licence: number = null 101 let licence: number | undefined
102 if (videoObject.licence) { 102 if (videoObject.licence) {
103 licence = parseInt(videoObject.licence.identifier, 10) 103 licence = parseInt(videoObject.licence.identifier, 10)
104 } 104 }
@@ -143,7 +143,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
143 throw new Error('Cannot find video files for ' + videoCreated.url) 143 throw new Error('Cannot find video files for ' + videoCreated.url)
144 } 144 }
145 145
146 const attributes = [] 146 const attributes: VideoFileModel[] = []
147 for (const fileUrl of fileUrls) { 147 for (const fileUrl of fileUrls) {
148 // Fetch associated magnet uri 148 // Fetch associated magnet uri
149 const magnet = videoObject.url.find(u => { 149 const magnet = videoObject.url.find(u => {
@@ -153,7 +153,11 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
153 if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href) 153 if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href)
154 154
155 const parsed = magnetUtil.decode(magnet.href) 155 const parsed = magnetUtil.decode(magnet.href)
156 if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) throw new Error('Cannot parse magnet URI ' + magnet.href) 156 if (!parsed ||
157 (parsed.infoHash &&
158 (isVideoFileInfoHashValid(parsed.infoHash) === false))) {
159 throw new Error('Cannot parse magnet URI ' + magnet.href)
160 }
157 161
158 const attribute = { 162 const attribute = {
159 extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ], 163 extname: VIDEO_MIMETYPE_EXT[ fileUrl.mimeType ],
@@ -161,7 +165,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
161 resolution: fileUrl.width, 165 resolution: fileUrl.width,
162 size: fileUrl.size, 166 size: fileUrl.size,
163 videoId: videoCreated.id 167 videoId: videoCreated.id
164 } 168 } as VideoFileModel
165 attributes.push(attribute) 169 attributes.push(attribute)
166 } 170 }
167 171
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 88a06cb79..ded321bf7 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -91,9 +91,10 @@ class Emailer {
91 91
92 async addVideoAbuseReport (videoId: number) { 92 async addVideoAbuseReport (videoId: number) {
93 const video = await VideoModel.load(videoId) 93 const video = await VideoModel.load(videoId)
94 if (!video) throw new Error('Unknown Video id during Abuse report.')
94 95
95 const text = `Hi,\n\n` + 96 const text = `Hi,\n\n` +
96 `Your instance received an abuse for video the following video ${video.url}\n\n` + 97 `Your instance received an abuse for the following video ${video.url}\n\n` +
97 `Cheers,\n` + 98 `Cheers,\n` +
98 `PeerTube.` 99 `PeerTube.`
99 100
diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
index c087371c6..36092665e 100644
--- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
+++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
@@ -15,7 +15,7 @@ async function computeBody (payload: { body: any, signatureActorId?: number }) {
15} 15}
16 16
17async function buildSignedRequestOptions (payload: { signatureActorId?: number }) { 17async function buildSignedRequestOptions (payload: { signatureActorId?: number }) {
18 let actor: ActorModel 18 let actor: ActorModel | null
19 if (payload.signatureActorId) { 19 if (payload.signatureActorId) {
20 actor = await ActorModel.load(payload.signatureActorId) 20 actor = await ActorModel.load(payload.signatureActorId)
21 if (!actor) throw new Error('Unknown signature actor id.') 21 if (!actor) throw new Error('Unknown signature actor id.')
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts
index bd68dd78b..6b1a8f132 100644
--- a/server/lib/job-queue/handlers/video-file.ts
+++ b/server/lib/job-queue/handlers/video-file.ts
@@ -28,7 +28,7 @@ async function processVideoFileImport (job: Bull.Job) {
28 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID) 28 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID)
29 // No video, maybe deleted? 29 // No video, maybe deleted?
30 if (!video) { 30 if (!video) {
31 logger.info('Do not process job %d, video does not exist.', job.id, { videoUUID: video.uuid }) 31 logger.info('Do not process job %d, video does not exist.', job.id)
32 return undefined 32 return undefined
33 } 33 }
34 34
@@ -45,13 +45,13 @@ async function processVideoFile (job: Bull.Job) {
45 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID) 45 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID)
46 // No video, maybe deleted? 46 // No video, maybe deleted?
47 if (!video) { 47 if (!video) {
48 logger.info('Do not process job %d, video does not exist.', job.id, { videoUUID: video.uuid }) 48 logger.info('Do not process job %d, video does not exist.', job.id)
49 return undefined 49 return undefined
50 } 50 }
51 51
52 // Transcoding in other resolution 52 // Transcoding in other resolution
53 if (payload.resolution) { 53 if (payload.resolution) {
54 await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode) 54 await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode || false)
55 55
56 await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video) 56 await retryTransactionWrapper(onVideoFileTranscoderOrImportSuccess, video)
57 } else { 57 } else {
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 1b46180e8..b018d0e8a 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -87,7 +87,7 @@ class JobQueue {
87 const queue = this.queues[obj.type] 87 const queue = this.queues[obj.type]
88 if (queue === undefined) { 88 if (queue === undefined) {
89 logger.error('Unknown queue %s: cannot create job.', obj.type) 89 logger.error('Unknown queue %s: cannot create job.', obj.type)
90 return 90 throw Error('Unknown queue, cannot create job')
91 } 91 }
92 92
93 const jobArgs: Bull.JobOptions = { 93 const jobArgs: Bull.JobOptions = {
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 06a340060..e547537c3 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -6,8 +6,8 @@ import { CONFIG, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../in
6 6
7type CachedRoute = { 7type CachedRoute = {
8 body: string, 8 body: string,
9 contentType?: string 9 contentType: string
10 statusCode?: string 10 statusCode: string
11} 11}
12 12
13class Redis { 13class Redis {
@@ -75,11 +75,12 @@ class Redis {
75 } 75 }
76 76
77 setCachedRoute (req: express.Request, body: any, lifetime: number, contentType?: string, statusCode?: number) { 77 setCachedRoute (req: express.Request, body: any, lifetime: number, contentType?: string, statusCode?: number) {
78 const cached: CachedRoute = { 78 const cached: CachedRoute = Object.assign({}, {
79 body: body.toString(), 79 body: body.toString()
80 contentType, 80 },
81 statusCode: statusCode.toString() 81 (contentType) ? { contentType } : null,
82 } 82 (statusCode) ? { statusCode: statusCode.toString() } : null
83 )
83 84
84 return this.setObject(this.buildCachedRouteKey(req), cached, lifetime) 85 return this.setObject(this.buildCachedRouteKey(req), cached, lifetime)
85 } 86 }
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 51050de9b..ac5f55260 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -6,6 +6,7 @@ import { UserModel } from '../models/account/user'
6import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' 6import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
7import { createVideoChannel } from './video-channel' 7import { createVideoChannel } from './video-channel'
8import { VideoChannelModel } from '../models/video/video-channel' 8import { VideoChannelModel } from '../models/video/video-channel'
9import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
9 10
10async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) { 11async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) {
11 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { 12 const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => {
@@ -34,9 +35,9 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
34 35
35async function createLocalAccountWithoutKeys ( 36async function createLocalAccountWithoutKeys (
36 name: string, 37 name: string,
37 userId: number, 38 userId: number | null,
38 applicationId: number, 39 applicationId: number | null,
39 t: Sequelize.Transaction, 40 t: Sequelize.Transaction | undefined,
40 type: ActivityPubActorType= 'Person' 41 type: ActivityPubActorType= 'Person'
41) { 42) {
42 const url = getAccountActivityPubUrl(name) 43 const url = getAccountActivityPubUrl(name)
@@ -49,7 +50,7 @@ async function createLocalAccountWithoutKeys (
49 userId, 50 userId,
50 applicationId, 51 applicationId,
51 actorId: actorInstanceCreated.id 52 actorId: actorInstanceCreated.id
52 }) 53 } as FilteredModelAttributes<AccountModel>)
53 54
54 const accountInstanceCreated = await accountInstance.save({ transaction: t }) 55 const accountInstanceCreated = await accountInstance.save({ transaction: t })
55 accountInstanceCreated.Actor = actorInstanceCreated 56 accountInstanceCreated.Actor = actorInstanceCreated
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index f88e5cfdf..70ba7c303 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -9,14 +9,14 @@ import { sendCreateVideoComment } from './activitypub/send'
9 9
10async function createVideoComment (obj: { 10async function createVideoComment (obj: {
11 text: string, 11 text: string,
12 inReplyToComment: VideoCommentModel, 12 inReplyToComment: VideoCommentModel | null,
13 video: VideoModel 13 video: VideoModel
14 account: AccountModel 14 account: AccountModel
15}, t: Sequelize.Transaction) { 15}, t: Sequelize.Transaction) {
16 let originCommentId: number = null 16 let originCommentId: number | null = null
17 let inReplyToCommentId: number = null 17 let inReplyToCommentId: number | null = null
18 18
19 if (obj.inReplyToComment) { 19 if (obj.inReplyToComment && obj.inReplyToComment !== null) {
20 originCommentId = obj.inReplyToComment.originCommentId || obj.inReplyToComment.id 20 originCommentId = obj.inReplyToComment.originCommentId || obj.inReplyToComment.id
21 inReplyToCommentId = obj.inReplyToComment.id 21 inReplyToCommentId = obj.inReplyToComment.id
22 } 22 }