MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Test

Method Test

service/admin/node.go:81–120  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

79)
80
81func (service *TestNodeService) Test(c *gin.Context) error {
82 dep := dependency.FromContext(c)
83 settings := dep.SettingProvider()
84
85 slave, err := url.Parse(service.Node.Server)
86 if err != nil {
87 return serializer.NewError(serializer.CodeParamErr, "Failed to parse node URL", err)
88 }
89
90 primaryURL := settings.SiteURL(setting.UseFirstSiteUrl(c)).String()
91 body := map[string]string{
92 "callback": primaryURL,
93 }
94 bodyByte, _ := json.Marshal(body)
95
96 r := dep.RequestClient()
97 res, err := r.Request(
98 "POST",
99 routes.SlavePingRoute(slave),
100 bytes.NewReader(bodyByte),
101 request.WithTimeout(time.Duration(10)*time.Second),
102 request.WithCredential(
103 auth.HMACAuth{SecretKey: []byte(service.Node.SlaveKey)},
104 int64(settings.SlaveRequestSignTTL(c)),
105 ),
106 request.WithSlaveMeta(int(service.Node.ID)),
107 request.WithMasterMeta(settings.SiteBasic(c).ID, primaryURL),
108 request.WithCorrelationID(),
109 ).CheckHTTPResponse(http.StatusOK).DecodeResponse()
110
111 if err != nil {
112 return serializer.NewError(serializer.CodeParamErr, "Failed to connect to node: "+err.Error(), nil)
113 }
114
115 if res.Code != 0 {
116 return serializer.NewError(serializer.CodeParamErr, "Successfully connected to slave node, but slave returns: "+res.Msg, nil)
117 }
118
119 return nil
120}
121
122type (
123 TestNodeDownloaderService struct {

Callers

nothing calls this directly

Calls 15

FromContextFunction · 0.92
NewErrorFunction · 0.92
UseFirstSiteUrlFunction · 0.92
SlavePingRouteFunction · 0.92
WithTimeoutFunction · 0.92
WithCredentialFunction · 0.92
WithSlaveMetaFunction · 0.92
WithMasterMetaFunction · 0.92
WithCorrelationIDFunction · 0.92
ParseMethod · 0.80
DecodeResponseMethod · 0.80
CheckHTTPResponseMethod · 0.80

Tested by

no test coverage detected