From 8161c384d78eb20b26fa8ccfab97386804a6ac61 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Mon, 17 Jan 2022 12:25:22 +0100 Subject: [PATCH] #5 and caching --- account.go | 7 +++++- files.go | 23 ------------------- image.go | 9 +++++--- templates/gallery_list.tmpl | 44 ++++++++++++++++++++++++++++++++----- templates/inc/top.tmpl | 1 - templates/message.tmpl | 11 ++++++++++ 6 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 templates/message.tmpl diff --git a/account.go b/account.go index d0d6778..8488f1c 100644 --- a/account.go +++ b/account.go @@ -153,7 +153,7 @@ func profile(t template.Template, data template.Data, s session.Session, c flame t.HTML(http.StatusOK, "settings_profile") } -func profileUpdate(s session.Session, c flamego.Context) { +func profileUpdate(t template.Template, data template.Data, s session.Session, c flamego.Context) { user, err := user2.GetUserById(sqlConnection, s.Get("user_id").(int)) if err != nil { panic(err) @@ -169,6 +169,11 @@ func profileUpdate(s session.Session, c flamego.Context) { if err != nil{ panic(err) } + + data["msg"] = "Profil updated" + data["link"] = "/settings/profile" + t.HTML(200, "message") + } func profileImage(t template.Template, data template.Data, s session.Session, c flamego.Context) { diff --git a/files.go b/files.go index 829f26a..f5b663e 100644 --- a/files.go +++ b/files.go @@ -29,29 +29,6 @@ type File struct { func uploadImageForm(t template.Template, data template.Data , s session.Session, c flamego.Context) { id := c.Request().FormValue("id") if id == "" { - galleries := []Gallery{} - err := sqlConnection.Select(&galleries, "SELECT * FROM gallery WHERE owner_id = ? ORDER BY id DESC", s.Get("user_id")) - if err != nil { - panic(err) - } - - data["galleries"] = galleries - - var list [][]Gallery - var tmp []Gallery - - for _, g := range galleries { - if len(tmp) == 6 { - list = append(list, tmp) - tmp = []Gallery{} - } - tmp = append(tmp, g) - } - list = append(list, tmp) - - data["list"] = list - - t.HTML(http.StatusOK, "file_gallery") return } data["id"] = id diff --git a/image.go b/image.go index 8907f94..6a2609f 100644 --- a/image.go +++ b/image.go @@ -8,7 +8,6 @@ import ( "github.com/nfnt/resize" "image" "image/png" - "net/http" "os" "strconv" ) @@ -57,9 +56,13 @@ func getImage(c flamego.Context) { send_s3 := buf.Bytes() - c.ResponseWriter().WriteHeader(http.StatusOK) - c.ResponseWriter().Header().Set("Content-Type", "application/octet-stream") + //c.ResponseWriter().WriteHeader(http.StatusOK) + + //c.ResponseWriter().Header().Set("Content-Type", "application/octet-stream") c.ResponseWriter().Header().Set("Content-Length", fmt.Sprintf("%v", len(send_s3))) + c.ResponseWriter().Header().Set("Cache-Control", "max-age=31536000") + c.ResponseWriter().Header().Set("X-Foo", "BAR") + c.ResponseWriter().WriteHeader(200) c.ResponseWriter().Write(send_s3) return } \ No newline at end of file diff --git a/templates/gallery_list.tmpl b/templates/gallery_list.tmpl index 35b4cdd..7a83ac2 100644 --- a/templates/gallery_list.tmpl +++ b/templates/gallery_list.tmpl @@ -1,5 +1,38 @@ {{template "top" .}} +

Select Gallery

@@ -7,11 +40,12 @@
{{ range . }}
-
-
{{ .Name }}
-
-

-
+
diff --git a/templates/inc/top.tmpl b/templates/inc/top.tmpl index d6f9ec4..1f05205 100644 --- a/templates/inc/top.tmpl +++ b/templates/inc/top.tmpl @@ -39,7 +39,6 @@ diff --git a/templates/message.tmpl b/templates/message.tmpl new file mode 100644 index 0000000..036706c --- /dev/null +++ b/templates/message.tmpl @@ -0,0 +1,11 @@ +{{template "top" .}} + + + {{template "bottom" .}} \ No newline at end of file