@@ -21,7 +21,7 @@ import (
|
||||
|
||||
var ErrNotAnImage = errors.New("not an image")
|
||||
|
||||
func (s *Service) getMime(path string) (mimeType string, err error) {
|
||||
func (s *Service) GetMime(path string) (mimeType string, err error) {
|
||||
info, err := s.fs.Stat(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("image file info could not be fetched: %w", err)
|
||||
@@ -35,13 +35,12 @@ func (s *Service) getMime(path string) (mimeType string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) getImage(uid string) (file []byte, mimeType string, err error) {
|
||||
path, err := PathFromUID(uid)
|
||||
func (s *Service) getImage(path string) (file []byte, mimeType string, err error) {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not get path: %w", err)
|
||||
return
|
||||
}
|
||||
mimeType, err = s.getMime(path)
|
||||
mimeType, err = s.GetMime(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -59,7 +58,19 @@ func (s *Service) getImage(uid string) (file []byte, mimeType string, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) GetImage(ctx context.Context, uid string, options Options) (img io.Reader, mimeType string, err error) {
|
||||
func (s *Service) GetImage(path string) (img Image, err error) {
|
||||
rawImage, _, err := s.getImage(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
img.Path = path
|
||||
img.Image, _, err = image.Decode(bytes.NewBuffer(rawImage))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) GetScaledImage(ctx context.Context, uid string, options Options) (img io.Reader, mimeType string, err error) {
|
||||
if err = s.seph.Acquire(ctx, 1); err != nil {
|
||||
err = fmt.Errorf("could not Acquire semaphore: %w", err)
|
||||
return
|
||||
@@ -67,7 +78,12 @@ func (s *Service) GetImage(ctx context.Context, uid string, options Options) (im
|
||||
}
|
||||
defer s.seph.Release(1)
|
||||
|
||||
rawImage, mimeType, err := s.getImage(uid)
|
||||
path, err := PathFromUID(uid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rawImage, mimeType, err := s.getImage(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user