announce: URL encode/decode template labels

Fixes #340, allowing slashes (/) in label names which would break the
URL otherwise.
This commit is contained in:
Harvey Tindall
2024-07-21 17:45:36 +01:00
parent 7c989fda08
commit 6b576f2ffe
2 changed files with 11 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"net/url"
"os"
"strings"
"time"
@@ -927,12 +928,17 @@ func (app *appContext) GetAnnounceTemplates(gc *gin.Context) {
// @Produce json
// @Success 200 {object} announcementTemplate
// @Failure 400 {object} boolResponse
// @Param name path string true "name of template"
// @Param name path string true "name of template (url encoded if necessary)"
// @Router /users/announce/template/{name} [get]
// @Security Bearer
// @tags Users
func (app *appContext) GetAnnounceTemplate(gc *gin.Context) {
name := gc.Param("name")
escapedName := gc.Param("name")
name, err := url.QueryUnescape(escapedName)
if err != nil {
respondBool(400, false, gc)
return
}
if announcement, ok := app.storage.GetAnnouncementsKey(name); ok {
gc.JSON(200, announcement)
return