From 9dc57ed8ced82ff244d61364ad49acf720af2ba9 Mon Sep 17 00:00:00 2001 From: Arnas Udovic Date: Thu, 8 Aug 2024 19:18:29 +0300 Subject: [PATCH] added abcex in/out convertion --- README.md | 5 ++- go.mod | 2 +- go.sum | 2 + main.go | 28 ++++++++++++++ views/index.html | 78 ++++++++++++++++++++++++++++++--------- views/layouts/master.html | 12 ++---- 6 files changed, 99 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 16e0cbd..8bfd869 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -# url_shortiner +# u.arns.lt (utilities) Various utilities just for fun. ## Technical idea * url shortiner (Trumpink nūruoda) +* convert in/to Abcex * TODO: image uploader/viewer * TODO: text uploader/viewer. Support code highlighting @@ -12,4 +13,4 @@ Various utilities just for fun. To try live version of this game visit https://u.arns.lt - \ No newline at end of file + diff --git a/go.mod b/go.mod index f822576..5ba4c08 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module g.arns.lt/zordsdavini/url_shortiner go 1.21.5 require ( - g.arns.lt/zordsdavini/abcex v1.0.0 + g.arns.lt/zordsdavini/abcex v1.0.2 github.com/foolin/goview v0.3.0 github.com/gin-contrib/sessions v0.0.5 github.com/gin-gonic/gin v1.9.1 diff --git a/go.sum b/go.sum index 13c7b0b..12ef3c4 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ g.arns.lt/zordsdavini/abcex v1.0.0 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E= g.arns.lt/zordsdavini/abcex v1.0.0/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8= +g.arns.lt/zordsdavini/abcex v1.0.2 h1:Q5+3J9NlHVnWGePetEAoDh/pUypkRTgcRrP13iy9y4s= +g.arns.lt/zordsdavini/abcex v1.0.2/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8= github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= diff --git a/main.go b/main.go index b214e6d..bd0b2b2 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( "log" "net/http" + "strconv" + "g.arns.lt/zordsdavini/abcex" "github.com/foolin/goview/supports/ginview" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" @@ -40,6 +42,32 @@ func main() { }) }) + r.POST("/abcex", func(c *gin.Context) { + value, err := strconv.Atoi(c.PostForm("encode_abcex")) + if err != nil { + c.HTML(http.StatusOK, "index", gin.H{ + "abcex_err": true, + }) + } else { + c.HTML(http.StatusOK, "index", gin.H{ + "abcex": abcex.Encode(int64(value)), + }) + } + }) + + r.POST("/de-abcex", func(c *gin.Context) { + value := c.PostForm("decode_abcex") + if err != nil { + c.HTML(http.StatusOK, "index", gin.H{ + "de_abcex_err": true, + }) + } else { + c.HTML(http.StatusOK, "index", gin.H{ + "de_abcex": abcex.Decode(value), + }) + } + }) + r.GET("/:short_url", func(c *gin.Context) { redirectUrl := getRedirectUrl(db, c.Param("short_url")) diff --git a/views/index.html b/views/index.html index fa407fc..fa3e5ff 100644 --- a/views/index.html +++ b/views/index.html @@ -6,23 +6,67 @@ {{define "content"}} -

-

- - -
+
+
+
+ + +
-{{if .shortUrl}} - {{ .shortUrl }} -{{end}} -

+ {{if .shortUrl}} + {{ .shortUrl }} + {{end}} +
+ +
+
+ + +
+ + {{if .abcex}} + {{ .abcex }} + {{end}} + {{if .abcex_err}} + Naėšējė ožkuodoutė... + {{end}} +
+ +
+
+ + +
+ + {{if .de_abcex}} + {{ .de_abcex }} + {{end}} + {{if .de_abcex_err}} + Naėšējė atkuodoutė... + {{end}} +
+
{{end}} diff --git a/views/layouts/master.html b/views/layouts/master.html index 023962e..83b0489 100644 --- a/views/layouts/master.html +++ b/views/layouts/master.html @@ -10,18 +10,14 @@
-

Arna rakondā

-
-
+

Arna rakondā

+
+
-
-
- {{template "content" .}} -
-
+ {{template "content" .}} {{include "layouts/footer"}}