sliproad/files/fileprovider.go
Gabriel Simmer ea1075cb5b
Rewrite file provider to proxy data download (rather than redirect)
Reworked the fileprovider to proxy data directly from the provider
rather than attempt to funkily redirect when needed, since it was overly
complex and wouldn't work well in the long run. Temporarily added "file"
as constant return for determining the filetype through Backblaze.

Added a Makefile to make life easier as well, and rewrote the README to
reflect the refactor/rewrite and new approach to providers.
2020-03-15 23:49:00 +00:00

73 lines
1.5 KiB
Go

package files
import "fmt"
type FileProvider struct {
Name string `yaml:"name"`
Provider string `yaml:"provider"`
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 FileContents struct {
Content []byte
IsUrl bool
}
type FileProviderInterface interface {
GetDirectory(path string) Directory
ViewFile(path string) []byte
SaveFile(contents []byte, path string) bool
DetermineType(path string) string
}
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) []byte {
return nil
}
func (f FileProvider) SaveFile(contents []byte, path string) bool {
return false
}
func (f FileProvider) DetermineType(path string) string {
return ""
}