Skip to content

Commit

Permalink
Merge branch 'main' into add_common_module
Browse files Browse the repository at this point in the history
Signed-off-by: jiuxia211 <[email protected]>
  • Loading branch information
jiuxia211 authored Dec 20, 2024
2 parents 6b8c86a + f4c4864 commit 55e5635
Show file tree
Hide file tree
Showing 33 changed files with 786 additions and 351 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> WARNING(Chinese only): 本项目受福州大学统一指导,由福州大学计算机与大数据学院、福州大学网络安全与信息化办公室管理(以上单位合称"官方")。这份源代码使用了宽松开源协议,但源码仅供学习参考,不允许该项目直接或间接性使用/修改后使用在任何非官方和 west2-online 外的应用、网站、app 及任何可以与用户产生交互的互联网信息媒介中。该警告具备行政约束效力。
<div align="center">
<h1 style="display: inline-block; vertical-align: middle;">fzuhelper-server</h1>
</div>
Expand Down
7 changes: 3 additions & 4 deletions api/handler/api/common_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/handler/api/paper_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/west2-online/fzuhelper-server/api/rpc"
"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/kitex_gen/paper"
"github.com/west2-online/fzuhelper-server/pkg/errno"

Check failure on line 37 in api/handler/api/paper_service_test.go

View workflow job for this annotation

GitHub Actions / lint

"github.com/west2-online/fzuhelper-server/pkg/errno" imported and not used (typecheck)

Check failure on line 37 in api/handler/api/paper_service_test.go

View workflow job for this annotation

GitHub Actions / Unit Test

"github.com/west2-online/fzuhelper-server/pkg/errno" imported and not used
)

func TestGetDownloadUrl(t *testing.T) {
Expand Down
28 changes: 10 additions & 18 deletions api/handler/api/version_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions api/handler/custom/launch_screen_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/west2-online/fzuhelper-server/api/rpc"
"github.com/west2-online/fzuhelper-server/kitex_gen/launch_screen"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/logger"
)

// MobileGetImage .
Expand All @@ -36,7 +35,6 @@ func MobileGetImage(ctx context.Context, c *app.RequestContext) {
var req api.MobileGetImageRequest
err = c.BindAndValidate(&req)
if err != nil {
logger.Errorf("api.MobileGetImage: BindAndValidate error %v", err)
pack.RespError(c, errno.ParamError.WithError(err))
return
}
Expand Down Expand Up @@ -65,7 +63,6 @@ func AddImagePointTime(ctx context.Context, c *app.RequestContext) {
var req api.AddImagePointTimeRequest
err = c.BindAndValidate(&req)
if err != nil {
logger.Errorf("api.AddImagePointTime: BindAndValidate error %v", err)
pack.RespError(c, errno.ParamError.WithError(err))
return
}
Expand Down
9 changes: 1 addition & 8 deletions api/handler/custom/url_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions api/mw/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,49 @@ package mw
import (
"fmt"
"testing"
"time"

"github.com/bytedance/mockey"
"github.com/golang-jwt/jwt"
"github.com/stretchr/testify/assert"

"github.com/west2-online/fzuhelper-server/pkg/constants"
)

const secretKeyExample = "MC4CAQAwBQYDK2VwBCIEIPAfnWESrQOyNXXHpMqx2xcgXXvPqvuSup4YLqIjMpI3"

// TestCreateExpiredToken 是一个特殊测试,旨在生成一个过期的 Token
func TestCreateExpiredToken(t *testing.T) {
// 默认生成时间是一年一个月七天前的
curTime := time.Now().AddDate(-1, -1, -7)
expiredTime := curTime.Add(constants.AccessTokenTTL)
var token string
var err error

claims := Claims{
Type: constants.TypeAccessToken,
StandardClaims: jwt.StandardClaims{
ExpiresAt: expiredTime.Unix(), // 过期时间戳
IssuedAt: curTime.Unix(), // 当前时间戳
Issuer: constants.Issuer, // 颁发者签名
},
}
tokenStruct := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claims)
key, err := jwt.ParseEdPrivateKeyFromPEM([]byte(fmt.Sprintf("%v\n%v\n%v", "-----BEGIN PRIVATE KEY-----",
secretKeyExample,
"-----END PRIVATE KEY-----")))
if err != nil {
t.Errorf("parse private key failed, err: %v", err)
}

token, err = tokenStruct.SignedString(key)
if err != nil {
t.Errorf("sign token failed, err: %v", err)
}

fmt.Printf("Access-Token: %s", token)
}

func TestCreateAllToken(t *testing.T) {
type testCase struct {
name string
Expand Down
13 changes: 4 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,10 @@ func getService(name string) *service {
}
}

// GetLoggerLevel 会尝试对文本日志等级做转换,如果失败则返回默认 INFO
func GetLoggerLevel() int64 {
// GetLoggerLevel 会返回服务的日志等级
func GetLoggerLevel() string {
if Server == nil {
return constants.LevelInfo // 默认 INFO
return constants.DefaultLogLevel
}

v, ok := constants.LevelMap[Server.LogLevel]
if !ok {
return constants.LevelInfo // 默认 INFO
}
return v
return Server.LogLevel
}
2 changes: 2 additions & 0 deletions docs/README.zh.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> 警告: 本项目受福州大学统一指导,由福州大学计算机与大数据学院、福州大学网络安全与信息化办公室管理(以上单位合称"官方")。这份源代码使用了宽松开源协议,但源码仅供学习参考,不允许该项目直接或间接性使用/修改后使用在任何非官方和 west2-online 外的应用、网站、app 及任何可以与用户产生交互的互联网信息媒介中。该警告具备行政约束效力。
<div align="center">
<h1 style="display: inline-block; vertical-align: middle;">fzuhelper-server</h1>
</div>
Expand Down
Loading

0 comments on commit 55e5635

Please sign in to comment.