aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 10:57:56 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite34c85e527100c0b5c44567bd951e95be41b8d7e (patch)
tree39697c5a4dda2c2e07142a8522538db783fce2fd /server/models
parent1e1265b36c09df1465aa2b4866815c957b6a532e (diff)
downloadPeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.gz
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.zst
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.zip
Fix issues on server start
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account.ts36
-rw-r--r--server/models/account/user.ts21
-rw-r--r--server/models/pod/pod.ts10
-rw-r--r--server/models/video/video-channel.ts9
-rw-r--r--server/models/video/video.ts8
5 files changed, 38 insertions, 46 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 6ef29c8b7..cd6c822f1 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -22,8 +22,8 @@ import {
22 22
23 AccountMethods 23 AccountMethods
24} from './account-interface' 24} from './account-interface'
25import LoadApplication = AccountMethods.LoadApplication
26import { sendDeleteAccount } from '../../lib/activitypub/send-request' 25import { sendDeleteAccount } from '../../lib/activitypub/send-request'
26import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
27 27
28let Account: Sequelize.Model<AccountInstance, AccountAttributes> 28let Account: Sequelize.Model<AccountInstance, AccountAttributes>
29let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID 29let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID
@@ -60,14 +60,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
60 type: DataTypes.STRING, 60 type: DataTypes.STRING,
61 allowNull: false, 61 allowNull: false,
62 validate: { 62 validate: {
63 usernameValid: value => { 63 nameValid: value => {
64 const res = isUserUsernameValid(value) 64 const res = isUserUsernameValid(value)
65 if (res === false) throw new Error('Username is not valid.') 65 if (res === false) throw new Error('Name is not valid.')
66 } 66 }
67 } 67 }
68 }, 68 },
69 url: { 69 url: {
70 type: DataTypes.STRING, 70 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
71 allowNull: false, 71 allowNull: false,
72 validate: { 72 validate: {
73 urlValid: value => { 73 urlValid: value => {
@@ -77,7 +77,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
77 } 77 }
78 }, 78 },
79 publicKey: { 79 publicKey: {
80 type: DataTypes.STRING, 80 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY.max),
81 allowNull: false, 81 allowNull: false,
82 validate: { 82 validate: {
83 publicKeyValid: value => { 83 publicKeyValid: value => {
@@ -87,7 +87,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
87 } 87 }
88 }, 88 },
89 privateKey: { 89 privateKey: {
90 type: DataTypes.STRING, 90 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max),
91 allowNull: false, 91 allowNull: false,
92 validate: { 92 validate: {
93 privateKeyValid: value => { 93 privateKeyValid: value => {
@@ -110,14 +110,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
110 type: DataTypes.INTEGER, 110 type: DataTypes.INTEGER,
111 allowNull: false, 111 allowNull: false,
112 validate: { 112 validate: {
113 followersCountValid: value => { 113 followingCountValid: value => {
114 const res = isAccountFollowingCountValid(value) 114 const res = isAccountFollowingCountValid(value)
115 if (res === false) throw new Error('Following count is not valid.') 115 if (res === false) throw new Error('Following count is not valid.')
116 } 116 }
117 } 117 }
118 }, 118 },
119 inboxUrl: { 119 inboxUrl: {
120 type: DataTypes.STRING, 120 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
121 allowNull: false, 121 allowNull: false,
122 validate: { 122 validate: {
123 inboxUrlValid: value => { 123 inboxUrlValid: value => {
@@ -127,7 +127,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
127 } 127 }
128 }, 128 },
129 outboxUrl: { 129 outboxUrl: {
130 type: DataTypes.STRING, 130 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
131 allowNull: false, 131 allowNull: false,
132 validate: { 132 validate: {
133 outboxUrlValid: value => { 133 outboxUrlValid: value => {
@@ -137,7 +137,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
137 } 137 }
138 }, 138 },
139 sharedInboxUrl: { 139 sharedInboxUrl: {
140 type: DataTypes.STRING, 140 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
141 allowNull: false, 141 allowNull: false,
142 validate: { 142 validate: {
143 sharedInboxUrlValid: value => { 143 sharedInboxUrlValid: value => {
@@ -147,7 +147,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
147 } 147 }
148 }, 148 },
149 followersUrl: { 149 followersUrl: {
150 type: DataTypes.STRING, 150 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
151 allowNull: false, 151 allowNull: false,
152 validate: { 152 validate: {
153 followersUrlValid: value => { 153 followersUrlValid: value => {
@@ -157,7 +157,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
157 } 157 }
158 }, 158 },
159 followingUrl: { 159 followingUrl: {
160 type: DataTypes.STRING, 160 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
161 allowNull: false, 161 allowNull: false,
162 validate: { 162 validate: {
163 followingUrlValid: value => { 163 followingUrlValid: value => {
@@ -241,7 +241,7 @@ function associate (models) {
241 241
242 Account.belongsTo(models.Application, { 242 Account.belongsTo(models.Application, {
243 foreignKey: { 243 foreignKey: {
244 name: 'userId', 244 name: 'applicationId',
245 allowNull: true 245 allowNull: true
246 }, 246 },
247 onDelete: 'cascade' 247 onDelete: 'cascade'
@@ -256,7 +256,7 @@ function associate (models) {
256 hooks: true 256 hooks: true
257 }) 257 })
258 258
259 Account.hasMany(models.AccountFollower, { 259 Account.hasMany(models.AccountFollow, {
260 foreignKey: { 260 foreignKey: {
261 name: 'accountId', 261 name: 'accountId',
262 allowNull: false 262 allowNull: false
@@ -265,7 +265,7 @@ function associate (models) {
265 onDelete: 'cascade' 265 onDelete: 'cascade'
266 }) 266 })
267 267
268 Account.hasMany(models.AccountFollower, { 268 Account.hasMany(models.AccountFollow, {
269 foreignKey: { 269 foreignKey: {
270 name: 'targetAccountId', 270 name: 'targetAccountId',
271 allowNull: false 271 allowNull: false
@@ -329,7 +329,7 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
329 attributes: [ 'sharedInboxUrl' ], 329 attributes: [ 'sharedInboxUrl' ],
330 include: [ 330 include: [
331 { 331 {
332 model: Account['sequelize'].models.AccountFollower, 332 model: Account['sequelize'].models.AccountFollow,
333 where: { 333 where: {
334 targetAccountId: this.id 334 targetAccountId: this.id
335 } 335 }
@@ -523,9 +523,9 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
523 523
524 for (const selection of selections) { 524 for (const selection of selections) {
525 let query = 'SELECT ' + selection + ' FROM "Account" ' + 525 let query = 'SELECT ' + selection + ' FROM "Account" ' +
526 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + 526 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' +
527 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + 527 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
528 'WHERE "Account"."id" = $id AND "AccountFollower"."state" = \'accepted\' ' + 528 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' +
529 'LIMIT ' + start 529 'LIMIT ' + start
530 530
531 if (count !== undefined) query += ', ' + count 531 if (count !== undefined) query += ', ' + count
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 7390baf91..8f7c9b013 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -1,23 +1,16 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
3import { getSort, addMethodsToModel } from '../utils'
4import { 3import {
5 cryptPassword,
6 comparePassword, 4 comparePassword,
5 cryptPassword,
6 isUserDisplayNSFWValid,
7 isUserPasswordValid, 7 isUserPasswordValid,
8 isUserRoleValid,
8 isUserUsernameValid, 9 isUserUsernameValid,
9 isUserDisplayNSFWValid, 10 isUserVideoQuotaValid
10 isUserVideoQuotaValid,
11 isUserRoleValid
12} from '../../helpers' 11} from '../../helpers'
13import { UserRight, USER_ROLE_LABELS, hasUserRight } from '../../../shared' 12import { addMethodsToModel, getSort } from '../utils'
14 13import { UserAttributes, UserInstance, UserMethods } from './user-interface'
15import {
16 UserInstance,
17 UserAttributes,
18
19 UserMethods
20} from './user-interface'
21 14
22let User: Sequelize.Model<UserInstance, UserAttributes> 15let User: Sequelize.Model<UserInstance, UserAttributes>
23let isPasswordMatch: UserMethods.IsPasswordMatch 16let isPasswordMatch: UserMethods.IsPasswordMatch
diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts
index 7c8b49bf8..6d270ad7f 100644
--- a/server/models/pod/pod.ts
+++ b/server/models/pod/pod.ts
@@ -63,8 +63,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
63 ) 63 )
64 64
65 const classMethods = [ 65 const classMethods = [
66 associate,
67
68 countAll, 66 countAll,
69 incrementScores, 67 incrementScores,
70 list, 68 list,
@@ -98,14 +96,6 @@ toFormattedJSON = function (this: PodInstance) {
98 96
99// ------------------------------ Statics ------------------------------ 97// ------------------------------ Statics ------------------------------
100 98
101function associate (models) {
102 Pod.belongsToMany(models.Request, {
103 foreignKey: 'podId',
104 through: models.RequestToPod,
105 onDelete: 'cascade'
106 })
107}
108
109countAll = function () { 99countAll = function () {
110 return Pod.count() 100 return Pod.count()
111} 101}
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 919ec916d..6d70f2aa2 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -10,6 +10,8 @@ import {
10 VideoChannelMethods 10 VideoChannelMethods
11} from './video-channel-interface' 11} from './video-channel-interface'
12import { sendDeleteVideoChannel } from '../../lib/activitypub/send-request' 12import { sendDeleteVideoChannel } from '../../lib/activitypub/send-request'
13import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels'
14import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
13 15
14let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes> 16let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes>
15let toFormattedJSON: VideoChannelMethods.ToFormattedJSON 17let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
@@ -65,10 +67,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
65 defaultValue: false 67 defaultValue: false
66 }, 68 },
67 url: { 69 url: {
68 type: DataTypes.STRING, 70 type: DataTypes.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.URL.max),
69 allowNull: false, 71 allowNull: false,
70 validate: { 72 validate: {
71 isUrl: true 73 urlValid: value => {
74 const res = isVideoChannelUrlValid(value)
75 if (res === false) throw new Error('Video channel URL is not valid.')
76 }
72 } 77 }
73 } 78 }
74 }, 79 },
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index ca71da375..dd73dd7ca 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -46,6 +46,7 @@ import { TagInstance } from './tag-interface'
46import { VideoFileInstance, VideoFileModel } from './video-file-interface' 46import { VideoFileInstance, VideoFileModel } from './video-file-interface'
47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' 47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
48import { sendDeleteVideo } from '../../lib/activitypub/send-request' 48import { sendDeleteVideo } from '../../lib/activitypub/send-request'
49import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
49 50
50const Buffer = safeBuffer.Buffer 51const Buffer = safeBuffer.Buffer
51 52
@@ -220,10 +221,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
220 defaultValue: false 221 defaultValue: false
221 }, 222 },
222 url: { 223 url: {
223 type: DataTypes.STRING, 224 type: DataTypes.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max),
224 allowNull: false, 225 allowNull: false,
225 validate: { 226 validate: {
226 isUrl: true 227 urlValid: value => {
228 const res = isVideoUrlValid(value)
229 if (res === false) throw new Error('Video URL is not valid.')
230 }
227 } 231 }
228 } 232 }
229 }, 233 },