2020-02-24 18:07:47 +00:00
|
|
|
package files
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type FileProvider struct {
|
2020-03-15 23:48:37 +00:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
Provider string `yaml:"provider"`
|
|
|
|
Authentication string `yaml:"authentication"`
|
|
|
|
Location string `yaml:"path"`
|
|
|
|
Config map[string]string `yaml:"config"`
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Directory struct {
|
2020-03-15 23:48:37 +00:00
|
|
|
Path string
|
|
|
|
Files []FileInfo
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type FileInfo struct {
|
|
|
|
IsDirectory bool
|
|
|
|
Name string
|
|
|
|
Extension string
|
|
|
|
}
|
|
|
|
|
|
|
|
var Providers map[string]FileProvider
|
|
|
|
|
2020-03-15 23:48:37 +00:00
|
|
|
type FileContents struct {
|
|
|
|
Content []byte
|
|
|
|
IsUrl bool
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:07:47 +00:00
|
|
|
type FileProviderInterface interface {
|
|
|
|
GetDirectory(path string) Directory
|
2020-03-15 23:48:37 +00:00
|
|
|
ViewFile(path string) []byte
|
2020-02-24 18:07:47 +00:00
|
|
|
SaveFile(contents []byte, path string) bool
|
2020-03-15 23:48:37 +00:00
|
|
|
DetermineType(path string) string
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TranslateProvider(codename string, i *FileProviderInterface) {
|
|
|
|
provider := Providers[codename]
|
|
|
|
if codename == "disk" {
|
|
|
|
*i = &DiskProvider{provider,}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if codename == "backblaze" {
|
2020-03-15 23:48:37 +00:00
|
|
|
bbProv := &BackblazeProvider{provider, provider.Config["bucket"], ""}
|
2020-02-24 18:07:47 +00:00
|
|
|
|
|
|
|
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{}
|
|
|
|
}
|
|
|
|
|
2020-03-15 23:48:37 +00:00
|
|
|
func (f FileProvider) ViewFile(path string) []byte {
|
|
|
|
return nil
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileProvider) SaveFile(contents []byte, path string) bool {
|
|
|
|
return false
|
2020-03-15 23:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileProvider) DetermineType(path string) string {
|
|
|
|
return ""
|
|
|
|
}
|