mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
c2171d00c9
Should offer some speed boost, copying the file contents rather than reading it all to memory then writing it back out. Should theoretically be able to handle larger files as well, although some benchmarks are TBD around filesize limits.
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
package files
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
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, w io.Writer)
|
|
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
|
|
}
|
|
/*
|
|
* @TODO: It would be ideal if the authorization with Backblaze was done before
|
|
* actually needing to use it, ideally during the startup step.
|
|
*/
|
|
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, w io.Writer) {
|
|
return
|
|
}
|
|
|
|
func (f FileProvider) SaveFile(contents []byte, path string) bool {
|
|
return false
|
|
}
|
|
|
|
func (f FileProvider) DetermineType(path string) string {
|
|
return ""
|
|
}
|