mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 19:16:24 +00:00
- Introduced new CSS files for rose, violet, and yellow themes with custom color variables. - Implemented dark mode styles for each theme. - Created a color data structure to manage theme colors in the console settings. feat: implement image cropper component - Added an image cropper component for user profile picture editing. - Integrated the image cropper into the user profile page. feat: enhance console sidebar with user permissions - Defined sidebar items with permission checks for admin and editor roles. - Updated user center navigation to reflect user permissions. feat: add user profile and security settings - Developed user profile page with avatar upload and editing functionality. - Implemented user security settings for password and email verification. feat: create reusable dialog and OTP input components - Built a dialog component for modal interactions. - Developed an OTP input component for email verification. fix: improve file handling utilities - Added utility functions for file URI generation. - Implemented permission checks for user roles in the common utilities.
32 lines
640 B
Go
32 lines
640 B
Go
package utils
|
||
|
||
import (
|
||
"crypto/sha256"
|
||
"encoding/hex"
|
||
"io"
|
||
"mime/multipart"
|
||
)
|
||
|
||
// FilePath 根据哈希值生成文件路径,前4位为目录位hash[0:4]/hash
|
||
func FilePath(hash string) (dir, file string) {
|
||
dir = hash[0:4]
|
||
file = hash
|
||
return
|
||
}
|
||
|
||
func FileHashFromStream(file multipart.File) (string, error) {
|
||
// 创建哈希计算器
|
||
hash := sha256.New()
|
||
|
||
// 将文件流内容拷贝到哈希计算器
|
||
if _, err := io.Copy(hash, file); err != nil {
|
||
return "", err
|
||
}
|
||
|
||
// 计算哈希值并转换为十六进制字符串
|
||
hashInBytes := hash.Sum(nil)
|
||
hashString := hex.EncodeToString(hashInBytes)
|
||
|
||
return hashString, nil
|
||
}
|