mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-24 21:09:16 +08:00
- 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.
40 lines
987 B
Go
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)
|
|
}
|