refactor(api): simplify instance listing response and add running status
Remove sensitive information from instance listing response for all users and add isRunning field Fix backend to prevent starting already running frpc instances
This commit is contained in:
@@ -539,13 +539,6 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userType, err := GetUserType(userID)
|
||||
if err != nil {
|
||||
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get user type: %v", err))
|
||||
SendErrorResponse(w, http.StatusInternalServerError, "Failed to get user type")
|
||||
return
|
||||
}
|
||||
|
||||
instances, err := GetUserInstances(userID)
|
||||
if err != nil {
|
||||
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get user instances: %v", err))
|
||||
@@ -556,32 +549,18 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
instanceList := make([]map[string]interface{}, len(instances))
|
||||
for i, inst := range instances {
|
||||
instanceData := map[string]interface{}{
|
||||
"instanceID": inst.ID,
|
||||
"name": inst.Name,
|
||||
"bootAtStart": inst.BootAtStart,
|
||||
"runUser": inst.RunUser,
|
||||
"configPath": inst.ConfigPath,
|
||||
"createdAt": inst.CreatedAt,
|
||||
"createdBy": inst.CreatedBy,
|
||||
}
|
||||
|
||||
if userType == "admin" || userType == "superuser" {
|
||||
serverAddr, err := getKeyText(inst.ConfigPath, "serverAddr", "")
|
||||
serverPort, err := getKeyText(inst.ConfigPath, "serverPort", "")
|
||||
authMethod, err := getKeyText(inst.ConfigPath, "auth.method", "")
|
||||
if err != nil {
|
||||
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to read config for instance %d: %v", inst.ID, err))
|
||||
}
|
||||
instanceData["serverAddr"] = serverAddr
|
||||
instanceData["serverPort"] = serverPort
|
||||
instanceData["auth_method"] = authMethod
|
||||
"instanceID": inst.ID,
|
||||
"name": inst.Name,
|
||||
"createdAt": inst.CreatedAt,
|
||||
"createdBy": inst.CreatedBy,
|
||||
"isRunning": IsInstanceRunning(inst.ID),
|
||||
}
|
||||
|
||||
instanceList[i] = instanceData
|
||||
}
|
||||
|
||||
SendSuccessResponse(w, "Instances retrieved successfully", instanceList)
|
||||
postLog.Info(fmt.Sprintf("[ListInstancesHandler] Retrieved %d instances for user %d (type: %s)", len(instances), userID, userType))
|
||||
postLog.Info(fmt.Sprintf("[ListInstancesHandler] Retrieved %d instances for user %d", len(instances), userID))
|
||||
}
|
||||
|
||||
func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user