4 Commits
869f09e139
...
b5c0c97008
Author | SHA1 | Message | Date |
---|---|---|---|
Roman Zipp |
b5c0c97008
|
Add get files endpoint readme docs
|
3 years ago |
Roman Zipp |
315c9adfca
|
Add check for directories in files endpoint
|
3 years ago |
Roman Zipp |
728f53c38f
|
Add get files endpoint
|
3 years ago |
Roman Zipp |
0ab6cf2b6e
|
Remove debug statement from upload endpoint test
|
3 years ago |
4 changed files with 126 additions and 3 deletions
-
25README.md
-
58controllers/file.go
-
6main.go
-
40main_test.go
@ -0,0 +1,58 @@ |
|||
package controllers |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"io/ioutil" |
|||
"net/http" |
|||
"time" |
|||
|
|||
"github.com/geplauder/lithium/pipelines" |
|||
"github.com/geplauder/lithium/settings" |
|||
"github.com/geplauder/lithium/storage" |
|||
) |
|||
|
|||
type File struct { |
|||
Bucket string `json:"bucket"` |
|||
FileName string `json:"file_name"` |
|||
Size int `json:"size"` |
|||
ModifiedAt time.Time `json:"modified_at"` |
|||
} |
|||
|
|||
func FileHandler(w http.ResponseWriter, r *http.Request, pipes []pipelines.IPipeline, storageProvider storage.IStorageProvider, appSettings settings.Settings) { |
|||
buckets, err := ioutil.ReadDir("./files/" + appSettings.StorageProvider.BasePath) |
|||
if err != nil { |
|||
json.NewEncoder(w).Encode(struct { |
|||
Files []File `json:"files"` |
|||
}{}) |
|||
return |
|||
} |
|||
|
|||
var files []File |
|||
|
|||
for _, b := range buckets { |
|||
if b.IsDir() == false { |
|||
continue |
|||
} |
|||
|
|||
bucketFiles, err := ioutil.ReadDir("./files/" + appSettings.StorageProvider.BasePath + "/" + b.Name()) |
|||
if err != nil { |
|||
writeError(w, 500, "Base path not found") |
|||
return |
|||
} |
|||
|
|||
for _, f := range bucketFiles { |
|||
if b.IsDir() == false { |
|||
continue |
|||
} |
|||
|
|||
files = append(files, File{b.Name(), f.Name(), int(f.Size()), f.ModTime()}) |
|||
} |
|||
} |
|||
|
|||
err = json.NewEncoder(w).Encode(struct { |
|||
Files []File `json:"files"` |
|||
}{files}) |
|||
if err != nil { |
|||
w.WriteHeader(http.StatusInternalServerError) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue