mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 08:44:25 +08:00
code refactor
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package avatars
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/pkg/models"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
||||
)
|
||||
|
||||
const internalAvatarUrlFormat = "%savatar/%d.%s"
|
||||
|
||||
// InternalStorageAvatarProvider represents the internal storage avatar provider
|
||||
type InternalStorageAvatarProvider struct {
|
||||
webRootUrl string
|
||||
}
|
||||
|
||||
// NewInternalStorageAvatarProvider returns a new internal storage avatar provider
|
||||
func NewInternalStorageAvatarProvider(config *settings.Config) *InternalStorageAvatarProvider {
|
||||
return &InternalStorageAvatarProvider{
|
||||
webRootUrl: config.RootUrl,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAvatarUrl returns the built-in avatar url
|
||||
func (p *InternalStorageAvatarProvider) GetAvatarUrl(user *models.User) string {
|
||||
if user.CustomAvatarType == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf(internalAvatarUrlFormat, p.webRootUrl, user.Uid, user.CustomAvatarType)
|
||||
}
|
||||
Reference in New Issue
Block a user