From 8e10cf1a5a438a00e5f7e0691cb830769867cffc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Nov 2017 16:28:35 +0100 Subject: Fix video upload and videos list --- server/models/account/account-follow-interface.ts | 4 ++-- server/models/account/account-follow.ts | 24 +++++++++++------------ server/models/account/account.ts | 1 + server/models/video/video.ts | 4 +++- 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'server/models') 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 { export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList > export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList > - export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList > - export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList > + export type ListAcceptedFollowerUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList > + export type ListAcceptedFollowingUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList > } export 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: }) } -listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) { - return createListAcceptedFollowForApiQuery('followers', id, start, count) +listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) { + return createListAcceptedFollowForApiQuery('followers', accountId, start, count) } -listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) { - return createListAcceptedFollowForApiQuery('following', id, start, count) +listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) { + return createListAcceptedFollowForApiQuery('following', accountId, start, count) } // ------------------------------ UTILS ------------------------------ -async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) { +async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) { let firstJoin: string let secondJoin: string @@ -168,20 +168,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi secondJoin = 'targetAccountId' } - const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ] + const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ] const tasks: Promise[] = [] for (const selection of selections) { - let query = 'SELECT ' + selection + ' FROM "Account" ' + - 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' + - 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + - 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' + - 'LIMIT ' + start + let query = 'SELECT ' + selection + ' FROM "Accounts" ' + + 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + + 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + + 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' ' + if (start !== undefined) query += 'LIMIT ' + start if (count !== undefined) query += ', ' + count const options = { - bind: { id }, + bind: { accountId }, type: Sequelize.QueryTypes.SELECT } 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) { name: 'targetAccountId', allowNull: false }, + as: 'followers', onDelete: 'cascade' }) } 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) { onDelete: 'cascade' }) - Video.belongsTo(models.VideoChannel, { + Video.belongsTo(models.Video, { foreignKey: { name: 'parentId', allowNull: true @@ -825,9 +825,11 @@ listForApi = function (start: number, count: number, sort: string) { include: [ { model: Video['sequelize'].models.VideoChannel, + required: true, include: [ { model: Video['sequelize'].models.Account, + required: true, include: [ { model: Video['sequelize'].models.Server, -- cgit v1.2.3