From cdeddff142fd20f8cb8bb346625909d61c596603 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Apr 2021 17:01:29 +0200 Subject: Add ability to update the banner --- server/controllers/api/config.ts | 8 ++++++++ server/models/account/actor-image.ts | 6 +++++- server/models/account/user.ts | 16 +++++++++++++++- server/tests/api/videos/video-channels.ts | 4 +++- 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 313513cea..e28f7502d 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -163,6 +163,14 @@ async function getConfig (req: express.Request, res: express.Response) { extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME } }, + banner: { + file: { + size: { + max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max + }, + extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME + } + }, video: { image: { extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME, diff --git a/server/models/account/actor-image.ts b/server/models/account/actor-image.ts index c532bd08d..b779e3cf6 100644 --- a/server/models/account/actor-image.ts +++ b/server/models/account/actor-image.ts @@ -72,7 +72,11 @@ export class ActorImageModel extends Model { } getStaticPath () { - return join(LAZY_STATIC_PATHS.AVATARS, this.filename) + if (this.type === ActorImageType.AVATAR) { + return join(LAZY_STATIC_PATHS.AVATARS, this.filename) + } + + return join(LAZY_STATIC_PATHS.BANNERS, this.filename) } getPath () { diff --git a/server/models/account/user.ts b/server/models/account/user.ts index a7a65c489..00c6d73aa 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -71,6 +71,7 @@ import { VideoLiveModel } from '../video/video-live' import { VideoPlaylistModel } from '../video/video-playlist' import { AccountModel } from './account' import { UserNotificationSettingModel } from './user-notification-setting' +import { ActorImageModel } from './actor-image' enum ScopeNames { FOR_ME_API = 'FOR_ME_API', @@ -97,7 +98,20 @@ enum ScopeNames { model: AccountModel, include: [ { - model: VideoChannelModel + model: VideoChannelModel.unscoped(), + include: [ + { + model: ActorModel, + required: true, + include: [ + { + model: ActorImageModel, + as: 'Banner', + required: false + } + ] + } + ] }, { attributes: [ 'id', 'name', 'type' ], diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 8033b9ba5..e50582218 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -9,6 +9,7 @@ import { doubleFollow, flushAndRunMultipleServers, getVideo, + getVideoChannel, getVideoChannelVideos, testImage, updateVideo, @@ -306,7 +307,8 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const videoChannel = await findChannel(server, secondVideoChannelId) + const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host) + const videoChannel = res.body await testImage(server.url, 'banner-resized', videoChannel.banner.path) } -- cgit v1.2.3