forked from electricdusk/rushlink
parent
40a32fa535
commit
728b5d9d4b
@ -1,5 +1,5 @@
|
||||
{{if .Request.PostForm.deleteToken -}}
|
||||
https://{{.Request.Host}}/{{.Paste.Key}}?deleteToken={{.Paste.DeleteToken | urlquery}}
|
||||
https://{{.Request.Host}}/{{.Paste.Key}}{{.FileExt}}?deleteToken={{.Paste.DeleteToken | urlquery}}
|
||||
{{else -}}
|
||||
https://{{.Request.Host}}/{{.Paste.Key}}
|
||||
https://{{.Request.Host}}/{{.Paste.Key}}{{.FileExt}}
|
||||
{{end -}}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"gitea.hashru.nl/dsprenkels/rushlink/internal/db"
|
||||
@ -209,7 +210,10 @@ func (rl *rushlink) newFileUploadPasteHandler(w http.ResponseWriter, r *http.Req
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := map[string]interface{}{"Paste": paste}
|
||||
data := map[string]interface{}{
|
||||
"Paste": paste,
|
||||
"FileUpload": fu,
|
||||
"FileExt": filepath.Ext(fu.FileName)}
|
||||
render(w, r, "newFileUploadPasteSuccess", data)
|
||||
}
|
||||
|
||||
|
20
router.go
20
router.go
@ -12,6 +12,9 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const urlKeyExpr = "{key:[A-Za-z0-9-_]{4,}}"
|
||||
const urlKeyWithExtExpr = urlKeyExpr + "{ext:\\.[A-Za-z0-9-_]+}"
|
||||
|
||||
type rushlink struct {
|
||||
db *db.Database
|
||||
fs *db.FileStore
|
||||
@ -79,14 +82,19 @@ func StartMainServer(addr string, db *db.Database, fs *db.FileStore) {
|
||||
router := mux.NewRouter()
|
||||
router.Use(recoveryMiddleware)
|
||||
router.Use(metricsMiddleware)
|
||||
router.HandleFunc("/uploads/{id:[A-Za-z0-9-_]+}/{filename:.+}", rl.uploadFileGetHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/", rl.indexGetHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/", rl.newPasteHandler).Methods("POST")
|
||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.viewPasteHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/nr", rl.viewPasteHandlerNoRedirect).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/meta", rl.viewPasteHandlerMeta).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.deletePasteHandler).Methods("DELETE")
|
||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/delete", rl.deletePasteHandler).Methods("POST")
|
||||
router.HandleFunc("/uploads/{id:[A-Za-z0-9-_]+}/{filename:.+}", rl.uploadFileGetHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyExpr, rl.viewPasteHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyWithExtExpr, rl.viewPasteHandler).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyExpr+"/nr", rl.viewPasteHandlerNoRedirect).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyWithExtExpr+"/nr", rl.viewPasteHandlerNoRedirect).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyExpr+"/meta", rl.viewPasteHandlerMeta).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyWithExtExpr+"/meta", rl.viewPasteHandlerMeta).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/"+urlKeyExpr, rl.deletePasteHandler).Methods("DELETE")
|
||||
router.HandleFunc("/"+urlKeyWithExtExpr, rl.deletePasteHandler).Methods("DELETE")
|
||||
router.HandleFunc("/"+urlKeyExpr+"/delete", rl.deletePasteHandler).Methods("POST")
|
||||
router.HandleFunc("/"+urlKeyWithExtExpr+"/delete", rl.deletePasteHandler).Methods("POST")
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: router,
|
||||
|
Loading…
Reference in New Issue
Block a user