package app import ( "encoding/base64" "fmt" "net/http" "path/filepath" ) func (app *App) Routes() *http.ServeMux { mux := http.NewServeMux() fileServer := http.FileServer(http.Dir("./web/static")) mux.Handle("GET /static/", http.StripPrefix("/static/", fileServer)) mux.HandleFunc("GET /{$}", app.HandleHome) mux.HandleFunc("POST /{$}", app.HandleUpload) mux.HandleFunc("POST /upload/chunk", app.HandleChunk) mux.HandleFunc("POST /upload/finish", app.HandleFinish) mux.HandleFunc("GET /{slug}", app.HandleGetFile) return mux } func (app *App) RespondWithLink(writer http.ResponseWriter, request *http.Request, key []byte, originalName string) { keySlug := base64.RawURLEncoding.EncodeToString(key) ext := filepath.Ext(originalName) link := fmt.Sprintf("%s/%s%s", request.Host, keySlug, ext) if request.Header.Get("X-Requested-With") == "XMLHttpRequest" { html := `