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.
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package files
|
|
|
|
import "fmt"
|
|
|
|
type FileProvider struct {
|
|
Name string `yaml:"name"`
|
|
Authentication string `yaml:"authentication"`
|
|
Location string `yaml:"path"`
|
|
Config map[string]string `yaml:"config"`
|
|
}
|
|
|
|
type Directory struct {
|
|
Path string
|
|
Files []FileInfo
|
|
}
|
|
|
|
type FileInfo struct {
|
|
IsDirectory bool
|
|
Name string
|
|
Extension string
|
|
}
|
|
|
|
var Providers map[string]FileProvider
|
|
|
|
type FileProviderInterface interface {
|
|
GetDirectory(path string) Directory
|
|
ViewFile(path string) string
|
|
SaveFile(contents []byte, path string) bool
|
|
}
|
|
|
|
func TranslateProvider(codename string, i *FileProviderInterface) {
|
|
provider := Providers[codename]
|
|
if codename == "disk" {
|
|
*i = &DiskProvider{provider,}
|
|
return
|
|
}
|
|
if codename == "backblaze" {
|
|
bbProv := &BackblazeProvider{provider, provider.Config["bucket"]}
|
|
|
|
err := bbProv.Authorize(provider.Config["appKeyId"], provider.Config["appId"])
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
*i = bbProv
|
|
return
|
|
}
|
|
*i = FileProvider{}
|
|
}
|
|
|
|
/** DO NOT USE THESE DEFAULTS **/
|
|
func (f FileProvider) GetDirectory(path string) Directory {
|
|
return Directory{}
|
|
}
|
|
|
|
func (f FileProvider) ViewFile(path string) string {
|
|
return ""
|
|
}
|
|
|
|
func (f FileProvider) SaveFile(contents []byte, path string) bool {
|
|
return false
|
|
} |