diff --git a/cmd/server/main.go b/cmd/server/main.go index 4f288ae..8f27503 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -279,7 +279,6 @@ func (s *Server) APIHandler(w http.ResponseWriter, r *http.Request) { // pasteHandler generates the html paste pages func (s *Server) pasteHandler(w http.ResponseWriter, r *http.Request) { - pasteId := chi.URLParam(r, "pasteId") lang := chi.URLParam(r, "lang") style := chi.URLParam(r, "style") @@ -288,12 +287,14 @@ func (s *Server) pasteHandler(w http.ResponseWriter, r *http.Request) { p, err := s.store.GetPaste(r.Context(), pasteId) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } // Run it through the highgligther., p.Paste, p.Extra, p.Lang, p.Style, err = s.styler.Highlight(p.Paste, lang, style) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } l := s.styler.Legacy() @@ -331,7 +332,7 @@ func (s *Server) CloneHandler(w http.ResponseWriter, r *http.Request) { return } - user, _ := s.store.GetUserKey(r.Context(), paste) + user, _ := s.getUserKey(r) page := &Page{ Body: template.HTML(p.Paste), PasteTitle: "Copy of " + p.Title, @@ -428,7 +429,6 @@ func (s *Server) pastesHandler(w http.ResponseWriter, r *http.Request) { key, err := s.getUserKey(r) b, err := s.store.GetUserPastes(r.Context(), key) - err = templates.ExecuteTemplate(w, "pastes.html", &b) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -440,11 +440,11 @@ func (s *Server) getUserKey(r *http.Request) (string, error) { cookie, err := r.Cookie("session") cookieValue := make(map[string]string) if err != nil { - return "", err + return "", nil } err = cookieHandler.Decode("session", cookie.Value, &cookieValue) if err != nil { - return "", err + return "", nil } email := cookieValue["email"] // Query database if id exists and if it does call generateName again diff --git a/db.sqlite b/db.sqlite index 1addabc..17c0a34 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/lib/store/sqlike/sqlike.go b/lib/store/sqlike/sqlike.go index babb9fa..48146bb 100644 --- a/lib/store/sqlike/sqlike.go +++ b/lib/store/sqlike/sqlike.go @@ -148,6 +148,9 @@ func (s *Sqlike) SavePaste(ctx context.Context, title string, data string, expir id = idgen.MustGenerate() expiretime := time.Now().Add(expiry) + if expiry == 0 { + expiretime = time.Time{} + } // Set the generated id as title if not given, if title == "" { title = id @@ -167,7 +170,7 @@ func (s *Sqlike) SavePaste(ctx context.Context, title string, data string, expir return nil, err } - _, err = stmt.Exec(id, title, sha, data, delKey, expiretime, userKey) + _, err = stmt.Exec(id, title, sha, data, delKey, expiretime.Unix(), userKey) if err != nil { return nil, err } diff --git a/lib/styler/styler.go b/lib/styler/styler.go index 33b82c4..8195462 100644 --- a/lib/styler/styler.go +++ b/lib/styler/styler.go @@ -98,9 +98,17 @@ func (s *Styler) Highlight(paste string, lang string, style string) (string, str lang = sanitize(lang) style = sanitize(style) lang, supported_lang = s.listOfLangsFirst[lang] + if supported_lang { + lang = sanitize(lang) + } else { + lang = "" + } style, supported_styles = s.listOfStyles[style] - lang = sanitize(lang) - style = sanitize(style) + if supported_styles { + style = sanitize(style) + } else { + style = "" + } if lang == "" { lang = "autodetect" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a73a983 --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +# paste server i guess + + +whatever diff --git a/static/index.html b/static/index.html index 62da059..9e1df52 100644 --- a/static/index.html +++ b/static/index.html @@ -162,13 +162,12 @@ }); $( "#button-save" ).click(function() { - // Construct the data, var data_lang = $("#button-language").attr("value"); var data_expiry = $("#button-expiry").attr("value"); var data_title = $("#title").val(); var data_paste = $("#paste").val(); - var user_key = {{.UserKey}}; + var user_key = {{.UserKey}}; var json_data = { expiry : data_expiry, title : data_title, @@ -184,7 +183,7 @@ data: JSON.stringify(json_data), dataType: "json", success: function(json){ - window.location = json.url+"/"+data_lang + window.location = "/p/"+json.id }, error: function(json){ sweetAlert("", json.responseText, "error");