mirror of https://github.com/jlelse/GoBlog
Catch case with no media files
This commit is contained in:
parent
486bc3a250
commit
9db6ca5b42
|
@ -8,11 +8,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *goBlog) serveEditorFiles(w http.ResponseWriter, r *http.Request) {
|
func (a *goBlog) serveEditorFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
blog := r.Context().Value(blogContextKey).(string)
|
||||||
|
// Get files
|
||||||
files, err := a.mediaFiles()
|
files, err := a.mediaFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
|
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Check if files at all
|
||||||
|
if len(files) == 0 {
|
||||||
|
a.render(w, r, templateEditorFiles, &renderData{
|
||||||
|
BlogString: blog,
|
||||||
|
Data: map[string]interface{}{},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
// Sort files time desc
|
// Sort files time desc
|
||||||
sort.Slice(files, func(i, j int) bool {
|
sort.Slice(files, func(i, j int) bool {
|
||||||
return files[i].Time.After(files[j].Time)
|
return files[i].Time.After(files[j].Time)
|
||||||
|
@ -31,7 +41,6 @@ func (a *goBlog) serveEditorFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Serve HTML
|
// Serve HTML
|
||||||
blog := r.Context().Value(blogContextKey).(string)
|
|
||||||
a.render(w, r, templateEditorFiles, &renderData{
|
a.render(w, r, templateEditorFiles, &renderData{
|
||||||
BlogString: blog,
|
BlogString: blog,
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
|
|
Loading…
Reference in New Issue