51 lines
1 KiB
Go
51 lines
1 KiB
Go
package apiv1
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func (a *API) getFilelistHandler(w http.ResponseWriter, r *http.Request) {
|
|
pauth := r.PathValue("pauth")
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
form := r.PostForm
|
|
if form.Has("pauth") {
|
|
pauth = form.Get("pauth")
|
|
}
|
|
|
|
files, err := a.idec.FilesList(pauth)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
|
|
for _, file := range files {
|
|
fmt.Fprintf(w, "%s:%d:%s\n", file.FullName, file.Size, file.Name)
|
|
}
|
|
}
|
|
|
|
func (a *API) getFileHandler(w http.ResponseWriter, r *http.Request) {
|
|
filename := r.PathValue("filename")
|
|
pauth := ""
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
form := r.PostForm
|
|
if form.Has("pauth") {
|
|
pauth = form.Get("pauth")
|
|
}
|
|
if form.Has("filename") {
|
|
filename = form.Get("filename")
|
|
}
|
|
|
|
if err := a.idec.GetFile(pauth, filename, w); err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|