1
0
Fork 0

Fix updating instance banner

This commit is contained in:
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)
}