feat: add longer url if "secret" field is present

This commit is contained in:
jabuxas 2024-10-29 17:51:27 -03:00
parent 6a2bf1ea4a
commit e216e2a1b5

View File

@ -160,6 +160,10 @@ func (app *Application) formHandler(w http.ResponseWriter, r *http.Request) {
filename := app.publicURL(file, ".txt") filename := app.publicURL(file, ".txt")
if len(r.Form["secret"]) == 0 {
filename = filename[:8]
}
// reopening file because hash consumes it // reopening file because hash consumes it
file, err = os.Open("/tmp/file.txt") file, err = os.Open("/tmp/file.txt")
if err != nil { if err != nil {
@ -196,6 +200,10 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) {
filename := app.publicURL(file, filepath.Ext(handler.Filename)) filename := app.publicURL(file, filepath.Ext(handler.Filename))
if len(r.Form["secret"]) == 0 {
filename = filename[:8]
}
// reopen the file for copying, as the hash process consumed the file reader // reopen the file for copying, as the hash process consumed the file reader
file, _, err = r.FormFile("file") file, _, err = r.FormFile("file")
if err != nil { if err != nil {
@ -204,8 +212,7 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) {
} }
defer file.Close() defer file.Close()
err = SaveFile(app.lastUploadedFile, file) if err = SaveFile(app.lastUploadedFile, file); err != nil {
if err != nil {
fmt.Fprintf(w, "Error parsing file: %s", err.Error()) fmt.Fprintf(w, "Error parsing file: %s", err.Error())
} }