Fix updating instance banner

pull/6215/head
Chocobozzz 2024-02-20 14:33:10 +01:00
parent 7ee0efb57a
commit cbfe10a43e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 11 additions and 4 deletions

View File

@ -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()

View File

@ -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)
}