1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Rework project structure

This commit is contained in:
Lukas Schulte Pelkum
2021-04-15 20:15:42 +02:00
parent de2add44ec
commit 1792ef1c38
20 changed files with 238 additions and 328 deletions

View File

@@ -2,9 +2,12 @@ package v1
import (
"encoding/json"
"time"
"github.com/lus/pasty/internal/pastes"
"github.com/lus/pasty/internal/config"
"github.com/lus/pasty/internal/shared"
"github.com/lus/pasty/internal/storage"
"github.com/lus/pasty/internal/utils"
"github.com/valyala/fasthttp"
)
@@ -15,10 +18,8 @@ func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
switch string(ctx.Request.Header.ContentType()) {
case "text/plain":
content = string(ctx.PostBody())
break
case "multipart/form-data":
content = string(ctx.FormValue("data"))
break
default:
ctx.SetStatusCode(fasthttp.StatusBadRequest)
ctx.SetBodyString("invalid content type")
@@ -34,11 +35,12 @@ func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
}
// Create the paste object
paste, err := pastes.Create(id, content)
if err != nil {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
ctx.SetBodyString(err.Error())
return
paste := &shared.Paste{
ID: id,
Content: content,
DeletionToken: utils.RandomString(config.Current.DeletionTokenLength),
Created: time.Now().Unix(),
AutoDelete: config.Current.AutoDelete.Enabled,
}
// Hash the deletion token

View File

@@ -2,10 +2,13 @@ package v1
import (
"encoding/json"
"time"
"github.com/fasthttp/router"
"github.com/lus/pasty/internal/pastes"
"github.com/lus/pasty/internal/config"
"github.com/lus/pasty/internal/shared"
"github.com/lus/pasty/internal/storage"
"github.com/lus/pasty/internal/utils"
limitFasthttp "github.com/ulule/limiter/v3/drivers/middleware/fasthttp"
"github.com/valyala/fasthttp"
)
@@ -73,11 +76,12 @@ func v1PostPaste(ctx *fasthttp.RequestCtx) {
}
// Create the paste object
paste, err := pastes.Create(id, values["content"])
if err != nil {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
ctx.SetBodyString(err.Error())
return
paste := &shared.Paste{
ID: id,
Content: values["content"],
DeletionToken: utils.RandomString(config.Current.DeletionTokenLength),
Created: time.Now().Unix(),
AutoDelete: config.Current.AutoDelete.Enabled,
}
// Hash the deletion token