- Add session.Attach to reuse per-request sessions across middleware and ghome handlers - Make Session finalize/abort paths idempotent to avoid duplicate commit or rollback work - Move request_data parsing helper to internal/utils - Expand ParseRequestData usage across api, download, unit, live, multiunit, and subscenario handlers - Extract download package metadata into internal/handler/download/types.go - Return explicit errors from selected session lookup helpers and update callers - Make api action handlers return errors directly instead of calling ss.CheckErr in nested layers Signed-off-by: Sean Du <do4suki@gmail.com>
46 lines
992 B
Go
46 lines
992 B
Go
package basic
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/pem"
|
|
"honoka-chan/config"
|
|
"honoka-chan/internal/router"
|
|
ghomeschema "honoka-chan/internal/schema/ghome"
|
|
"honoka-chan/internal/session"
|
|
"honoka-chan/pkg/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func publicKey(ctx *gin.Context) {
|
|
ss := session.Attach(ctx)
|
|
defer ss.Finalize()
|
|
|
|
publicKeyCode := 0
|
|
publicKeyMsg := "ok"
|
|
publicKeyData := ghomeschema.PublicKeyData{
|
|
Result: publicKeyCode,
|
|
Message: publicKeyMsg,
|
|
}
|
|
|
|
publicKey := utils.ReadAllText(config.PublicKeyPath)
|
|
block, _ := pem.Decode([]byte(publicKey))
|
|
if block == nil || block.Type != "PUBLIC KEY" {
|
|
publicKeyMsg = "公钥读取失败!"
|
|
publicKeyCode = 31
|
|
} else {
|
|
publicKeyData.Key = base64.StdEncoding.EncodeToString(block.Bytes)
|
|
publicKeyData.Method = "rsa"
|
|
}
|
|
|
|
ss.Respond(ghomeschema.PublicKeyResp{
|
|
Code: publicKeyCode,
|
|
Msg: publicKeyMsg,
|
|
Data: publicKeyData,
|
|
})
|
|
}
|
|
|
|
func init() {
|
|
router.AddHandler("v1", "POST", "/basic/publickey", publicKey)
|
|
}
|