supports local file system object storage and use it as the default avatar provider

This commit is contained in:
MaysWind
2024-07-27 23:29:18 +08:00
parent 731b6e8bad
commit 2e04affb00
26 changed files with 858 additions and 29 deletions
+43
View File
@@ -3,9 +3,29 @@ package utils
import (
"io"
"os"
"path/filepath"
"strings"
)
var imageFileExtensionContentTypeMap = map[string]string{
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"png": "image/png",
"gif": "image/gif",
"webp": "image/webp",
}
// GetImageContentType returns the content type of specified image file extension or returns empty when the file extension is not image or not supported
func GetImageContentType(fileExtension string) string {
contentType, exists := imageFileExtensionContentTypeMap[fileExtension]
if !exists {
return ""
}
return contentType
}
// ListFileNamesWithPrefixAndSuffix returns file name list which has specified prefix and suffix
func ListFileNamesWithPrefixAndSuffix(path string, prefix string, suffix string) []string {
dir, err := os.Open(path)
@@ -69,6 +89,29 @@ func WriteFile(path string, data []byte) error {
return err
}
// GetFileNameWithoutExtension returns the file name without extension
func GetFileNameWithoutExtension(path string) string {
fileName := filepath.Base(path)
extension := filepath.Ext(fileName)
if len(extension) < 1 {
return fileName
}
return fileName[0 : len(fileName)-len(extension)]
}
// GetFileNameExtension returns the file extension without dot
func GetFileNameExtension(path string) string {
extension := filepath.Ext(path)
if len(extension) < 1 || extension[0] != '.' {
return extension
}
return extension[1:]
}
// IdentReader returns the original io reader
func IdentReader(encoding string, input io.Reader) (io.Reader, error) {
return input, nil