mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
d86ed1233f
Implemented file uploading for both the disk and Backblaze providers. Also implements a UI element and frontend logic for doing so from the frontend. Disk will write directly to disk, while the Backblaze provider will attempt to stream the file from memory directly to the POST body. This could introduce some problems down the line, so caching to disk then uploading in the background may need to be implemented. It also performs the final upload using a goroutine so the end client can continue on it's merry way. Backblaze proved a bit tricky to do, and considering switching to using a library for managing Backblaze going forward.
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package files
|
|
|
|
import (
|
|
"io"
|
|
"mime/multipart"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
type FileContents struct {
|
|
Content []byte
|
|
IsUrl bool
|
|
}
|
|
|
|
type FileProviderInterface interface {
|
|
Setup(args map[string]string) bool
|
|
GetDirectory(path string) Directory
|
|
ViewFile(path string, w io.Writer)
|
|
SaveFile(file multipart.File, handler *multipart.FileHeader, path string) bool
|
|
DetermineType(path string) string
|
|
}
|
|
|
|
/** DO NOT USE THESE DEFAULTS **/
|
|
func (f FileProvider) Setup(args map[string]string) bool {
|
|
return false
|
|
}
|
|
|
|
func (f FileProvider) GetDirectory(path string) Directory {
|
|
return Directory{}
|
|
}
|
|
|
|
func (f FileProvider) ViewFile(path string, w io.Writer) {
|
|
return
|
|
}
|
|
|
|
func (f FileProvider) SaveFile(file multipart.File, handler *multipart.FileHeader, path string) bool {
|
|
return false
|
|
}
|
|
|
|
func (f FileProvider) DetermineType(path string) string {
|
|
return ""
|
|
}
|
|
|