add license apply proxy api

This commit is contained in:
medcl 2023-06-08 13:22:25 +08:00
parent df4de53d29
commit 9f90e49ae4
2 changed files with 45 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package api package api
import ( import (
"infini.sh/console/plugin/api/license"
"path" "path"
"infini.sh/console/config" "infini.sh/console/config"
@ -72,4 +73,6 @@ func Init(cfg *config.AppConfig) {
insight.InitAPI() insight.InitAPI()
layout.InitAPI() layout.InitAPI()
notification.InitAPI() notification.InitAPI()
license.InitAPI()
} }

42
plugin/api/license/api.go Normal file
View File

@ -0,0 +1,42 @@
/* Copyright © INFINI LTD. All rights reserved.
* Web: https://infinilabs.com
* Email: hello#infini.ltd */
package license
import (
"infini.sh/framework/core/api"
httprouter "infini.sh/framework/core/api/router"
"infini.sh/framework/core/util"
"infini.sh/license"
"net/http"
)
type LicenseAPI struct {
api.Handler
}
func InitAPI() {
handler := LicenseAPI{}
api.HandleAPIMethod(api.POST, "/_license/request_trial", handler.RequestTrialLicense)
}
func (handler *LicenseAPI) RequestTrialLicense(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
body, err := handler.GetRawBody(req)
if err != nil {
handler.Error500(w, err.Error())
return
}
v := license.TrialRequest{}
util.FromJSONBytes(body, &v)
//TODO implement config for the api endpoint
request:=util.NewPostRequest("https://api.infini.sh/_license/request_trial", util.MustToJSONBytes(v))
response,err:=util.ExecuteRequest(request)
if err!=nil{
handler.WriteError(w,err.Error(),response.StatusCode)
return
}
w.WriteHeader(response.StatusCode)
w.Write(response.Body)
}