From 9db6ca5b428b4efe249d7b94d65597055d09fdff Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 18 Jul 2021 16:39:20 +0200 Subject: [PATCH] Catch case with no media files --- editorFiles.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/editorFiles.go b/editorFiles.go index 86a87ab..b30cae0 100644 --- a/editorFiles.go +++ b/editorFiles.go @@ -8,11 +8,21 @@ import ( ) func (a *goBlog) serveEditorFiles(w http.ResponseWriter, r *http.Request) { + blog := r.Context().Value(blogContextKey).(string) + // Get files files, err := a.mediaFiles() if err != nil { a.serveError(w, r, err.Error(), http.StatusInternalServerError) 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.Slice(files, func(i, j int) bool { return files[i].Time.After(files[j].Time) @@ -31,7 +41,6 @@ func (a *goBlog) serveEditorFiles(w http.ResponseWriter, r *http.Request) { return } // Serve HTML - blog := r.Context().Value(blogContextKey).(string) a.render(w, r, templateEditorFiles, &renderData{ BlogString: blog, Data: map[string]interface{}{