mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-14 00:48:26 +08:00
Go: refactor and add version type (#16863)
### Summary ``` RAGFlow(admin)> show version; +--------------+-----------------------+ | field | value | +--------------+-----------------------+ | version | v0.26.4-84-g547bc8614 | | version_type | open source | +--------------+-----------------------+ ``` --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -221,7 +221,7 @@ func main() {
|
||||
}
|
||||
|
||||
if arguments.versionFlag {
|
||||
fmt.Printf("RAGFlow version: %s\n", utility.GetRAGFlowVersion())
|
||||
fmt.Printf("RAGFlow version: %s\n", common.GetRAGFlowVersion())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ func runAdmin(args *serverArgs) error {
|
||||
" /_/ |_/_/ |_\\____/_/ /_/\\____/|__/|__/ /_/ |_\\__,_/_/ /_/ /_/_/_/ /_/ \n")
|
||||
|
||||
// Print RAGFlow version
|
||||
common.Info(fmt.Sprintf("RAGFlow admin version: %s", utility.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("RAGFlow admin version: %s", common.GetRAGFlowVersion()))
|
||||
|
||||
// Start HTTP server in a goroutine
|
||||
go func() {
|
||||
@@ -509,7 +509,7 @@ func runIngestor(args *serverArgs) error {
|
||||
" /____/\n")
|
||||
|
||||
// Print RAGFlow version
|
||||
common.Info(fmt.Sprintf("RAGFlow ingestion service version: %s", utility.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("RAGFlow ingestion service version: %s", common.GetRAGFlowVersion()))
|
||||
|
||||
// Get local IP address for heartbeat reporting
|
||||
localIP, err := utility.GetLocalIP()
|
||||
@@ -584,7 +584,7 @@ func runSyncer(args *serverArgs) error {
|
||||
" /____/ \n")
|
||||
|
||||
// Print RAGFlow version
|
||||
common.Info(fmt.Sprintf("RAGFlow file syncer service version: %s", utility.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("RAGFlow file syncer service version: %s", common.GetRAGFlowVersion()))
|
||||
|
||||
// Get local IP address for heartbeat reporting
|
||||
localIP, err := utility.GetLocalIP()
|
||||
@@ -863,7 +863,7 @@ func startServer(config *server.Config) {
|
||||
" / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /\n" +
|
||||
" /_/ |_|/_/ |_|\\____//_/ /_/ \\____/ |__/|__/\n",
|
||||
)
|
||||
common.Info(fmt.Sprintf("RAGFlow Go Version: %s", utility.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("RAGFlow Go Version: %s", common.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("Server starting on port: %d", config.Server.Port))
|
||||
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
common.Fatal("Failed to start server", zap.Error(err))
|
||||
|
||||
@@ -84,7 +84,7 @@ func (h *Handler) Ping(c *gin.Context) {
|
||||
|
||||
// Login handle admin login
|
||||
// @Summary Admin Login
|
||||
// @Description Admin login verification using email, only superuser can login
|
||||
// @Description Admin login verification using email, only superuser can log in
|
||||
// @Tags admin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -170,51 +170,66 @@ type ListUsersRequest struct {
|
||||
// ListUsers handle list users
|
||||
func (h *Handler) ListUsers(c *gin.Context) {
|
||||
|
||||
var err error
|
||||
var pageInt int
|
||||
page := c.Param("page")
|
||||
if page == "" {
|
||||
pageInt = 0
|
||||
} else {
|
||||
pageInt, err = strconv.Atoi(page)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Page must be an integer")
|
||||
return
|
||||
}
|
||||
name := c.DefaultQuery("keyword", "")
|
||||
status := c.DefaultQuery("status", "")
|
||||
role := c.DefaultQuery("role", "")
|
||||
sort := c.DefaultQuery("sort", "") // descending or ascending
|
||||
orderBy := c.DefaultQuery("order", "") // order by field
|
||||
pageInt, err := common.ParseRequestIntPositive(c, c.Query("page"), "page", 1)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
pageSizeInt, err := common.ParseRequestIntPositive(c, c.Query("page_size"), "page_size", 10)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
plan := c.Query("plan") // plan name
|
||||
topInt, err := common.ParseRequestIntPositive(c, c.Query("top"), "top", 0)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
quotaInt, err := common.ParseRequestIntPositive(c, c.Query("quota"), "quota", 0)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if quotaInt > 100 {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be less than or equal to 100")
|
||||
return
|
||||
}
|
||||
daysInt, err := common.ParseRequestIntPositive(c, c.Query("days"), "days", 0)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var pageSizeInt int
|
||||
pageSize := c.Param("page_size")
|
||||
if pageSize == "" {
|
||||
pageSizeInt = 0
|
||||
} else {
|
||||
pageSizeInt, err = strconv.Atoi(pageSize)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Page size must be an integer")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var req ListUsersRequest
|
||||
var users []map[string]interface{}
|
||||
if err = c.ShouldBindJSON(&req); err != nil {
|
||||
users, err = h.service.ListUsers(pageInt, pageSizeInt)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
switch common.GetRAGFlowType() {
|
||||
case common.OpenSourceVersion:
|
||||
|
||||
common.SuccessWithData(c, users, "Get all users")
|
||||
} else {
|
||||
users, err = h.service.ListUsersEnterprise(pageInt, pageSizeInt, req.UserStatus, req.OrderBy, req.Plan, req.Top, req.Days, req.Quota)
|
||||
users, err = h.service.ListUsers(pageInt, pageSizeInt, name, status, sort, orderBy)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
common.SuccessWithData(c, users, "List users")
|
||||
case common.EnterpriseEdition:
|
||||
users, err = h.service.ListUsersEE(pageInt, pageSizeInt, name, status, role, sort, orderBy, plan, topInt, daysInt, quotaInt)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
default:
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Invalid RAGFlow type")
|
||||
return
|
||||
}
|
||||
|
||||
common.SuccessWithData(c, users, "List users")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateUserHTTPRequest create user request
|
||||
@@ -730,8 +745,8 @@ func (h *Handler) ListEnvironments(c *gin.Context) {
|
||||
|
||||
// GetVersion handle get version
|
||||
func (h *Handler) GetVersion(c *gin.Context) {
|
||||
version := h.service.GetVersion()
|
||||
common.SuccessWithData(c, gin.H{"version": version}, "")
|
||||
version, versionType := h.service.GetVersion()
|
||||
common.SuccessWithData(c, gin.H{"version": version, "version_type": versionType}, "")
|
||||
}
|
||||
|
||||
// GetFingerprint handle get system fingerprint
|
||||
|
||||
@@ -140,8 +140,8 @@ func generateRandomHex(n int) string {
|
||||
}
|
||||
|
||||
// ListUsers list all users
|
||||
func (s *Service) ListUsers(page, pageSize int) ([]map[string]interface{}, error) {
|
||||
users, _, err := s.userDAO.List(page*pageSize, pageSize)
|
||||
func (s *Service) ListUsers(pageIndex, pageSize int, name, status, sort, orderBy string) ([]map[string]interface{}, error) {
|
||||
users, _, err := s.userDAO.List(pageIndex*pageSize, pageSize, name, status, sort, orderBy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1544,8 +1544,8 @@ func (s *Service) ListEnvironments() ([]map[string]interface{}, error) {
|
||||
// Version methods
|
||||
|
||||
// GetVersion get RAGFlow version
|
||||
func (s *Service) GetVersion() string {
|
||||
return utility.GetRAGFlowVersion()
|
||||
func (s *Service) GetVersion() (string, string) {
|
||||
return common.GetRAGFlowVersion(), common.GetRAGFlowType()
|
||||
}
|
||||
|
||||
// Sandbox methods
|
||||
|
||||
@@ -788,26 +788,19 @@ func (s *Service) ShowUsersActivity(days, windows *int) (map[string]interface{},
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListUsersEnterprise(pageIndex, pageSize int, status, orderBy, plan *string, top, days, quota *int) ([]map[string]interface{}, error) {
|
||||
func (s *Service) ListUsersEE(pageIndex, pageSize int, name string, status, role, sort, orderBy, plan string, top, days, quota int) ([]map[string]interface{}, error) {
|
||||
item := map[string]interface{}{}
|
||||
if status != nil {
|
||||
item["status"] = *status
|
||||
}
|
||||
if orderBy != nil {
|
||||
item["order_by"] = *orderBy
|
||||
}
|
||||
if plan != nil {
|
||||
item["plan"] = *plan
|
||||
}
|
||||
if top != nil {
|
||||
item["top"] = *top
|
||||
}
|
||||
if days != nil {
|
||||
item["days"] = *days
|
||||
}
|
||||
if quota != nil {
|
||||
item["quota"] = *quota
|
||||
}
|
||||
item["pageIndex"] = pageIndex
|
||||
item["pageSize"] = pageSize
|
||||
item["name"] = name
|
||||
item["status"] = status
|
||||
item["role"] = role
|
||||
item["sort"] = sort
|
||||
item["order_by"] = orderBy
|
||||
item["plan"] = plan
|
||||
item["top"] = top
|
||||
item["days"] = days
|
||||
item["quota"] = quota
|
||||
|
||||
var result []map[string]interface{}
|
||||
result = append(result, item)
|
||||
@@ -17,7 +17,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -91,3 +93,21 @@ func ResponseWithHttpCodeData(c *gin.Context, httpCode int, code ErrorCode, data
|
||||
Message: message,
|
||||
})
|
||||
}
|
||||
|
||||
func ParseRequestIntPositive(c *gin.Context, parameter, parameterName string, defaultValue int) (int, error) {
|
||||
var parameterInt int
|
||||
var err error
|
||||
if parameter == "" {
|
||||
parameterInt = defaultValue
|
||||
} else {
|
||||
parameterInt, err = strconv.Atoi(parameter)
|
||||
if err != nil {
|
||||
return defaultValue, fmt.Errorf("%w: %s must be an integer", err, parameterName)
|
||||
}
|
||||
}
|
||||
|
||||
if parameterInt < 0 {
|
||||
return defaultValue, fmt.Errorf("%w: %s must be a positive integer or zero", err, parameterName)
|
||||
}
|
||||
return parameterInt, nil
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package utility
|
||||
package common
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -24,21 +24,21 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ragflowVersionInfo = "unknown"
|
||||
versionOnce sync.Once
|
||||
versionInfo = "unknown"
|
||||
versionOnce sync.Once
|
||||
)
|
||||
|
||||
// GetRAGFlowVersion gets the RAGFlow version information
|
||||
// It reads from VERSION file or falls back to git describe command
|
||||
func GetRAGFlowVersion() string {
|
||||
versionOnce.Do(func() {
|
||||
ragflowVersionInfo = getRAGFlowVersionInternal()
|
||||
versionInfo = getVersionInternal()
|
||||
})
|
||||
return ragflowVersionInfo
|
||||
return versionInfo
|
||||
}
|
||||
|
||||
// getRAGFlowVersionInternal internal function to get version
|
||||
func getRAGFlowVersionInternal() string {
|
||||
// getVersionInternal internal function to get version
|
||||
func getVersionInternal() string {
|
||||
// Get the path to VERSION file
|
||||
// Assuming this file is in internal/utility, VERSION is in project root
|
||||
exePath, err := os.Executable()
|
||||
23
internal/common/version_ee.go
Normal file
23
internal/common/version_ee.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package common
|
||||
|
||||
var OpenSourceVersion = "open source"
|
||||
var EnterpriseEdition = "enterprise edition"
|
||||
|
||||
func GetRAGFlowType() string {
|
||||
return OpenSourceVersion
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package utility
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -97,7 +97,7 @@ func (dao *UserDAO) UpdateAccessToken(user *entity.User, token string) error {
|
||||
}
|
||||
|
||||
// List list users (only active users with status != "0")
|
||||
func (dao *UserDAO) List(offset, limit int) ([]*entity.User, int64, error) {
|
||||
func (dao *UserDAO) List(offset, limit int, name, status, sort, orderBy string) ([]*entity.User, int64, error) {
|
||||
var users []*entity.User
|
||||
var total int64
|
||||
|
||||
|
||||
@@ -214,41 +214,6 @@ func (h *UserHandler) GetUserByID(c *gin.Context) {
|
||||
common.SuccessWithData(c, user, "success")
|
||||
}
|
||||
|
||||
// ListUsers user list
|
||||
// @Summary User List
|
||||
// @Description Get paginated user list
|
||||
// @Tags users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "page number" default(1)
|
||||
// @Param page_size query int false "items per page" default(10)
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /api/v1/users [get]
|
||||
func (h *UserHandler) ListUsers(c *gin.Context) {
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "10"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize < 1 || pageSize > 100 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
users, total, code, err := h.userService.ListUsers(page, pageSize)
|
||||
if err != nil {
|
||||
common.ResponseWithCodeData(c, code, false, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
common.SuccessWithData(c, gin.H{
|
||||
"items": users,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
}, "success")
|
||||
}
|
||||
|
||||
// Logout user logout
|
||||
// @Summary User Logout
|
||||
// @Description Logout user and invalidate access token
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewAdminClient(logger *zap.Logger, serverType common.ServerType, serverName
|
||||
serverName: serverName,
|
||||
host: host,
|
||||
port: port,
|
||||
version: utility.GetRAGFlowVersion(),
|
||||
version: common.GetRAGFlowVersion(),
|
||||
lastSuccess: false,
|
||||
attemptCount: 0,
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"ragflow/internal/engine"
|
||||
"ragflow/internal/server"
|
||||
"ragflow/internal/storage"
|
||||
"ragflow/internal/utility"
|
||||
)
|
||||
|
||||
// SystemService system service
|
||||
@@ -67,6 +66,7 @@ func (s *SystemService) GetConfig() (*ConfigResponse, error) {
|
||||
// VersionResponse version response
|
||||
type VersionResponse struct {
|
||||
Version string `json:"version"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type HealthzMeta struct {
|
||||
@@ -86,9 +86,11 @@ type HealthzResponse struct {
|
||||
|
||||
// GetVersion get RAGFlow version
|
||||
func (s *SystemService) GetVersion() (*VersionResponse, error) {
|
||||
version := utility.GetRAGFlowVersion()
|
||||
version := common.GetRAGFlowVersion()
|
||||
versionType := common.GetRAGFlowType()
|
||||
return &VersionResponse{
|
||||
Version: version,
|
||||
Type: versionType,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -442,33 +442,6 @@ func (s *UserService) GetUserByID(id uint) (*UserResponse, common.ErrorCode, err
|
||||
}, common.CodeSuccess, nil
|
||||
}
|
||||
|
||||
// ListUsers list users
|
||||
func (s *UserService) ListUsers(page, pageSize int) ([]*UserResponse, int64, common.ErrorCode, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
users, total, err := s.userDAO.List(offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, common.CodeServerError, err
|
||||
}
|
||||
|
||||
responses := make([]*UserResponse, len(users))
|
||||
for i, user := range users {
|
||||
responses[i] = &UserResponse{
|
||||
ID: user.ID,
|
||||
Email: user.Email,
|
||||
Nickname: user.Nickname,
|
||||
Status: user.Status,
|
||||
CreatedAt: func() string {
|
||||
if user.CreateTime != nil {
|
||||
return time.Unix(*user.CreateTime, 0).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
return ""
|
||||
}(),
|
||||
}
|
||||
}
|
||||
|
||||
return responses, total, common.CodeSuccess, nil
|
||||
}
|
||||
|
||||
// VerifyPassword verify password
|
||||
// Supports both werkzeug pbkdf2 format (pbkdf2:sha256:iterations$salt$hash) and scrypt format
|
||||
func (s *UserService) VerifyPassword(hashedPassword, password string) bool {
|
||||
|
||||
Reference in New Issue
Block a user