aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-07-25 22:01:25 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-07-25 22:01:25 +0200
commitc1e791bad0b079af67398f6407221e6dcbb573dd (patch)
tree82e5944b4458dd35aa482a38f6b650eb93bb89ad /server/models
parent5f7021c33d31c5255b995ae0ff86b5bbea4ea4b9 (diff)
downloadPeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.gz
PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.zst
PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.zip
expliciting type checks and predicates (server only)
Diffstat (limited to 'server/models')
-rw-r--r--server/models/activitypub/actor-follow.ts8
-rw-r--r--server/models/migrations/index.ts23
-rw-r--r--server/models/oauth/oauth-token.ts9
-rw-r--r--server/models/video/video-comment.ts4
4 files changed, 35 insertions, 9 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index b8ce6de1d..adec5e92b 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -111,7 +111,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
111 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) 111 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
112 } 112 }
113 113
114 static updateActorFollowsScore (goodInboxes: string[], badInboxes: string[], t: Sequelize.Transaction) { 114 static updateActorFollowsScore (goodInboxes: string[], badInboxes: string[], t: Sequelize.Transaction | undefined) {
115 if (goodInboxes.length === 0 && badInboxes.length === 0) return 115 if (goodInboxes.length === 0 && badInboxes.length === 0) return
116 116
117 logger.info('Updating %d good actor follows and %d bad actor follows scores.', goodInboxes.length, badInboxes.length) 117 logger.info('Updating %d good actor follows and %d bad actor follows scores.', goodInboxes.length, badInboxes.length)
@@ -344,7 +344,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
344 } 344 }
345 } 345 }
346 346
347 private static incrementScores (inboxUrls: string[], value: number, t: Sequelize.Transaction) { 347 private static incrementScores (inboxUrls: string[], value: number, t: Sequelize.Transaction | undefined) {
348 const inboxUrlsString = inboxUrls.map(url => `'${url}'`).join(',') 348 const inboxUrlsString = inboxUrls.map(url => `'${url}'`).join(',')
349 349
350 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` + 350 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
@@ -354,10 +354,10 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
354 'WHERE "actor"."inboxUrl" IN (' + inboxUrlsString + ') OR "actor"."sharedInboxUrl" IN (' + inboxUrlsString + ')' + 354 'WHERE "actor"."inboxUrl" IN (' + inboxUrlsString + ') OR "actor"."sharedInboxUrl" IN (' + inboxUrlsString + ')' +
355 ')' 355 ')'
356 356
357 const options = { 357 const options = t ? {
358 type: Sequelize.QueryTypes.BULKUPDATE, 358 type: Sequelize.QueryTypes.BULKUPDATE,
359 transaction: t 359 transaction: t
360 } 360 } : undefined
361 361
362 return ActorFollowModel.sequelize.query(query, options) 362 return ActorFollowModel.sequelize.query(query, options)
363 } 363 }
diff --git a/server/models/migrations/index.ts b/server/models/migrations/index.ts
new file mode 100644
index 000000000..c2b31b05e
--- /dev/null
+++ b/server/models/migrations/index.ts
@@ -0,0 +1,23 @@
1import * as Sequelize from 'sequelize'
2
3declare namespace Migration {
4 interface Boolean extends Sequelize.DefineAttributeColumnOptions {
5 defaultValue: boolean | null
6 }
7
8 interface String extends Sequelize.DefineAttributeColumnOptions {
9 defaultValue: string | null
10 }
11
12 interface Integer extends Sequelize.DefineAttributeColumnOptions {
13 defaultValue: number | null
14 }
15
16 interface BigInteger extends Sequelize.DefineAttributeColumnOptions {
17 defaultValue: Sequelize.DataTypeBigInt | number | null
18 }
19}
20
21export {
22 Migration
23}
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index 759aa2779..026c30135 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -154,9 +154,12 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> {
154 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT) 154 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT)
155 .findOne(query) 155 .findOne(query)
156 .then(token => { 156 .then(token => {
157 token['user'] = token.User 157 if (token) {
158 158 token['user'] = token.User
159 return token 159 return token
160 } else {
161 return new OAuthTokenModel()
162 }
160 }) 163 })
161 } 164 }
162 165
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index e79aff209..03122dc03 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -156,7 +156,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
156 as: 'InReplyToVideoComment', 156 as: 'InReplyToVideoComment',
157 onDelete: 'CASCADE' 157 onDelete: 'CASCADE'
158 }) 158 })
159 InReplyToVideoComment: VideoCommentModel 159 InReplyToVideoComment: VideoCommentModel | null
160 160
161 @ForeignKey(() => VideoModel) 161 @ForeignKey(() => VideoModel)
162 @Column 162 @Column
@@ -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) { 420 if ((this.inReplyToCommentId !== null) || (this.InReplyToVideoComment !== 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