From 0626e7af82e02f8a5bd1e74a7d4d8c916d073ceb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Apr 2018 15:10:54 +0200 Subject: Add account view --- server/models/video/video.ts | 73 ++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b0fff6526..2ad9c00dd 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -95,7 +95,33 @@ enum ScopeNames { } @Scopes({ - [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean) => { + [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean, accountId?: number) => { + const accountInclude = { + attributes: [ 'name' ], + model: AccountModel.unscoped(), + required: true, + where: {}, + include: [ + { + attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], + model: ActorModel.unscoped(), + required: true, + where: VideoModel.buildActorWhereWithFilter(filter), + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: false + }, + { + model: AvatarModel.unscoped(), + required: false + } + ] + } + ] + } + const query: IFindOptions = { where: { id: { @@ -125,30 +151,7 @@ enum ScopeNames { model: VideoChannelModel.unscoped(), required: true, include: [ - { - attributes: [ 'name' ], - model: AccountModel.unscoped(), - required: true, - include: [ - { - attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], - model: ActorModel.unscoped(), - required: true, - where: VideoModel.buildActorWhereWithFilter(filter), - include: [ - { - attributes: [ 'host' ], - model: ServerModel.unscoped(), - required: false - }, - { - model: AvatarModel.unscoped(), - required: false - } - ] - } - ] - } + accountInclude ] } ] @@ -166,6 +169,12 @@ enum ScopeNames { query.where['nsfw'] = false } + if (accountId) { + accountInclude.where = { + id: accountId + } + } + return query }, [ScopeNames.WITH_ACCOUNT_DETAILS]: { @@ -688,7 +697,15 @@ export class VideoModel extends Model { }) } - static async listForApi (start: number, count: number, sort: string, hideNSFW: boolean, filter?: VideoFilter, withFiles = false) { + static async listForApi ( + start: number, + count: number, + sort: string, + hideNSFW: boolean, + filter?: VideoFilter, + withFiles = false, + accountId?: number + ) { const query = { offset: start, limit: count, @@ -696,7 +713,7 @@ export class VideoModel extends Model { } const serverActor = await getServerActor() - return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles ] }) + return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles, accountId ] }) .findAndCountAll(query) .then(({ rows, count }) => { return { @@ -879,8 +896,6 @@ export class VideoModel extends Model { private static getLanguageLabel (id: string) { let languageLabel = VIDEO_LANGUAGES[id] - console.log(VIDEO_LANGUAGES) - console.log(id) if (!languageLabel) languageLabel = 'Unknown' return languageLabel -- cgit v1.2.3