Add download handler
This commit is contained in:
parent
cb27aab401
commit
98ded1615a
11
main.go
11
main.go
|
@ -256,6 +256,13 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func cloneHandler(w http.ResponseWriter, r *http.Request) {
|
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)
|
||||||
|
paste := vars["pasteId"]
|
||||||
|
s := getPaste(paste, "")
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename="+paste)
|
||||||
|
w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
||||||
|
io.Copy(w, s)
|
||||||
|
|
||||||
}
|
}
|
||||||
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
@ -270,8 +277,8 @@ func main() {
|
||||||
router.HandleFunc("/p/{pasteId}", pasteHandler)
|
router.HandleFunc("/p/{pasteId}", pasteHandler)
|
||||||
router.HandleFunc("/raw/{pasteId}", rawHandler)
|
router.HandleFunc("/raw/{pasteId}", rawHandler)
|
||||||
router.HandleFunc("/p/{pasteId}/{lang}", pasteHandler)
|
router.HandleFunc("/p/{pasteId}/{lang}", pasteHandler)
|
||||||
router.HandleFunc("/{clone}/{pasteId}", cloneHandler)
|
router.HandleFunc("/clone/{pasteId}", cloneHandler)
|
||||||
router.HandleFunc("/{download}/{pasteId}", downloadHandler)
|
router.HandleFunc("/download/{pasteId}", downloadHandler)
|
||||||
router.HandleFunc("/save", saveHandler)
|
router.HandleFunc("/save", saveHandler)
|
||||||
router.HandleFunc("/save/{output}", saveHandler)
|
router.HandleFunc("/save/{output}", saveHandler)
|
||||||
router.HandleFunc("/del/{pasteId}/{delKey}", delHandler)
|
router.HandleFunc("/del/{pasteId}/{delKey}", delHandler)
|
||||||
|
|
Loading…
Reference in New Issue