Add title support
This commit is contained in:
parent
da55f3847c
commit
dc1ad54fa3
22
main.go
22
main.go
|
@ -213,11 +213,11 @@ func highlight(s string, lang string) (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPaste(paste string, lang string) string {
|
func getPaste(paste string, lang string) (string, string) {
|
||||||
param1 := html.EscapeString(paste)
|
param1 := html.EscapeString(paste)
|
||||||
db, err := sql.Open("mysql", DATABASE)
|
db, err := sql.Open("mysql", DATABASE)
|
||||||
var s string
|
var title, s string
|
||||||
err = db.QueryRow("select data from pastebin where id=?", param1).Scan(&s)
|
err = db.QueryRow("select title, data from pastebin where id=?", param1).Scan(&title, &s)
|
||||||
db.Close()
|
db.Close()
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
@ -225,11 +225,11 @@ func getPaste(paste string, lang string) string {
|
||||||
return "Error invalid paste"
|
return "Error invalid paste"
|
||||||
} else {
|
} else {
|
||||||
if lang == "" {
|
if lang == "" {
|
||||||
return html.UnescapeString(s)
|
return html.UnescapeString(s), title
|
||||||
} else {
|
} else {
|
||||||
high, err := highlight(s, lang)
|
high, err := highlight(s, lang)
|
||||||
check(err)
|
check(err)
|
||||||
return high
|
return high, title
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,13 +243,13 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
paste := vars["pasteId"]
|
paste := vars["pasteId"]
|
||||||
lang := vars["lang"]
|
lang := vars["lang"]
|
||||||
s := getPaste(paste, lang)
|
s, title := getPaste(paste, lang)
|
||||||
link := ADDRESS + "/raw/" + paste
|
link := ADDRESS + "/raw/" + paste
|
||||||
download := ADDRESS + "/download/" + paste
|
download := ADDRESS + "/download/" + paste
|
||||||
clone := ADDRESS + "/clone/" + paste
|
clone := ADDRESS + "/clone/" + paste
|
||||||
if lang == "" {
|
if lang == "" {
|
||||||
p := &Page{
|
p := &Page{
|
||||||
Title: paste,
|
Title: title,
|
||||||
Body: []byte(s),
|
Body: []byte(s),
|
||||||
Raw: link,
|
Raw: link,
|
||||||
Home: ADDRESS,
|
Home: ADDRESS,
|
||||||
|
@ -270,12 +270,12 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func cloneHandler(w http.ResponseWriter, r *http.Request) {
|
func cloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
paste := vars["pasteId"]
|
paste := vars["pasteId"]
|
||||||
s := getPaste(paste, "")
|
s, title := getPaste(paste, "")
|
||||||
link := ADDRESS + "/raw/" + paste
|
link := ADDRESS + "/raw/" + paste
|
||||||
download := ADDRESS + "/download/" + paste
|
download := ADDRESS + "/download/" + paste
|
||||||
clone := ADDRESS + "/clone/" + paste
|
clone := ADDRESS + "/clone/" + paste
|
||||||
p := &Page{
|
p := &Page{
|
||||||
Title: paste,
|
Title: title,
|
||||||
Body: []byte(s),
|
Body: []byte(s),
|
||||||
Raw: link,
|
Raw: link,
|
||||||
Home: ADDRESS,
|
Home: ADDRESS,
|
||||||
|
@ -291,7 +291,7 @@ func cloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func downloadHandler(w http.ResponseWriter, r *http.Request) {
|
func downloadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
paste := vars["pasteId"]
|
paste := vars["pasteId"]
|
||||||
s := getPaste(paste, "")
|
s, _ := getPaste(paste, "")
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename="+paste)
|
w.Header().Set("Content-Disposition", "attachment; filename="+paste)
|
||||||
w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
||||||
io.WriteString(w, s)
|
io.WriteString(w, s)
|
||||||
|
@ -300,7 +300,7 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
paste := vars["pasteId"]
|
paste := vars["pasteId"]
|
||||||
s := getPaste(paste, "")
|
s, _ := getPaste(paste, "")
|
||||||
io.WriteString(w, s)
|
io.WriteString(w, s)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue