Compare commits

...

3 commits

Author SHA1 Message Date
Thibault Piron
3f8d42571b
feat: add possibility to hide upload button 2025-09-15 09:17:08 +02:00
33628331f4 feat: set default expiration in select (#28)
All checks were successful
/ pre-commit (push) Successful in 1m10s
No default value in select could be interpreted as ever lasting note.
Default value in the select makes that clearer.

Co-authored-by: Thibault Piron <thibault.a.piron@gmail.com>
Reviewed-on: #28
Reviewed-by: Julien Riou <jriou@monitoring@riou.xyz>
Co-authored-by: tapiron <tapiron@monitoring@riou.xyz>
Co-committed-by: tapiron <tapiron@monitoring@riou.xyz>
2025-09-15 06:51:16 +02:00
938d10c3a6 fix: remove double rendering and test error (#26)
All checks were successful
/ pre-commit (push) Successful in 1m11s
Remove double template rendering and test error for non password protected note

Co-authored-by: Thibault Piron <thibault.a.piron@gmail.com>
Reviewed-on: #26
Reviewed-by: Julien Riou <jriou@monitoring@riou.xyz>
Co-authored-by: tapiron <tapiron@monitoring@riou.xyz>
Co-committed-by: tapiron <tapiron@monitoring@riou.xyz>
2025-09-13 19:10:50 +02:00
4 changed files with 38 additions and 32 deletions

View file

@ -33,6 +33,7 @@ The file format is **JSON**:
* **observation_internal** (int): Number of seconds to wait between two observations (default 60) * **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) * **languages** ([]string): List of supported [languages](https://github.com/microsoft/monaco-editor/tree/main/src/basic-languages)
* **language** (string): Default language (default "text") * **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. The configuration file is not required but the service might not be exposed to the public.

View file

@ -7,24 +7,25 @@ import (
) )
type Config struct { type Config struct {
Title string `json:"title"` Title string `json:"title"`
DatabaseType string `json:"database_type"` DatabaseType string `json:"database_type"`
DatabaseDsn string `json:"database_dsn"` DatabaseDsn string `json:"database_dsn"`
IDLength int `json:"id_length"` IDLength int `json:"id_length"`
PasswordLength int `json:"password_length"` PasswordLength int `json:"password_length"`
ExpirationInterval int `json:"expiration_interval"` ExpirationInterval int `json:"expiration_interval"`
ListenAddress string `json:"listen_address"` ListenAddress string `json:"listen_address"`
ListenPort int `json:"listen_port"` ListenPort int `json:"listen_port"`
Expirations []int `json:"expirations"` Expirations []int `json:"expirations"`
Expiration int `json:"expiration"` Expiration int `json:"expiration"`
MaxUploadSize int64 `json:"max_upload_size"` MaxUploadSize int64 `json:"max_upload_size"`
ShowVersion bool `json:"show_version"` ShowVersion bool `json:"show_version"`
EnableMetrics bool `json:"enable_metrics"` EnableMetrics bool `json:"enable_metrics"`
PrometheusRoute string `json:"prometheus_route"` PrometheusRoute string `json:"prometheus_route"`
PrometheusNotesMetric string `json:"prometheus_notes_metric"` PrometheusNotesMetric string `json:"prometheus_notes_metric"`
ObservationInterval int `json:"observation_internal"` ObservationInterval int `json:"observation_internal"`
Languages []string `json:"languages"` Languages []string `json:"languages"`
Language string `json:"language"` Language string `json:"language"`
EnableUploadFileButton bool `json:"enable_upload_file_button"`
} }
func NewConfig() *Config { func NewConfig() *Config {
@ -69,7 +70,8 @@ func NewConfig() *Config {
"SQL", "SQL",
"YAML", "YAML",
}, },
Language: "text", Language: "text",
EnableUploadFileButton: true,
} }
} }

View file

@ -186,13 +186,15 @@ func (h *GetProtectedNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
} }
type PageData struct { type PageData struct {
Title string Title string
Version string Version string
Expirations []int Expirations []int
Languages []string Expiration int
Err error Languages []string
URL string Err error
Note *Note URL string
Note *Note
EnableUploadFileButton bool
} }
type HomeHandler struct { type HomeHandler struct {
@ -345,9 +347,6 @@ func (h *GetWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
h.PageData.Err = fmt.Errorf("jriou")
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
h.PageData.Note = note h.PageData.Note = note
h.logger.Debug("rendering note web page") h.logger.Debug("rendering note web page")
@ -426,12 +425,14 @@ func (s *Server) Start() error {
p := PageData{ p := PageData{
Title: s.config.Title, Title: s.config.Title,
Expirations: s.config.Expirations, Expirations: s.config.Expirations,
Expiration: s.config.Expiration,
Languages: s.config.Languages, Languages: s.config.Languages,
} }
if s.config.ShowVersion { if s.config.ShowVersion {
p.Version = s.version p.Version = s.version
} }
p.EnableUploadFileButton = s.config.EnableUploadFileButton
templates, err := template.New("templates").Funcs(funcs).ParseFS(templatesFS, "templates/*.html") templates, err := template.New("templates").Funcs(funcs).ParseFS(templatesFS, "templates/*.html")
if err != nil { if err != nil {

View file

@ -31,14 +31,16 @@
value="delete-after-read" name="delete-after-read"> value="delete-after-read" name="delete-after-read">
<label class="col-form-label col-form-label-sm" for="delete-after-read">Delete after read</label> <label class="col-form-label col-form-label-sm" for="delete-after-read">Delete after read</label>
</div> </div>
{{if .EnableUploadFileButton}}
<div class="col"> <div class="col">
<input type="file" class="form-control" for="file" id="file" name="file" accept="text/plain" /> <input type="file" class="form-control" for="file" id="file" name="file" accept="text/plain" />
</div> </div>
{{end}}
<div class="col"> <div class="col">
<select class="form-select" aria-label="Expiration" id="expiration" name="expiration"> <select class="form-select" aria-label="Expiration" id="expiration" name="expiration">
<option selected="selected" disabled>Expiration</option> <option disabled>Expiration</option>
{{range .Expirations}} {{range $exp := .Expirations}}
<option value="{{.}}">{{HumanDuration .}}</option> <option {{ if eq $exp $.Expiration }}selected="selected"{{end}} value="{{$exp}}">{{HumanDuration $exp}}</option>
{{end}} {{end}}
</select> </select>
</div> </div>