From 938d10c3a6770c78125af56a55fdaab921e9bbb2 Mon Sep 17 00:00:00 2001 From: tapiron Date: Sat, 13 Sep 2025 19:10:50 +0200 Subject: [PATCH 1/4] fix: remove double rendering and test error (#26) Remove double template rendering and test error for non password protected note Co-authored-by: Thibault Piron Reviewed-on: https://git.riou.xyz/jriou/coller/pulls/26 Reviewed-by: Julien Riou Co-authored-by: tapiron Co-committed-by: tapiron --- src/server/server.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/server/server.go b/src/server/server.go index 224c46e..28bd435 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -345,9 +345,6 @@ func (h *GetWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - h.PageData.Err = fmt.Errorf("jriou") - h.Templates.ExecuteTemplate(w, templateName, h.PageData) - h.PageData.Note = note h.logger.Debug("rendering note web page") From 4944e47e764ca4785e01355505f9711ba37f3bba Mon Sep 17 00:00:00 2001 From: Thibault Piron Date: Fri, 12 Sep 2025 18:20:19 +0200 Subject: [PATCH 2/4] feat: add possibility to hide upload button --- src/cmd/collerd/README.md | 1 + src/server/config.go | 40 +++++++++++++++++---------------- src/server/server.go | 16 +++++++------ src/server/templates/index.html | 2 ++ 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/cmd/collerd/README.md b/src/cmd/collerd/README.md index 30eb167..d99a273 100644 --- a/src/cmd/collerd/README.md +++ b/src/cmd/collerd/README.md @@ -33,6 +33,7 @@ The file format is **JSON**: * **observation_internal** (int): Number of seconds to wait between two observations (default 60) * **languages** ([]string): List of supported [languages](https://github.com/microsoft/monaco-editor/tree/main/src/basic-languages) * **language** (string): Default language (default "text") +* **enable_upload_file_button** (bool): Display the upload file button in the UI (default true) The configuration file is not required but the service might not be exposed to the public. diff --git a/src/server/config.go b/src/server/config.go index 4e6cdc7..8ba51ca 100644 --- a/src/server/config.go +++ b/src/server/config.go @@ -7,24 +7,25 @@ import ( ) type Config struct { - Title string `json:"title"` - DatabaseType string `json:"database_type"` - DatabaseDsn string `json:"database_dsn"` - IDLength int `json:"id_length"` - PasswordLength int `json:"password_length"` - ExpirationInterval int `json:"expiration_interval"` - ListenAddress string `json:"listen_address"` - ListenPort int `json:"listen_port"` - Expirations []int `json:"expirations"` - Expiration int `json:"expiration"` - MaxUploadSize int64 `json:"max_upload_size"` - ShowVersion bool `json:"show_version"` - EnableMetrics bool `json:"enable_metrics"` - PrometheusRoute string `json:"prometheus_route"` - PrometheusNotesMetric string `json:"prometheus_notes_metric"` - ObservationInterval int `json:"observation_internal"` - Languages []string `json:"languages"` - Language string `json:"language"` + Title string `json:"title"` + DatabaseType string `json:"database_type"` + DatabaseDsn string `json:"database_dsn"` + IDLength int `json:"id_length"` + PasswordLength int `json:"password_length"` + ExpirationInterval int `json:"expiration_interval"` + ListenAddress string `json:"listen_address"` + ListenPort int `json:"listen_port"` + Expirations []int `json:"expirations"` + Expiration int `json:"expiration"` + MaxUploadSize int64 `json:"max_upload_size"` + ShowVersion bool `json:"show_version"` + EnableMetrics bool `json:"enable_metrics"` + PrometheusRoute string `json:"prometheus_route"` + PrometheusNotesMetric string `json:"prometheus_notes_metric"` + ObservationInterval int `json:"observation_internal"` + Languages []string `json:"languages"` + Language string `json:"language"` + EnableUploadFileButton bool `json:"enable_upload_file_button"` } func NewConfig() *Config { @@ -69,7 +70,8 @@ func NewConfig() *Config { "SQL", "YAML", }, - Language: "text", + Language: "text", + EnableUploadFileButton: true, } } diff --git a/src/server/server.go b/src/server/server.go index 224c46e..bd8097c 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -186,13 +186,14 @@ func (h *GetProtectedNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } type PageData struct { - Title string - Version string - Expirations []int - Languages []string - Err error - URL string - Note *Note + Title string + Version string + Expirations []int + Languages []string + Err error + URL string + Note *Note + EnableUploadFileButton bool } type HomeHandler struct { @@ -432,6 +433,7 @@ func (s *Server) Start() error { if s.config.ShowVersion { p.Version = s.version } + p.EnableUploadFileButton = s.config.EnableUploadFileButton templates, err := template.New("templates").Funcs(funcs).ParseFS(templatesFS, "templates/*.html") if err != nil { diff --git a/src/server/templates/index.html b/src/server/templates/index.html index 42faef1..fc64a82 100644 --- a/src/server/templates/index.html +++ b/src/server/templates/index.html @@ -31,9 +31,11 @@ value="delete-after-read" name="delete-after-read"> + {{if .EnableUploadFileButton}}
+ {{end}}
- - {{range .Expirations}} - + + {{range $exp := .Expirations}} + {{end}}
From 3f8d42571b7a438dd30e2f9f6e54d32eb3654af6 Mon Sep 17 00:00:00 2001 From: Thibault Piron Date: Fri, 12 Sep 2025 18:20:19 +0200 Subject: [PATCH 4/4] feat: add possibility to hide upload button --- src/cmd/collerd/README.md | 1 + src/server/config.go | 40 +++++++++++++++++---------------- src/server/server.go | 18 ++++++++------- src/server/templates/index.html | 2 ++ 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/cmd/collerd/README.md b/src/cmd/collerd/README.md index 30eb167..d99a273 100644 --- a/src/cmd/collerd/README.md +++ b/src/cmd/collerd/README.md @@ -33,6 +33,7 @@ The file format is **JSON**: * **observation_internal** (int): Number of seconds to wait between two observations (default 60) * **languages** ([]string): List of supported [languages](https://github.com/microsoft/monaco-editor/tree/main/src/basic-languages) * **language** (string): Default language (default "text") +* **enable_upload_file_button** (bool): Display the upload file button in the UI (default true) The configuration file is not required but the service might not be exposed to the public. diff --git a/src/server/config.go b/src/server/config.go index 4e6cdc7..8ba51ca 100644 --- a/src/server/config.go +++ b/src/server/config.go @@ -7,24 +7,25 @@ import ( ) type Config struct { - Title string `json:"title"` - DatabaseType string `json:"database_type"` - DatabaseDsn string `json:"database_dsn"` - IDLength int `json:"id_length"` - PasswordLength int `json:"password_length"` - ExpirationInterval int `json:"expiration_interval"` - ListenAddress string `json:"listen_address"` - ListenPort int `json:"listen_port"` - Expirations []int `json:"expirations"` - Expiration int `json:"expiration"` - MaxUploadSize int64 `json:"max_upload_size"` - ShowVersion bool `json:"show_version"` - EnableMetrics bool `json:"enable_metrics"` - PrometheusRoute string `json:"prometheus_route"` - PrometheusNotesMetric string `json:"prometheus_notes_metric"` - ObservationInterval int `json:"observation_internal"` - Languages []string `json:"languages"` - Language string `json:"language"` + Title string `json:"title"` + DatabaseType string `json:"database_type"` + DatabaseDsn string `json:"database_dsn"` + IDLength int `json:"id_length"` + PasswordLength int `json:"password_length"` + ExpirationInterval int `json:"expiration_interval"` + ListenAddress string `json:"listen_address"` + ListenPort int `json:"listen_port"` + Expirations []int `json:"expirations"` + Expiration int `json:"expiration"` + MaxUploadSize int64 `json:"max_upload_size"` + ShowVersion bool `json:"show_version"` + EnableMetrics bool `json:"enable_metrics"` + PrometheusRoute string `json:"prometheus_route"` + PrometheusNotesMetric string `json:"prometheus_notes_metric"` + ObservationInterval int `json:"observation_internal"` + Languages []string `json:"languages"` + Language string `json:"language"` + EnableUploadFileButton bool `json:"enable_upload_file_button"` } func NewConfig() *Config { @@ -69,7 +70,8 @@ func NewConfig() *Config { "SQL", "YAML", }, - Language: "text", + Language: "text", + EnableUploadFileButton: true, } } diff --git a/src/server/server.go b/src/server/server.go index 92dc217..1b406fe 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -186,14 +186,15 @@ func (h *GetProtectedNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } type PageData struct { - Title string - Version string - Expirations []int - Expiration int - Languages []string - Err error - URL string - Note *Note + Title string + Version string + Expirations []int + Expiration int + Languages []string + Err error + URL string + Note *Note + EnableUploadFileButton bool } type HomeHandler struct { @@ -431,6 +432,7 @@ func (s *Server) Start() error { if s.config.ShowVersion { p.Version = s.version } + p.EnableUploadFileButton = s.config.EnableUploadFileButton templates, err := template.New("templates").Funcs(funcs).ParseFS(templatesFS, "templates/*.html") if err != nil { diff --git a/src/server/templates/index.html b/src/server/templates/index.html index 0cf1d6d..4c18a78 100644 --- a/src/server/templates/index.html +++ b/src/server/templates/index.html @@ -31,9 +31,11 @@ value="delete-after-read" name="delete-after-read"> + {{if .EnableUploadFileButton}}
+ {{end}}