loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: add length limit to discord webhook icon_url

Kidsan cf3ebab4 b5b9cc1c

+26 -6
+1
options/locale/locale_en-US.ini
··· 2358 2358 settings.slack_color = Color 2359 2359 settings.discord_username = Username 2360 2360 settings.discord_icon_url = Icon URL 2361 + settings.discord_icon_url.exceeds_max_length = Icon URL must be less than or equal to 2048 characters 2361 2362 settings.event_desc = Trigger on: 2362 2363 settings.event_push_only = Push events 2363 2364 settings.event_send_everything = All events
+25 -6
services/webhook/discord.go
··· 14 14 "strings" 15 15 "unicode/utf8" 16 16 17 + "gitea.com/go-chi/binding" 18 + 17 19 webhook_model "code.gitea.io/gitea/models/webhook" 18 20 "code.gitea.io/gitea/modules/git" 19 21 "code.gitea.io/gitea/modules/json" ··· 22 24 api "code.gitea.io/gitea/modules/structs" 23 25 "code.gitea.io/gitea/modules/util" 24 26 webhook_module "code.gitea.io/gitea/modules/webhook" 27 + gitea_context "code.gitea.io/gitea/services/context" 25 28 "code.gitea.io/gitea/services/forms" 26 29 "code.gitea.io/gitea/services/webhook/shared" 27 30 ) ··· 31 34 func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD } 32 35 func (discordHandler) Icon(size int) template.HTML { return shared.ImgIcon("discord.png", size) } 33 36 37 + type discordForm struct { 38 + forms.WebhookCoreForm 39 + PayloadURL string `binding:"Required;ValidUrl"` 40 + Username string 41 + IconURL string 42 + } 43 + 44 + var _ binding.Validator = &discordForm{} 45 + 46 + // Validate implements binding.Validator. 47 + func (d *discordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { 48 + ctx := gitea_context.GetWebContext(req) 49 + if len([]rune(d.IconURL)) > 2048 { 50 + errs = append(errs, binding.Error{ 51 + FieldNames: []string{"IconURL"}, 52 + Message: ctx.Locale.TrString("repo.settings.discord_icon_url.exceeds_max_length"), 53 + }) 54 + } 55 + return errs 56 + } 57 + 34 58 func (discordHandler) UnmarshalForm(bind func(any)) forms.WebhookForm { 35 - var form struct { 36 - forms.WebhookCoreForm 37 - PayloadURL string `binding:"Required;ValidUrl"` 38 - Username string 39 - IconURL string 40 - } 59 + var form discordForm 41 60 bind(&form) 42 61 43 62 return forms.WebhookForm{