From cbfe10a43e8d0b530bf7207fc9c74fb8cc3bb8df Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Feb 2024 14:33:10 +0100 Subject: [PATCH] Fix updating instance banner --- packages/tests/src/api/server/config.ts | 4 ++++ server/core/controllers/api/config.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts index 71694b396..baa9b0574 100644 --- a/packages/tests/src/api/server/config.ts +++ b/packages/tests/src/api/server/config.ts @@ -631,6 +631,10 @@ describe('Test config', function () { await testFileExistsOrNot(server, 'avatars', basename(bannerPath), true) }) + it('Should re-update an existing instance banner', async function () { + await server.config.updateInstanceBanner({ fixture: 'banner.jpg' }) + }) + it('Should remove instance banner', async function () { await server.config.deleteInstanceBanner() diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts index 86cd8d35e..6630cb40b 100644 --- a/server/core/controllers/api/config.ts +++ b/server/core/controllers/api/config.ts @@ -158,16 +158,19 @@ async function updateCustomConfig (req: express.Request, res: express.Response) async function updateInstanceBanner (req: express.Request, res: express.Response) { const bannerPhysicalFile = req.files['bannerfile'][0] - const accountServer = (await getServerActor()).Account - await updateLocalActorImageFiles(accountServer, bannerPhysicalFile, ActorImageType.BANNER) + const serverActor = await getServerActor() + serverActor.Banners = await ActorImageModel.listByActor(serverActor, ActorImageType.BANNER) // Reload banners from DB + + await updateLocalActorImageFiles(serverActor.Account, bannerPhysicalFile, ActorImageType.BANNER) return res.sendStatus(HttpStatusCode.NO_CONTENT_204) } async function deleteInstanceBanner (req: express.Request, res: express.Response) { - const accountServer = (await getServerActor()).Account + const serverActor = await getServerActor() + serverActor.Banners = await ActorImageModel.listByActor(serverActor, ActorImageType.BANNER) // Reload banners from DB - await deleteLocalActorImageFile(accountServer, ActorImageType.BANNER) + await deleteLocalActorImageFile(serverActor.Account, ActorImageType.BANNER) return res.sendStatus(HttpStatusCode.NO_CONTENT_204) }