added abcex in/out convertion
This commit is contained in:
parent
d227c0368b
commit
9dc57ed8ce
6 changed files with 99 additions and 28 deletions
|
@ -1,10 +1,11 @@
|
||||||
# url_shortiner
|
# u.arns.lt (utilities)
|
||||||
|
|
||||||
Various utilities just for fun.
|
Various utilities just for fun.
|
||||||
|
|
||||||
## Technical idea
|
## Technical idea
|
||||||
|
|
||||||
* url shortiner (Trumpink nūruoda)
|
* url shortiner (Trumpink nūruoda)
|
||||||
|
* convert in/to Abcex
|
||||||
* TODO: image uploader/viewer
|
* TODO: image uploader/viewer
|
||||||
* TODO: text uploader/viewer. Support code highlighting
|
* TODO: text uploader/viewer. Support code highlighting
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module g.arns.lt/zordsdavini/url_shortiner
|
||||||
go 1.21.5
|
go 1.21.5
|
||||||
|
|
||||||
require (
|
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/foolin/goview v0.3.0
|
||||||
github.com/gin-contrib/sessions v0.0.5
|
github.com/gin-contrib/sessions v0.0.5
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,7 @@
|
||||||
g.arns.lt/zordsdavini/abcex v1.0.0 h1:qQqlZ4DMfethCGK4I6yGaLqMrTzKNIshqpINd1l3t0E=
|
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.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.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
||||||
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
|
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=
|
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||||
|
|
28
main.go
28
main.go
|
@ -3,7 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"g.arns.lt/zordsdavini/abcex"
|
||||||
"github.com/foolin/goview/supports/ginview"
|
"github.com/foolin/goview/supports/ginview"
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-contrib/sessions/cookie"
|
"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) {
|
r.GET("/:short_url", func(c *gin.Context) {
|
||||||
redirectUrl := getRedirectUrl(db, c.Param("short_url"))
|
redirectUrl := getRedirectUrl(db, c.Param("short_url"))
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
|
|
||||||
<p>
|
<div class="row">
|
||||||
|
<div class="col-md-4 col-sm-12">
|
||||||
<form method="POST" class="form-inline">
|
<form method="POST" class="form-inline">
|
||||||
<input
|
<input
|
||||||
type="url"
|
type="url"
|
||||||
|
@ -23,6 +24,49 @@
|
||||||
{{if .shortUrl}}
|
{{if .shortUrl}}
|
||||||
<b>{{ .shortUrl }}</b>
|
<b>{{ .shortUrl }}</b>
|
||||||
{{end}}
|
{{end}}
|
||||||
</p>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4 col-sm-12">
|
||||||
|
<form action="/abcex" method="POST" class="form-inline">
|
||||||
|
<input
|
||||||
|
name="encode_abcex"
|
||||||
|
class="form-control mb-2 mr-sm-2 border-success"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="submit"
|
||||||
|
value="Ožkuodouk i Abcex"
|
||||||
|
class="btn btn-sm btn-success mb-2"
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{if .abcex}}
|
||||||
|
<b>{{ .abcex }}</b>
|
||||||
|
{{end}}
|
||||||
|
{{if .abcex_err}}
|
||||||
|
<b class="text-danger">Naėšējė ožkuodoutė...</b>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4 col-sm-12">
|
||||||
|
<form action="/de-abcex" method="POST" class="form-inline">
|
||||||
|
<input
|
||||||
|
name="decode_abcex"
|
||||||
|
class="form-control mb-2 mr-sm-2 border-success"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="submit"
|
||||||
|
value="Atkuodouk ėš Abcex"
|
||||||
|
class="btn btn-sm btn-success mb-2"
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{if .de_abcex}}
|
||||||
|
<b>{{ .de_abcex }}</b>
|
||||||
|
{{end}}
|
||||||
|
{{if .de_abcex_err}}
|
||||||
|
<b class="text-danger">Naėšējė atkuodoutė...</b>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -10,18 +10,14 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container py-2">
|
<div class="container py-2">
|
||||||
<h1>Arna rakondā</h1>
|
<h1><a href="/">Arna rakondā</a></h1>
|
||||||
<div class="border-top row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col pb-3">
|
||||||
<a href="https://www.buymeacoffee.com/zordsdavini" target="_blank" rel="nofollow noopener"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="40px"></a>
|
<a href="https://www.buymeacoffee.com/zordsdavini" target="_blank" rel="nofollow noopener"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="40px"></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
{{template "content" .}}
|
{{template "content" .}}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{include "layouts/footer"}}
|
{{include "layouts/footer"}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue