Skip to content

Commit

Permalink
Merge pull request #5 from paradeum-team/kli
Browse files Browse the repository at this point in the history
Deprecated API
  • Loading branch information
likai1130 authored Dec 27, 2022
2 parents bd4ad6e + 31b66c2 commit 34752b1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions common/middleware/captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// @Tags 登陆
// @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}"
// @Router /api/v1/captcha [get]

func GenerateCaptchaHandler(c *gin.Context) {
id, b64s, err := captcha.DriverDigitFunc()
if err != nil {
Expand Down
25 changes: 13 additions & 12 deletions common/middleware/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import (
const DownloadUrlPrefix = "/public/downloadFile/"

var (
failedInitFilePath = cerr.New(4500, "初始化路径失败", "failed to initialize upload path")
failedSavingFile = cerr.New(4501, "未能保存文件", "failed to save the uploaded file")
failedUploadToOss = cerr.New(4502, "上传OSS失败", "failed to upload to oss")
requiredFileErr = cerr.New(4503, "文件不能为空", "file cannot be empty")
failedInitFilePath = cerr.New(4500, "初始化路径失败", "failed to initialize upload path")
failedSavingFile = cerr.New(4501, "未能保存文件", "failed to save the uploaded file")
failedUploadToOss = cerr.New(4502, "上传OSS失败", "failed to upload to oss")
requiredFileErr = cerr.New(4503, "文件不能为空", "file cannot be empty")
failedDownloadFromOss = cerr.New(4504, "OSS下载失败", "failed to download from oss")
failedUploadingfile = cerr.New(4505, "未能上传文件", "failed to upload")
failedUploadingfile = cerr.New(4505, "未能上传文件", "failed to upload")
)

type FileResponse struct {
Path string `json:"path"`
FullPath string `json:"full_path"`
Name string `json:"name"`
Size int64 `json:"size"`
Size int64 `json:"size"`
}

type File struct {
Expand All @@ -55,6 +55,7 @@ type File struct {
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/public/uploadFile [post]
// @Security Bearer

func (e File) UploadFile(c *gin.Context) {
e.MakeContext(c)

Expand Down Expand Up @@ -100,11 +101,12 @@ func (e File) UploadFile(c *gin.Context) {
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /public/downloadFile/{pathname}/{filename} [get]
// @Security Bearer

func (e File) DownloadFile(c *gin.Context) {
var req struct {
Pathname string `uri:"pathname"`
Filename string `uri:"filename"`
As string `form:"as"`
As string `form:"as"`
}
err := e.MakeContext(c).
Bind(&req, nil, binding.Query).
Expand Down Expand Up @@ -177,7 +179,7 @@ func (e File) baseImg(c *gin.Context) (*FileResponse, error) {
ddd, _ := base64.StdEncoding.DecodeString(file2list[1])

// get ext name from file2list[0]
filename := e.filename(category,"*.jpg")
filename := e.filename(category, "*.jpg")
err := e.saveFile(bytes.NewReader(ddd), filename)
if err != nil {
return nil, err
Expand All @@ -187,7 +189,7 @@ func (e File) baseImg(c *gin.Context) (*FileResponse, error) {
Path: filename,
FullPath: urlPrefix + filename,
Name: "",
Size: int64(len(ddd)),
Size: int64(len(ddd)),
}
return fileResponse, nil
}
Expand Down Expand Up @@ -287,7 +289,7 @@ func (e File) ImportTempFile(c *gin.Context) (*FileResponse, error) {
Path: filename,
FullPath: fullname,
Name: file.Filename,
Size: file.Size,
Size: file.Size,
}
return fileResponse, nil
}
Expand Down Expand Up @@ -316,8 +318,7 @@ func (e File) singleFile(c *gin.Context) (*FileResponse, error) {
Path: filename,
FullPath: urlPrefix + filename,
Name: file.Filename,
Size: file.Size,

Size: file.Size,
}
return fileResponse, nil
}
Expand Down
1 change: 1 addition & 0 deletions common/middleware/jwtauth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func PayloadFunc(data interface{}) jwt.MapClaims {
// @Param account body Login true "account"
// @Success 200 {string} string "{"code": 200, "expire": "2019-08-07T12:45:48+08:00", "token": ".eyJleHAiOjE1NjUxNTMxNDgsImlkIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU2NTE0OTU0OH0.-zvzHvbg0A" }"
// @Router /api/v1/login [post]

func Authenticator(c *gin.Context) (interface{}, error) {
log := api.MustGetLogger(c)
db := api.MustGetOrm(c)
Expand Down
13 changes: 7 additions & 6 deletions common/middleware/oss_signed_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

type PresignTokenRequest struct {
Directory string `json:"directory"`
Filename string `json:"filename"`
Duration int `json:"duration"`
Filename string `json:"filename"`
Duration int `json:"duration"`
}

type PresignTokenResponse struct {
Vendor string `json:"vendor"`
Token interface{} `json:"token"`
Vendor string `json:"vendor"`
Token interface{} `json:"token"`
}

type PresignToken struct {
Expand All @@ -32,6 +32,7 @@ type PresignToken struct {
// @Success 200 {object} PresignTokenResponse "{"code": 200, "data": [...]}"
// @Router /presign-token [post]
// @Security Bearer

func (e PresignToken) PresignToken(c *gin.Context) {
var req PresignTokenRequest

Expand All @@ -58,9 +59,9 @@ func (e PresignToken) PresignToken(c *gin.Context) {
//c.Header("Access-Control-Allow-Methods", "POST")
//c.Header("Access-Control-Allow-Origin", "*")

response := PresignTokenResponse {
response := PresignTokenResponse{
Vendor: oss.Name(),
Token: token,
Token: token,
}
e.OK(response, "成功")
}
17 changes: 9 additions & 8 deletions common/middleware/server_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
GB = 1024 * MB
)

//获取相差时间
// 获取相差时间
func GetHourDiffer(startTime, endTime string) int64 {
var hour int64
t1, err := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
Expand All @@ -44,6 +44,7 @@ func GetHourDiffer(startTime, endTime string) int64 {
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /server-monitor [get]
// @Security Bearer

func ServerInfo(c *gin.Context) {
sysInfo, err := host.Info()
osDic := make(map[string]interface{}, 0)
Expand Down Expand Up @@ -103,13 +104,13 @@ func ServerInfo(c *gin.Context) {
appVersion = "dev"
}
data := map[string]interface{}{
"requestId": utils.GenerateMsgIDFromContext(c),
"code": 200,
"os": osDic,
"mem": memDic,
"cpu": cpuDic,
"disk": diskDic,
"diskList": disklist,
"requestId": utils.GenerateMsgIDFromContext(c),
"code": 200,
"os": osDic,
"mem": memDic,
"cpu": cpuDic,
"disk": diskDic,
"diskList": disklist,
"appVersion": appVersion,
}
c.Set("result", data)
Expand Down

0 comments on commit 34752b1

Please sign in to comment.