mirror of
https://github.com/elyby/chrly.git
synced 2024-11-19 11:43:06 +05:30
34 lines
527 B
Go
34 lines
527 B
Go
package fs
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/elyby/chrly/model"
|
|
)
|
|
|
|
func New(basePath string) (*Filesystem, error) {
|
|
return &Filesystem{path: basePath}, nil
|
|
}
|
|
|
|
type Filesystem struct {
|
|
path string
|
|
}
|
|
|
|
func (f *Filesystem) FindCapeByUsername(username string) (*model.Cape, error) {
|
|
capePath := path.Join(f.path, strings.ToLower(username)+".png")
|
|
file, err := os.Open(capePath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
|
|
return nil, err
|
|
}
|
|
|
|
return &model.Cape{
|
|
File: file,
|
|
}, nil
|
|
}
|