fix: enforce the chat's per-message upload total

jz.bm.chat.max_upload_bytes is now handed to golem15.chat as the total
size of one message's attachments, so the server enforces the limit the
bootstrap advertises.
This commit is contained in:
2026-10-26 19:32:07 +01:00
parent cf32fa18b9
commit a840d0ad02
2 changed files with 22 additions and 1 deletions

19
chat.go
View File

@@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
chatclasses "git.golem15.com/golem15/sm-chat-plugin/classes"
chatcontracts "git.golem15.com/golem15/sm-chat-plugin/contracts"
chanclasses "git.golem15.com/golem15/sm-chatchannels-plugin/classes"
"git.golem15.com/golem15/summercms/modules/backpack"
@@ -42,9 +43,27 @@ func (p *Plugin) registerChat(app *backpack.App) error {
if err := reg.Add(p.ID(), chatcontracts.Registration{Alias: classes.ChatContextType, Loader: p.loadChatContext}); err != nil {
return err
}
if err := p.installChatLimits(app); err != nil {
return err
}
return p.installChatAccess(app)
}
// installChatLimits makes golem15.chat enforce jz.bm.chat.max_upload_bytes
// as the total size of one message's attachments, the value the bootstrap
// advertises to the student app. golem15.chat publishes its service from
// its own database hook, which runs before this one.
func (p *Plugin) installChatLimits(app *backpack.App) error {
return lagoon.OnDatabase(app, func(_ *sql.DB, _ *gorm.DB) error {
svc, ok := app.Lookup[*chatclasses.Service]()
if !ok || svc == nil {
return errors.New("jz.bm: golem15.chat must be listed before jz.bm in summer.yaml")
}
svc.SetMaxMessageBytes(int64(p.chatMaxUploadBytes()))
return nil
})
}
// loadChatContext is the loader of the bm alias. The only context is id 1;
// any other id is unknown, which golem15.chat answers with its not-a-member
// error.

View File

@@ -19,7 +19,9 @@ public_url: ""
chat:
group: studenci
moderator_group: moderatorzy
# Total size of one message's attachments (60 MiB). It stays under nginx's
# Total size of one message's attachments (60 MiB), enforced by
# golem15.chat when the message is sent (Service.SetMaxMessageBytes) and
# checked by the student app before upload. It stays under nginx's
# client_max_body_size 64m so the multipart envelope still fits.
max_upload_bytes: 62914560
# Entity embeds (deadline, class, reading) per message.