summaryrefslogtreecommitdiff
path: root/pkg/apiv1/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/apiv1/file.go')
-rw-r--r--pkg/apiv1/file.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/pkg/apiv1/file.go b/pkg/apiv1/file.go
new file mode 100644
index 0000000..eb1a8d8
--- /dev/null
+++ b/pkg/apiv1/file.go
@@ -0,0 +1,51 @@
+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)
+ }
+}