mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Rework db layer.
Add database checker. Rename SkinsRepositoryInterface and CapesRepositoryInterface methods.
This commit is contained in:
37
db/fs/fs.go
Normal file
37
db/fs/fs.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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) {
|
||||
if username == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user