Compare commits
No commits in common. "73c06c3636b2f634938cb6e4f50b109cdd4ae4b5" and "098f53ef67652820cb3e319327d16e98bcea7f15" have entirely different histories.
73c06c3636
...
098f53ef67
4 changed files with 29 additions and 65 deletions
2
db.go
2
db.go
|
@ -18,7 +18,7 @@ func connectDB() *redis.Client {
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertPaste(key string, content string, secret string, ttl time.Duration) {
|
func insert_paste(key string, content string, secret string, ttl time.Duration) {
|
||||||
type dbSchema struct {
|
type dbSchema struct {
|
||||||
content string
|
content string
|
||||||
secret string
|
secret string
|
||||||
|
|
17
main.go
17
main.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -20,22 +19,10 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
fs := http.FileServer(http.Dir("./static"))
|
fs := http.FileServer(http.Dir("./static"))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||||
} else {
|
} else {
|
||||||
if urlExist(path) {
|
w.WriteHeader(http.StatusNotFound)
|
||||||
io.WriteString(w, "exist")
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case "POST":
|
case "POST":
|
||||||
if path == "/" {
|
fmt.Println("Post!")
|
||||||
secret := generateSecret()
|
|
||||||
url := "/" + generateUrl()
|
|
||||||
content := r.FormValue("content")
|
|
||||||
insertPaste(url, content, secret, -1)
|
|
||||||
http.Redirect(w, r, url, http.StatusSeeOther)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,32 +9,30 @@
|
||||||
<link href="/static/style.css" rel="stylesheet">
|
<link href="/static/style.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form>
|
<label for="content"></label>
|
||||||
<label for="content"></label>
|
<textarea id="content" name="content" placeholder="Your paste here"></textarea>
|
||||||
<textarea id="content" name="content" placeholder="Your paste here"></textarea>
|
<nav>
|
||||||
<nav>
|
<ul>
|
||||||
<ul>
|
<li>
|
||||||
<li>
|
<label for="password">Password?</label>
|
||||||
<label for="password">Password?</label>
|
<input id="password" type="text">
|
||||||
<input id="password" type="text">
|
</li>
|
||||||
</li>
|
<li><label for="exp">Expiration?</label>
|
||||||
<li><label for="exp">Expiration?</label>
|
<input id="exp" type="date"></li>
|
||||||
<input id="exp" type="date"></li>
|
<li>
|
||||||
<li>
|
<label for="type">Type</label>
|
||||||
<label for="type">Type</label>
|
<select id="type" name="type">
|
||||||
<select id="type" name="type">
|
<option value="">Plaintext</option>
|
||||||
<option value="">Plaintext</option>
|
<option value="">Python</option>
|
||||||
<option value="">Python</option>
|
</select>
|
||||||
</select>
|
</li>
|
||||||
</li>
|
</ul>
|
||||||
</ul>
|
<button>
|
||||||
<button>
|
<svg height="26" viewBox="0 0 24 24" width="26" xmlns="http://www.w3.org/2000/svg">
|
||||||
<svg height="26" viewBox="0 0 24 24" width="26" xmlns="http://www.w3.org/2000/svg">
|
<polyline points="9 11 12 14 22 4"></polyline>
|
||||||
<polyline points="9 11 12 14 22 4"></polyline>
|
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path>
|
||||||
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path>
|
</svg>
|
||||||
</svg>
|
</button>
|
||||||
</button>
|
</nav>
|
||||||
</nav>
|
|
||||||
</form>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
23
utils.go
23
utils.go
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "math/rand"
|
||||||
"math/rand"
|
|
||||||
)
|
|
||||||
|
|
||||||
func generateUrl() string {
|
func generateUrl() string {
|
||||||
length := currentConfig.urlLength
|
length := currentConfig.urlLength
|
||||||
|
@ -14,22 +12,3 @@ func generateUrl() string {
|
||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSecret() string {
|
|
||||||
length := 32
|
|
||||||
listChars := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
||||||
b := make([]rune, length)
|
|
||||||
for i := range b {
|
|
||||||
b[i] = listChars[rand.Intn(len(listChars))]
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func urlExist(url string) bool {
|
|
||||||
exist := connectDB().Exists(ctx, url).Val()
|
|
||||||
if exist == 1 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue