aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 16:28:35 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit8e10cf1a5a438a00e5f7e0691cb830769867cffc (patch)
tree23c0aeb43d7fb05b2d280c37b4334c2f320b647e /server/models
parent8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (diff)
downloadPeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.tar.gz
PeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.tar.zst
PeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.zip
Fix video upload and videos list
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-follow-interface.ts4
-rw-r--r--server/models/account/account-follow.ts24
-rw-r--r--server/models/account/account.ts1
-rw-r--r--server/models/video/video.ts4
4 files changed, 18 insertions, 15 deletions
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index 413dad190..54baf45ed 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -10,8 +10,8 @@ export namespace AccountFollowMethods {
10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
12 12
13 export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 13 export type ListAcceptedFollowerUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> >
14 export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 14 export type ListAcceptedFollowingUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> >
15} 15}
16 16
17export interface AccountFollowClass { 17export interface AccountFollowClass {
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index c940d7cd4..f457e43e9 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -146,17 +146,17 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
146 }) 146 })
147} 147}
148 148
149listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) { 149listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) {
150 return createListAcceptedFollowForApiQuery('followers', id, start, count) 150 return createListAcceptedFollowForApiQuery('followers', accountId, start, count)
151} 151}
152 152
153listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) { 153listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) {
154 return createListAcceptedFollowForApiQuery('following', id, start, count) 154 return createListAcceptedFollowForApiQuery('following', accountId, start, count)
155} 155}
156 156
157// ------------------------------ UTILS ------------------------------ 157// ------------------------------ UTILS ------------------------------
158 158
159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) { 159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) {
160 let firstJoin: string 160 let firstJoin: string
161 let secondJoin: string 161 let secondJoin: string
162 162
@@ -168,20 +168,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
168 secondJoin = 'targetAccountId' 168 secondJoin = 'targetAccountId'
169 } 169 }
170 170
171 const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ] 171 const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ]
172 const tasks: Promise<any>[] = [] 172 const tasks: Promise<any>[] = []
173 173
174 for (const selection of selections) { 174 for (const selection of selections) {
175 let query = 'SELECT ' + selection + ' FROM "Account" ' + 175 let query = 'SELECT ' + selection + ' FROM "Accounts" ' +
176 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' + 176 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' +
177 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + 177 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
178 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' + 178 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' '
179 'LIMIT ' + start
180 179
180 if (start !== undefined) query += 'LIMIT ' + start
181 if (count !== undefined) query += ', ' + count 181 if (count !== undefined) query += ', ' + count
182 182
183 const options = { 183 const options = {
184 bind: { id }, 184 bind: { accountId },
185 type: Sequelize.QueryTypes.SELECT 185 type: Sequelize.QueryTypes.SELECT
186 } 186 }
187 tasks.push(AccountFollow['sequelize'].query(query, options)) 187 tasks.push(AccountFollow['sequelize'].query(query, options))
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 464105261..84461a2eb 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -263,6 +263,7 @@ function associate (models) {
263 name: 'targetAccountId', 263 name: 'targetAccountId',
264 allowNull: false 264 allowNull: false
265 }, 265 },
266 as: 'followers',
266 onDelete: 'cascade' 267 onDelete: 'cascade'
267 }) 268 })
268} 269}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 86800fb88..b00081f25 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -329,7 +329,7 @@ function associate (models) {
329 onDelete: 'cascade' 329 onDelete: 'cascade'
330 }) 330 })
331 331
332 Video.belongsTo(models.VideoChannel, { 332 Video.belongsTo(models.Video, {
333 foreignKey: { 333 foreignKey: {
334 name: 'parentId', 334 name: 'parentId',
335 allowNull: true 335 allowNull: true
@@ -825,9 +825,11 @@ listForApi = function (start: number, count: number, sort: string) {
825 include: [ 825 include: [
826 { 826 {
827 model: Video['sequelize'].models.VideoChannel, 827 model: Video['sequelize'].models.VideoChannel,
828 required: true,
828 include: [ 829 include: [
829 { 830 {
830 model: Video['sequelize'].models.Account, 831 model: Video['sequelize'].models.Account,
832 required: true,
831 include: [ 833 include: [
832 { 834 {
833 model: Video['sequelize'].models.Server, 835 model: Video['sequelize'].models.Server,