This commit is contained in:
a 2022-08-03 05:21:56 -05:00
parent 5c2c358ff3
commit 0dfd668894
6 changed files with 25 additions and 11 deletions

View File

@ -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

BIN
db.sqlite

Binary file not shown.

View File

@ -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
}

View File

@ -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"

4
readme.md Normal file
View File

@ -0,0 +1,4 @@
# paste server i guess
whatever

View File

@ -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");