Files
CLIProxyAPI/cmd/server/home_plugin_status.go
hkfires e9a11db7b9 feat(home): enhance plugin management and synchronization
- Added NodeID field to HomeConfig for better identification.
- Updated ConfigFromJWT to populate NodeID from claims.
- Introduced new Redis keys for managing plugin status and tasks.
- Implemented RPushPluginStatus and GetPluginTasks methods in the client for handling plugin-related data.
- Enhanced Sync functionality to include detailed reporting on plugin installation and deletion tasks.
- Added error handling and reporting for plugin synchronization failures.
- Created tests for new plugin synchronization and management features.
- Improved the overall structure and readability of the plugin synchronization logic.
2026-06-23 20:42:33 +08:00

40 lines
987 B
Go

package main
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/router-for-me/CLIProxyAPI/v7/internal/homeplugins"
)
const homePluginStatusReportTimeout = 10 * time.Second
type homePluginStatusClient interface {
RPushPluginStatus(ctx context.Context, payload []byte) error
}
func reportHomePluginStatus(ctx context.Context, client homePluginStatusClient, nodeID string, report homeplugins.SyncReport) error {
if client == nil {
return fmt.Errorf("home plugin status client is unavailable")
}
nodeID = strings.TrimSpace(nodeID)
if nodeID == "" {
return fmt.Errorf("home plugin status node id is empty")
}
report.NodeID = nodeID
report.UpdatedAt = time.Now().UTC()
raw, errMarshal := json.Marshal(report)
if errMarshal != nil {
return errMarshal
}
if ctx == nil {
ctx = context.Background()
}
reportCtx, cancel := context.WithTimeout(ctx, homePluginStatusReportTimeout)
defer cancel()
return client.RPushPluginStatus(reportCtx, raw)
}