2020-02-24 18:07:47 +00:00
|
|
|
package files
|
|
|
|
|
2020-03-19 10:13:38 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2020-02-24 18:07:47 +00:00
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// FileIsRemote denotes whether file is a remote file.
|
|
|
|
const FileIsRemote = "remote"
|
2020-04-15 23:19:33 +01:00
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// FileIsLocal denotes whether file is a local file.
|
|
|
|
const FileIsLocal = "local"
|
|
|
|
|
|
|
|
// FileProvider aggregates some very basic properties for authentication and
|
|
|
|
// provider decoding.
|
2020-02-24 18:07:47 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// Directory contains the path and a collection of FileInfos.
|
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
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// FileInfo describes a single file or directory, doing it's best to
|
|
|
|
// figure out the extension as well.
|
2020-02-24 18:07:47 +00:00
|
|
|
type FileInfo struct {
|
|
|
|
IsDirectory bool
|
|
|
|
Name string
|
|
|
|
Extension string
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// FileProviderInterface provides some sane default functions.
|
2020-02-24 18:07:47 +00:00
|
|
|
type FileProviderInterface interface {
|
2020-04-15 23:19:33 +01:00
|
|
|
Setup(args map[string]string) (ok bool)
|
|
|
|
GetDirectory(path string) (directory Directory)
|
|
|
|
FilePath(path string) (realpath string)
|
2020-04-15 12:16:27 +01:00
|
|
|
RemoteFile(path string, writer io.Writer)
|
2020-04-15 23:19:33 +01:00
|
|
|
SaveFile(file io.Reader, filename string, path string) (ok bool)
|
|
|
|
ObjectInfo(path string) (exists bool, isDir bool, location string)
|
|
|
|
CreateDirectory(path string) (ok bool)
|
|
|
|
Delete(path string) (ok bool)
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 00:31:24 +00:00
|
|
|
/** DO NOT USE THESE DEFAULTS **/
|
2020-04-24 09:01:53 +01:00
|
|
|
|
|
|
|
// Setup runs when the application starts up, and allows for things like authentication.
|
2020-03-21 00:31:24 +00:00
|
|
|
func (f FileProvider) Setup(args map[string]string) bool {
|
|
|
|
return false
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// GetDirectory fetches a directory's contents.
|
2020-02-24 18:07:47 +00:00
|
|
|
func (f FileProvider) GetDirectory(path string) Directory {
|
|
|
|
return Directory{}
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// FilePath returns the path to the file, whether it be a URL or local file path.
|
2020-04-15 23:19:33 +01:00
|
|
|
func (f FileProvider) FilePath(path string) string {
|
2020-04-15 12:16:27 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// RemoteFile will bypass http.ServeContent() and instead write directly to the response.
|
2020-04-15 12:16:27 +01:00
|
|
|
func (f FileProvider) RemoteFile(path string, writer io.Writer) {
|
2020-03-19 10:13:38 +00:00
|
|
|
return
|
2020-02-24 18:07:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// SaveFile will save a file with the contents of the io.Reader at the path specified.
|
2020-04-03 13:26:06 +01:00
|
|
|
func (f FileProvider) SaveFile(file io.Reader, filename string, path string) bool {
|
2020-02-24 18:07:47 +00:00
|
|
|
return false
|
2020-03-15 23:48:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// ObjectInfo will return the info for an object given a path to if the file exists and location.
|
|
|
|
// Should return whether the path exists, if the path is a directory, and if it lives on disk.
|
|
|
|
// (see constants defined: `FILE_IS_REMOTE` and `FILE_IS_LOCAL`)
|
2020-04-15 23:19:33 +01:00
|
|
|
func (f FileProvider) ObjectInfo(path string) (bool, bool, string) {
|
|
|
|
return false, false, ""
|
2020-03-15 23:48:37 +00:00
|
|
|
}
|
2020-03-21 00:31:24 +00:00
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// CreateDirectory will create a directory on services that support it.
|
2020-04-12 22:10:51 +01:00
|
|
|
func (f FileProvider) CreateDirectory(path string) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-04-24 09:01:53 +01:00
|
|
|
// Delete simply deletes a file. This is expected to be a destructive action by default.
|
2020-04-12 22:10:51 +01:00
|
|
|
func (f FileProvider) Delete(path string) bool {
|
|
|
|
return false
|
2020-04-24 09:01:53 +01:00
|
|
|
}
|