mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
bf1f06b79c
Expanding this as we go, currently have POC Backblaze B2 support and basic 'disk' provider as well. Still WIP, but functional for the most part. Also moving to simplified YAML configuration. Overall, simplifying things to be extensible down the line. Still work to be done, but coming along nicely.
42 lines
915 B
Go
42 lines
915 B
Go
package router
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/gmemstr/nas/common"
|
|
"github.com/gmemstr/nas/files"
|
|
"github.com/gorilla/mux"
|
|
"net/http"
|
|
)
|
|
|
|
func HandleProvider() common.Handler {
|
|
|
|
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
|
vars := mux.Vars(r)
|
|
if r.Method == "GET" {
|
|
providerCodename := vars["provider"]
|
|
var provider files.FileProviderInterface
|
|
files.TranslateProvider(providerCodename, &provider)
|
|
|
|
fileList := provider.GetDirectory("")
|
|
if vars["file"] != "" {
|
|
fileList = provider.GetDirectory(vars["file"])
|
|
}
|
|
data, err := json.Marshal(fileList)
|
|
if err != nil {
|
|
w.Write([]byte("An error occurred"))
|
|
return nil
|
|
}
|
|
w.Write(data)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func ListProviders() common.Handler {
|
|
|
|
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
|
|
return nil
|
|
}
|
|
}
|