mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-03 15:56:22 +00:00
✨ feat: enhance post retrieval with authorization token
- Updated `getPostById` function to accept an optional authorization token. - Modified `PostPage` to retrieve the token from cookies and pass it to the API call. - Added smooth transition effects for background and text colors in `globals.css`. - Cleaned up imports and formatting in `blog-home.tsx`. - Refactored `blog-post.tsx` to use `MDXRemote` for rendering markdown content. - Introduced `blog-comment.tsx` and `blog-post-header.client.tsx` components for better structure. - Added a switch component for dark/light mode toggle in the navbar. - Updated `Post` model to include a description field.
This commit is contained in:
@ -11,11 +11,13 @@ const (
|
||||
RoleUser = "user"
|
||||
RoleAdmin = "admin"
|
||||
EnvKeyBaseUrl = "BASE_URL" // 环境变量:基础URL
|
||||
EnvKeyLogLevel = "LOG_LEVEL" // 环境变量:日志级别
|
||||
EnvKeyMode = "MODE" // 环境变量:运行模式
|
||||
EnvKeyJwtSecrete = "JWT_SECRET" // 环境变量:JWT密钥
|
||||
EnvKeyPasswordSalt = "PASSWORD_SALT" // 环境变量:密码盐
|
||||
EnvKeyTokenDuration = "TOKEN_DURATION" // 环境变量:令牌有效期
|
||||
EnvKeyTokenDurationDefault = 300
|
||||
EnvKeyRefreshTokenDurationDefault = 604800
|
||||
EnvKeyRefreshTokenDuration = "REFRESH_TOKEN_DURATION" // 环境变量:刷新令牌有效期
|
||||
EnvKeyRefreshTokenDurationWithRemember = "REFRESH_TOKEN_DURATION_WITH_REMEMBER" // 环境变量:记住我刷新令牌有效期
|
||||
KVKeyEmailVerificationCode = "email_verification_code:" // KV存储:邮箱验证码
|
||||
@ -40,6 +42,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
OrderByEnumPost = []string{OrderByCreatedAt, OrderByUpdatedAt, OrderByLikeCount, OrderByCommentCount, OrderByViewCount, OrderByHeat} // 帖子可用的排序方式
|
||||
OrderByEnumComment = []string{OrderByCreatedAt, OrderByUpdatedAt, OrderByCommentCount} // 评论可用的排序方式
|
||||
OrderByEnumPost = []string{OrderByCreatedAt, OrderByUpdatedAt, OrderByLikeCount, OrderByCommentCount, OrderByViewCount, OrderByHeat} // 帖子可用的排序方式
|
||||
OrderByEnumComment = []string{OrderByCreatedAt, OrderByUpdatedAt, OrderByCommentCount} // 评论可用的排序方式
|
||||
)
|
||||
|
@ -1,7 +1,9 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/snowykami/neo-blog/pkg/constant"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -12,10 +14,26 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
_ = godotenv.Load()
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
logrus.Warnf("Error loading .env file: %v", err)
|
||||
}
|
||||
|
||||
logrus.Infof("env loaded")
|
||||
// Init env
|
||||
IsDevMode = Env.Get(constant.EnvKeyMode, constant.ModeProd) == constant.ModeDev
|
||||
// Set log level
|
||||
logrus.SetLevel(getLogLevel(Env.Get(constant.EnvKeyLogLevel, "info")))
|
||||
if logrus.GetLevel() == logrus.DebugLevel {
|
||||
logrus.Debug("Debug mode is enabled, printing environment variables:")
|
||||
for _, e := range os.Environ() {
|
||||
if len(e) > 0 && e[0] == '_' {
|
||||
// Skip environment variables that start with '_'
|
||||
continue
|
||||
}
|
||||
fmt.Printf("%s ", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type envUtils struct{}
|
||||
@ -56,3 +74,23 @@ func (e *envUtils) GetAsBool(key string, defaultValue ...bool) bool {
|
||||
}
|
||||
return boolValue
|
||||
}
|
||||
|
||||
func getLogLevel(levelString string) logrus.Level {
|
||||
switch levelString {
|
||||
case "debug":
|
||||
return logrus.DebugLevel
|
||||
case "info":
|
||||
return logrus.InfoLevel
|
||||
case "warn":
|
||||
return logrus.WarnLevel
|
||||
case "error":
|
||||
return logrus.ErrorLevel
|
||||
case "fatal":
|
||||
return logrus.FatalLevel
|
||||
case "panic":
|
||||
return logrus.PanicLevel
|
||||
default:
|
||||
logrus.Warnf("Unknown log level: %s, defaulting to InfoLevel", levelString)
|
||||
return logrus.InfoLevel
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user