From bbf0967a46360da0d369222b72dd952576d8a756 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 4 Oct 2023 00:10:29 +0200 Subject: [PATCH 1/2] add(backend): add url to have raw paste --- db.go | 10 ++++++++-- main.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/db.go b/db.go index 149fda1..e2a7cbd 100644 --- a/db.go +++ b/db.go @@ -28,9 +28,15 @@ func insertPaste(key string, content string, secret string, ttl time.Duration) { content: content, secret: secret, } - connectDB().HSet(ctx, key, "content", hash.content) - connectDB().HSet(ctx, key, "secret", hash.secret) + db := connectDB() + db.HSet(ctx, key, "content", hash.content) + db.HSet(ctx, key, "secret", hash.secret) if ttl > -1 { connectDB().Do(ctx, key, ttl) } } + +func getContent(key string) string { + db := connectDB() + return db.HGet(ctx, key, "content").Val() +} diff --git a/main.go b/main.go index fb83c5e..96dc5aa 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( var currentConfig config func handleRequest(w http.ResponseWriter, r *http.Request) { - path := r.URL.Path + path := strings.ReplaceAll(r.URL.Path, "/raw", "") switch r.Method { case "GET": if path == "/" { @@ -21,7 +21,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request) { http.Handle("/static/", http.StripPrefix("/static/", fs)) } else { if urlExist(path) { - io.WriteString(w, "exist") + pasteContent := getContent(path) + fmt.Println(pasteContent) + if strings.HasSuffix("/raw", path) { + io.WriteString(w, pasteContent) + } else { + io.WriteString(w, pasteContent) + } } else { w.WriteHeader(http.StatusNotFound) } From 273fb204a1e6f4e336903aeb6250ef33fc49f2f3 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 4 Oct 2023 01:06:47 +0200 Subject: [PATCH 2/2] add(config): empty example --- .env.example | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..faaaf55 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +PLAKKEN_HOST=0.0.0.0 +PLAKKEN_PORT=3000 +PLAKKEN_REDIS_ADDR=localhost:6379 +PLAKKEN_REDIS_USER= +PLAKKEN_REDIS_PASSWORD= +PLAKKEN_REDIS_DB=0