aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-16 22:42:48 -0700
committerjackyzha0 <[email protected]>2020-05-16 22:42:48 -0700
commit712bf925f8ae84a5a2fee87b8aa3c969df48fd50 (patch)
tree839a68fe0c96e313a896d0cf0300523da275fac0 /backend
parentMerge pull request #26 from jackyzha0/raw-button (diff)
downloadctrl-v-712bf925f8ae84a5a2fee87b8aa3c969df48fd50.tar.xz
ctrl-v-712bf925f8ae84a5a2fee87b8aa3c969df48fd50.zip
allow language saving
Diffstat (limited to 'backend')
-rw-r--r--backend/api/routes.go4
-rw-r--r--backend/db/db.go9
-rw-r--r--backend/db/schemas.go5
3 files changed, 11 insertions, 7 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go
index 26c932f..d05e99a 100644
--- a/backend/api/routes.go
+++ b/backend/api/routes.go
@@ -28,12 +28,13 @@ func insertFunc(w http.ResponseWriter, r *http.Request) {
content := r.FormValue("content")
title := r.FormValue("title")
password := r.FormValue("password")
+ lang := r.FormValue("language")
// get ip
ip := getIP(r)
// insert content
- hash, err := db.New(ip, content, expiry, title, password)
+ hash, err := db.New(ip, content, expiry, title, password, lang)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "%s", err.Error())
@@ -99,6 +100,7 @@ func handleGetPaste(w http.ResponseWriter, r *http.Request, parsedPassword strin
"title": paste.Title,
"content": paste.Content,
"expiry": paste.Expiry,
+ "language": paste.Language,
}
jsonData, _ := json.Marshal(pasteMap)
diff --git a/backend/db/db.go b/backend/db/db.go
index df112d0..258b4df 100644
--- a/backend/db/db.go
+++ b/backend/db/db.go
@@ -28,7 +28,7 @@ const TitleLimit = 100
const ContentLimit = 100000
// creates a new paste with title, content and hash, returns the hash of the created paste
-func New(ip, content, expiry, title, password string) (string, error) {
+func New(ip, content, expiry, title, password, lang string) (string, error) {
// generate hash from ip
hash := security.GenerateURI(ip)
@@ -40,9 +40,10 @@ func New(ip, content, expiry, title, password string) (string, error) {
// create new struct
new := Paste{
- Hash: hash,
- Content: content,
- Title: title,
+ Hash: hash,
+ Content: content,
+ Title: title,
+ Language: lang,
}
// if there is a password, encrypt content and hash the password
diff --git a/backend/db/schemas.go b/backend/db/schemas.go
index d3551fc..a3b55d0 100644
--- a/backend/db/schemas.go
+++ b/backend/db/schemas.go
@@ -10,9 +10,10 @@ import (
type Paste struct {
ID bson.ObjectId `bson:"_id,omitempty"`
Hash string
- Content string
- Expiry time.Time `bson:"expiry"`
Title string
+ Content string
+ Language string
Password string
+ Expiry time.Time `bson:"expiry"`
Salt []byte
}