A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
add version
aichy126bf730b954abf
diff --git a/cmd/answer/main.go b/cmd/answer/main.goindex 08214244..e9308442 100644--- a/cmd/answer/main.go+++ b/cmd/answer/main.go@@ -5,6 +5,7 @@ import ("path/filepath""github.com/answerdev/answer/internal/base/conf"+ "github.com/answerdev/answer/internal/base/constant""github.com/answerdev/answer/internal/cli""github.com/gin-gonic/gin""github.com/segmentfault/pacman"@@ -40,7 +41,6 @@ func main() {func runApp() {log.SetLogger(zap.NewLogger(log.ParseLevel(logLevel), zap.WithName("answer"), zap.WithPath(logPath), zap.WithCallerFullPath()))-c, err := readConfig()if err != nil {panic(err)@@ -50,6 +50,8 @@ func runApp() {if err != nil {panic(err)}+ constant.Version = Version+defer cleanup()if err := app.Run(); err != nil {panic(err)diff --git a/docs/docs.go b/docs/docs.goindex 5a209686..5c31c2fb 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -2717,14 +2717,14 @@ const docTemplate = `{},"/answer/api/v1/siteinfo": {"get": {- "description": "Get siteinfo",+ "description": "get site info","produces": ["application/json"],"tags": ["site"],- "summary": "Get siteinfo",+ "summary": "get site info","responses": {"200": {"description": "OK",diff --git a/docs/swagger.json b/docs/swagger.jsonindex 362039a0..f7545616 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -2705,14 +2705,14 @@},"/answer/api/v1/siteinfo": {"get": {- "description": "Get siteinfo",+ "description": "get site info","produces": ["application/json"],"tags": ["site"],- "summary": "Get siteinfo",+ "summary": "get site info","responses": {"200": {"description": "OK",diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex 76c5217d..8fab9053 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -3043,7 +3043,7 @@ paths:- Search/answer/api/v1/siteinfo:get:- description: Get siteinfo+ description: get site infoproduces:- application/jsonresponses:@@ -3056,7 +3056,7 @@ paths:data:$ref: '#/definitions/schema.SiteGeneralResp'type: object- summary: Get siteinfo+ summary: get site infotags:- site/answer/api/v1/tag:diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.goindex 5a182716..e41d50ea 100644--- a/internal/base/constant/constant.go+++ b/internal/base/constant/constant.go@@ -27,6 +27,8 @@ const (// object TagID AnswerList// key equal database's table namevar (+ Version string = ""+ObjectTypeStrMapping = map[string]int{QuestionObjectType: 1,AnswerObjectType: 2,diff --git a/internal/schema/dashboard_schema.go b/internal/schema/dashboard_schema.goindex 74eb8ca9..bba29da1 100644--- a/internal/schema/dashboard_schema.go+++ b/internal/schema/dashboard_schema.go@@ -1,16 +1,29 @@package schematype DashboardInfo struct {- QuestionCount int64 `json:"question_count"`- AnswerCount int64 `json:"answer_count"`- CommentCount int64 `json:"comment_count"`- VoteCount int64 `json:"vote_count"`- UserCount int64 `json:"user_count"`- ReportCount int64 `json:"report_count"`- UploadingFiles bool `json:"uploading_files"`- SMTP bool `json:"smtp"`- HTTPS bool `json:"https"`- TimeZone string `json:"time_zone"`- OccupyingStorageSpace string `json:"occupying_storage_space"`- AppStartTime string `json:"app_start_time"`+ QuestionCount int64 `json:"question_count"`+ AnswerCount int64 `json:"answer_count"`+ CommentCount int64 `json:"comment_count"`+ VoteCount int64 `json:"vote_count"`+ UserCount int64 `json:"user_count"`+ ReportCount int64 `json:"report_count"`+ UploadingFiles bool `json:"uploading_files"`+ SMTP bool `json:"smtp"`+ HTTPS bool `json:"https"`+ TimeZone string `json:"time_zone"`+ OccupyingStorageSpace string `json:"occupying_storage_space"`+ AppStartTime string `json:"app_start_time"`+ VersionInfo DashboardInfoVersion `json:"version_info"`+}++type DashboardInfoVersion struct {+ Version string `json:"version"`+ RemoteVersion string `json:"remote_version"`+}++type RemoteVersion struct {+ Release struct {+ Version string `json:"version"`+ URL string `json:"url"`+ } `json:"release"`}diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.goindex fcea03dd..e642a85c 100644--- a/internal/service/dashboard/dashboard_service.go+++ b/internal/service/dashboard/dashboard_service.go@@ -2,7 +2,11 @@ package dashboardimport ("context"+ "encoding/json"+ "io/ioutil"+ "net/http"+ "github.com/answerdev/answer/internal/base/constant""github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/activity_common"answercommon "github.com/answerdev/answer/internal/service/answer_common"@@ -12,6 +16,7 @@ import ("github.com/answerdev/answer/internal/service/report_common""github.com/answerdev/answer/internal/service/siteinfo_common"usercommon "github.com/answerdev/answer/internal/service/user_common"+ "github.com/segmentfault/pacman/log")type DashboardService struct {@@ -112,5 +117,32 @@ func (ds *DashboardService) Statistical(ctx context.Context) (*schema.DashboardIdashboardInfo.OccupyingStorageSpace = "1MB"dashboardInfo.AppStartTime = "102"dashboardInfo.TimeZone = siteInfoInterface.TimeZone+ dashboardInfo.VersionInfo.Version = constant.Version+ dashboardInfo.VersionInfo.RemoteVersion = ds.RemoteVersion(ctx)return dashboardInfo, nil}++func (ds *DashboardService) RemoteVersion(ctx context.Context) string {+ url := "https://answer.dev/getlatest"+ req, _ := http.NewRequest("GET", url, nil)+ req.Header.Set("User-Agent", "Answer/"+constant.Version)+ resp, err := (&http.Client{}).Do(req)+ if err != nil {+ log.Error("http.Client error", err)+ return ""+ }+ defer resp.Body.Close()++ respByte, err := ioutil.ReadAll(resp.Body)+ if err != nil {+ log.Error("http.Client error", err)+ return ""+ }+ remoteVersion := &schema.RemoteVersion{}+ err = json.Unmarshal(respByte, remoteVersion)+ if err != nil {+ log.Error("json.Unmarshal error", err)+ return ""+ }+ return remoteVersion.Release.Version+}