dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 01ad6ee88c8861eddc1132c450c6a6fc09de21d3
parent fc13bb27ce04abd68f81de76bb2b5789bfd7f4ca
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun,  4 Dec 2022 00:32:16 -0500

dedup code

Diffstat:
Mpkg/web/handlers/handlers.go | 30++++++------------------------
1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -650,32 +650,14 @@ func DAesB64Str(in string) (string, error) { } func MetaCss(c echo.Context) error { - token := "signal" - lb := "" // \n - var buf bytes.Buffer - sizes := []float64{0, 320, 350, 390, 430, 470, 520, 570, 620, 690, 750, 830, 910, 1000, 1100, 1220, 1340, 1470, 1620, 1780, 1960, 2150, 2370, 2600} - for i := 1; i < len(sizes); i++ { - prev := sizes[i-1] - size := sizes[i] - _, _ = fmt.Fprintf(&buf, "@media(min-device-width:%.0fpx) and (max-device-width:%.5fpx){.div_1{background:url('/public/img/%s/sw/%.0fx%.0f.png')}}%s", prev, size-0.00001, token, prev, size, lb) - } - _, _ = fmt.Fprintf(&buf, "@media(min-device-width:%.0fpx){.div_1{background:url('/public/img/%s/sw/%.0fx.png')}}%s", 2600.0, token, 2600.0, lb) - for i := 1; i < len(sizes); i++ { - prev := sizes[i-1] - size := sizes[i] - _, _ = fmt.Fprintf(&buf, "@media(min-device-height:%.0fpx) and (max-device-height:%.5fpx){.div_2{background:url('/public/img/%s/sh/%.0fx%.0f.png')}}%s", prev, size-0.00001, token, prev, size, lb) - } - _, _ = fmt.Fprintf(&buf, "@media(min-device-height:%.0fpx){.div_2{background:url('/public/img/%s/sh/%.0fx.png')}}%s", 2600.0, token, 2600.0, lb) - fonts := []string{"Helvatica"} - for idx, font := range fonts { - _, _ = fmt.Fprintf(&buf, `@font-face{font-family:'%s';src:local('%s'),url('/public/img/%s/%s/%s.ttf')format('truetype');}%s`, font, font, token, font, font, lb) - _, _ = fmt.Fprintf(&buf, `.div_f%d{font-family:'%s';position:absolute;top:-100px}%s`, idx, font, lb) - } - return c.Blob(http.StatusOK, "text/css; charset=utf-8", buf.Bytes()) + return c.Blob(http.StatusOK, "text/css; charset=utf-8", metaCss("signal")) } func SignupCss(c echo.Context) error { - token := c.Param("signupToken") + return c.Blob(http.StatusOK, "text/css; charset=utf-8", metaCss(c.Param("signupToken"))) +} + +func metaCss(token string) []byte { lb := "" // \n var buf bytes.Buffer sizes := []float64{0, 320, 350, 390, 430, 470, 520, 570, 620, 690, 750, 830, 910, 1000, 1100, 1220, 1340, 1470, 1620, 1780, 1960, 2150, 2370, 2600} @@ -696,7 +678,7 @@ func SignupCss(c echo.Context) error { _, _ = fmt.Fprintf(&buf, `@font-face{font-family:'%s';src:local('%s'),url('/public/img/%s/%s/%s.ttf')format('truetype');}%s`, font, font, token, font, font, lb) _, _ = fmt.Fprintf(&buf, `.div_f%d{font-family:'%s';position:absolute;top:-100px}%s`, idx, font, lb) } - return c.Blob(http.StatusOK, "text/css; charset=utf-8", buf.Bytes()) + return buf.Bytes() } //var signupCache = cache.New(5*time.Minute, 5*time.Minute)