Removed utils/render pages

This commit is contained in:
Phil 2021-12-07 17:34:44 +01:00
parent 29896be872
commit 0520e68ddc
5 changed files with 22 additions and 61 deletions

20
main.go
View file

@ -52,30 +52,40 @@ func main() {
Max: 10,
Expiration: 60 * time.Second,
LimitReached: func(c *fiber.Ctx) error {
return c.Render("slowdown", fiber.Map{})
return c.Render("home", fiber.Map{
"ERR": "You have reached the limit of requests! Please check back later. (1 minute)",
})
},
}))
app.Post("/", func(c *fiber.Ctx) error {
u := new(EUrl)
if err := c.BodyParser(u); err != nil {
return err
return c.Render("home", fiber.Map{
"ERR": err.Error(),
})
}
if !regexp.MustCompile(`^(http|https|mailto|ts3server)://`).MatchString(u.URL) {
return c.Status(http.StatusBadRequest).SendString("Invalid URL")
return c.Render("home", fiber.Map{
"ERR": err.Error(),
})
}
id, err := gonanoid.New(8)
if err != nil {
c.SendString(err.Error())
return c.Render("home", fiber.Map{
"ERR": err.Error(),
})
}
err = client.Set(id, u.URL, 1296000*time.Second).Err()
if err != nil {
c.SendString(err.Error())
return c.Render("home", fiber.Map{
"ERR": err.Error(),
})
}
fURL := c.Protocol() + "://" + c.Hostname() + "/" + id

View file

@ -1 +0,0 @@
package utils

View file

@ -61,6 +61,13 @@
</div>
{{ end }}
<!-- URL FAIL CHECK -->
{{ if .ERR }}
<div style="padding-right: 20px;" class="alert alert-dismissible alert-danger">
<p>{{ .ERR }}</p>
</div>
{{ end }}
</div>
<footer>
<center>

View file

@ -1,22 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<title>goshortly</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://bootswatch.com/5/darkly/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous">
</script>
</body>
</html>

View file

@ -1,33 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<title>SlowDOWN!</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<body class="bg-dark">
<div class="container">
<div class="mt-2 mb-4 text-white bg-dark rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Slowdown!</h1>
<p>You reached the Request limit on 10 req / 60sec.</p>
<button class="btn btn-outline-light" type="button" href="/">Go Back</button>
</div>
</div>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous">
</script>
</body>
</html>