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