mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
bf1f06b79c
Expanding this as we go, currently have POC Backblaze B2 support and basic 'disk' provider as well. Still WIP, but functional for the most part. Also moving to simplified YAML configuration. Overall, simplifying things to be extensible down the line. Still work to be done, but coming along nicely.
49 lines
924 B
Go
49 lines
924 B
Go
package files
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type DiskProvider struct{
|
|
FileProvider
|
|
}
|
|
|
|
func (dp *DiskProvider) GetDirectory(path string) Directory {
|
|
rp := strings.Join([]string{dp.Location,path}, "/")
|
|
fileDir, err := ioutil.ReadDir(rp)
|
|
if err != nil {
|
|
_ = os.MkdirAll(path, 0644)
|
|
}
|
|
var fileList []FileInfo
|
|
|
|
for _, file := range fileDir {
|
|
info := FileInfo{
|
|
IsDirectory: file.IsDir(),
|
|
Name: file.Name(),
|
|
}
|
|
if !info.IsDirectory {
|
|
split := strings.Split(file.Name(), ".")
|
|
info.Extension = split[len(split) - 1]
|
|
}
|
|
fileList = append(fileList, info)
|
|
}
|
|
|
|
return Directory{
|
|
Path: rp,
|
|
Files: fileList,
|
|
}
|
|
}
|
|
|
|
func (dp *DiskProvider) ViewFile(path string) string {
|
|
return strings.Join([]string{dp.Location,path}, "/")
|
|
}
|
|
|
|
func (dp *DiskProvider) SaveFile(contents []byte, path string) bool {
|
|
err := ioutil.WriteFile(path, contents, 0600)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
} |