forked from jriou/coller
Compare commits
3 commits
792eff78cc
...
cfdf653c47
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cfdf653c47 | ||
401397241b | |||
af5baa999c |
3 changed files with 23 additions and 9 deletions
|
@ -25,6 +25,7 @@ type Config struct {
|
||||||
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"`
|
||||||
|
UploadFileButton bool `json:"upload_file_button"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
|
@ -69,7 +70,8 @@ func NewConfig() *Config {
|
||||||
"SQL",
|
"SQL",
|
||||||
"YAML",
|
"YAML",
|
||||||
},
|
},
|
||||||
Language: "text",
|
Language: "text",
|
||||||
|
UploadFileButton: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,13 +186,14 @@ 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
|
Languages []string
|
||||||
Err error
|
Err error
|
||||||
URL string
|
URL string
|
||||||
Note *Note
|
Note *Note
|
||||||
|
UploadFileButton bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomeHandler struct {
|
type HomeHandler struct {
|
||||||
|
@ -246,7 +247,7 @@ func (h *CreateNoteWithFormHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
h.logger.Debug("checking file content type")
|
h.logger.Debug("checking file content type")
|
||||||
if handler.Header.Get("Content-Type") != "text/plain" {
|
if !strings.HasPrefix(handler.Header.Get("Content-Type"), "text/") {
|
||||||
h.PageData.Err = fmt.Errorf("text file expected (got %s)", handler.Header.Get("Content-Type"))
|
h.PageData.Err = fmt.Errorf("text file expected (got %s)", handler.Header.Get("Content-Type"))
|
||||||
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
|
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
|
||||||
return
|
return
|
||||||
|
@ -377,6 +378,12 @@ func (h *GetProtectedWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if note == nil {
|
||||||
|
h.PageData.Err = fmt.Errorf("Note doesn't exist or has been deleted")
|
||||||
|
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if password != "" && note.Encrypted {
|
if password != "" && note.Encrypted {
|
||||||
note.Content, err = internal.Decrypt(note.Content, password)
|
note.Content, err = internal.Decrypt(note.Content, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -426,6 +433,9 @@ func (s *Server) Start() error {
|
||||||
if s.config.ShowVersion {
|
if s.config.ShowVersion {
|
||||||
p.Version = s.version
|
p.Version = s.version
|
||||||
}
|
}
|
||||||
|
if s.config.UploadFileButton {
|
||||||
|
p.UploadFileButton = true
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
|
|
@ -31,9 +31,11 @@
|
||||||
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 .UploadFileButton}}
|
||||||
<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 selected="selected" disabled>Expiration</option>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue