aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/custom-validators/videos.ts8
-rw-r--r--server/helpers/utils.ts3
-rw-r--r--server/initializers/database.ts9
-rw-r--r--server/initializers/migrations/0055-video-uuid.ts5
-rw-r--r--server/lib/activitypub/videos.ts6
-rw-r--r--server/lib/redis.ts4
-rw-r--r--server/models/migrations/index.ts4
-rw-r--r--server/models/utils.ts2
-rw-r--r--server/models/video/video-comment.ts2
9 files changed, 24 insertions, 19 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 70904af0c..338c96582 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -110,7 +110,7 @@ function isScheduleVideoUpdatePrivacyValid (value: number) {
110 ) 110 )
111} 111}
112 112
113function isVideoFileInfoHashValid (value: string) { 113function isVideoFileInfoHashValid (value: string | null | undefined) {
114 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) 114 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
115} 115}
116 116
@@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) {
158 video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) 158 video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id)
159 } 159 }
160 160
161 if (video && video !== null) { 161 if (video === null) {
162 res.status(404) 162 res.status(404)
163 .json({ error: 'Video not found' }) 163 .json({ error: 'Video not found' })
164 .end() 164 .end()
@@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) {
173async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { 173async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
174 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { 174 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
175 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) 175 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
176 if (videoChannel && videoChannel !== null) { 176 if (videoChannel === null) {
177 res.status(400) 177 res.status(400)
178 .json({ error: 'Unknown video video channel on this instance.' }) 178 .json({ error: 'Unknown video video channel on this instance.' })
179 .end() 179 .end()
@@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel,
186 } 186 }
187 187
188 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) 188 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
189 if (videoChannel && videoChannel !== null) { 189 if (videoChannel === null) {
190 res.status(400) 190 res.status(400)
191 .json({ error: 'Unknown video video channel for this account.' }) 191 .json({ error: 'Unknown video video channel for this account.' })
192 .end() 192 .end()
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 7ff1556e3..cfb427570 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -144,7 +144,8 @@ let serverActor: ActorModel
144async function getServerActor () { 144async function getServerActor () {
145 if (serverActor === undefined) { 145 if (serverActor === undefined) {
146 const application = await ApplicationModel.load() 146 const application = await ApplicationModel.load()
147 if (!application) throw Error('Could not application.') 147 if (!application) throw Error('Could not load Application from database.')
148
148 serverActor = application.Account.Actor 149 serverActor = application.Account.Actor
149 } 150 }
150 151
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index d95e34bce..1a9ce5a61 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -125,10 +125,11 @@ async function checkPostgresExtensions () {
125} 125}
126 126
127async function createFunctions () { 127async function createFunctions () {
128 const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(varchar) 128 const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(text)
129 RETURNS text AS $$ 129 RETURNS text AS
130 SELECT unaccent($1) 130$func$
131 $$ LANGUAGE sql IMMUTABLE;` 131SELECT public.unaccent('public.unaccent', $1::text)
132$func$ LANGUAGE sql IMMUTABLE;`
132 133
133 return sequelizeTypescript.query(query, { raw: true }) 134 return sequelizeTypescript.query(query, { raw: true })
134} 135}
diff --git a/server/initializers/migrations/0055-video-uuid.ts b/server/initializers/migrations/0055-video-uuid.ts
index 6db25f193..e0f904080 100644
--- a/server/initializers/migrations/0055-video-uuid.ts
+++ b/server/initializers/migrations/0055-video-uuid.ts
@@ -1,5 +1,6 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 2import * as Promise from 'bluebird'
3import { Migration } from '../../models/migrations'
3 4
4function up (utils: { 5function up (utils: {
5 transaction: Sequelize.Transaction, 6 transaction: Sequelize.Transaction,
@@ -12,7 +13,7 @@ function up (utils: {
12 type: Sequelize.UUID, 13 type: Sequelize.UUID,
13 defaultValue: Sequelize.UUIDV4, 14 defaultValue: Sequelize.UUIDV4,
14 allowNull: true 15 allowNull: true
15 } 16 } as Migration.UUID
16 17
17 return q.addColumn('Videos', 'uuid', dataUUID) 18 return q.addColumn('Videos', 'uuid', dataUUID)
18 .then(() => { 19 .then(() => {
@@ -24,7 +25,7 @@ function up (utils: {
24 return utils.sequelize.query(query) 25 return utils.sequelize.query(query)
25 }) 26 })
26 .then(() => { 27 .then(() => {
27 dataUUID.defaultValue = null // FIXME:default value cannot be null if string 28 dataUUID.defaultValue = null
28 29
29 return q.changeColumn('Videos', 'uuid', dataUUID) 30 return q.changeColumn('Videos', 'uuid', dataUUID)
30 }) 31 })
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 2944cb729..b6f57e0ab 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -38,7 +38,7 @@ async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, tr
38 }) as VideoCaptionModel[] 38 }) as VideoCaptionModel[]
39 } 39 }
40 40
41 if (isNewVideo === true) { 41 if (isNewVideo) {
42 // Now we'll add the video's meta data to our followers 42 // Now we'll add the video's meta data to our followers
43 await sendCreateVideo(video, transaction) 43 await sendCreateVideo(video, transaction)
44 await shareVideoByServerAndChannel(video, transaction) 44 await shareVideoByServerAndChannel(video, transaction)
@@ -153,9 +153,7 @@ 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 || 156 if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) {
157 (parsed.infoHash &&
158 (isVideoFileInfoHashValid(parsed.infoHash) === false))) {
159 throw new Error('Cannot parse magnet URI ' + magnet.href) 157 throw new Error('Cannot parse magnet URI ' + magnet.href)
160 } 158 }
161 159
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index e547537c3..941f7d557 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 {
diff --git a/server/models/migrations/index.ts b/server/models/migrations/index.ts
index c2b31b05e..24badb166 100644
--- a/server/models/migrations/index.ts
+++ b/server/models/migrations/index.ts
@@ -16,6 +16,10 @@ declare namespace Migration {
16 interface BigInteger extends Sequelize.DefineAttributeColumnOptions { 16 interface BigInteger extends Sequelize.DefineAttributeColumnOptions {
17 defaultValue: Sequelize.DataTypeBigInt | number | null 17 defaultValue: Sequelize.DataTypeBigInt | number | null
18 } 18 }
19
20 interface UUID extends Sequelize.DefineAttributeColumnOptions {
21 defaultValue: Sequelize.DataTypeUUIDv4 | null
22 }
19} 23}
20 24
21export { 25export {
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 393f8f036..99e146583 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -76,7 +76,7 @@ export {
76// --------------------------------------------------------------------------- 76// ---------------------------------------------------------------------------
77 77
78function searchTrigramNormalizeValue (value: string) { 78function searchTrigramNormalizeValue (value: string) {
79 return Sequelize.fn('lower', Sequelize.fn('unaccent', value)) 79 return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', value))
80} 80}
81 81
82function searchTrigramNormalizeCol (col: string) { 82function searchTrigramNormalizeCol (col: string) {
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 03122dc03..f84c1880c 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -417,7 +417,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
417 toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject { 417 toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject {
418 let inReplyTo: string 418 let inReplyTo: string
419 // New thread, so in AS we reply to the video 419 // New thread, so in AS we reply to the video
420 if ((this.inReplyToCommentId !== null) || (this.InReplyToVideoComment !== null)) { 420 if (this.inReplyToCommentId === null) {
421 inReplyTo = this.Video.url 421 inReplyTo = this.Video.url
422 } else { 422 } else {
423 inReplyTo = this.InReplyToVideoComment.url 423 inReplyTo = this.InReplyToVideoComment.url