feat: add /last for checking last uploaded file
This commit is contained in:
parent
468fb823e9
commit
4ed73c3086
1
abyss.go
1
abyss.go
@ -56,6 +56,7 @@ func main() {
|
||||
"/tree/",
|
||||
app.basicAuth(app.treeHandler),
|
||||
)
|
||||
mux.HandleFunc("/last", app.lastHandler)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: app.port,
|
||||
|
19
handlers.go
19
handlers.go
@ -16,10 +16,11 @@ type Application struct {
|
||||
username string
|
||||
password string
|
||||
}
|
||||
url string
|
||||
key string
|
||||
filesDir string
|
||||
port string
|
||||
url string
|
||||
key string
|
||||
filesDir string
|
||||
port string
|
||||
lastUploadedFile string
|
||||
}
|
||||
|
||||
func (app *Application) treeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@ -47,6 +48,14 @@ func (app *Application) indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *Application) lastHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if app.lastUploadedFile == "" {
|
||||
http.Error(w, "No new files uploaded yet", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, app.lastUploadedFile)
|
||||
}
|
||||
|
||||
func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.Error(w, "Method not allowed", http.StatusUnauthorized)
|
||||
@ -87,6 +96,8 @@ func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Error copying the file", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
app.lastUploadedFile = filepath
|
||||
|
||||
if app.url == "" {
|
||||
fmt.Fprintf(w, "http://localhost%s/%s\n", app.port, filename)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user