2020-12-04 13:10:32 +01:00
|
|
|
package hub
|
2020-10-03 13:50:30 +02:00
|
|
|
|
2020-10-08 08:52:03 +02:00
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"runtime"
|
|
|
|
)
|
2020-10-03 13:50:30 +02:00
|
|
|
|
2020-12-04 13:10:32 +01:00
|
|
|
var ServiceURL = "https://hub.photoprism.app/v1/hello"
|
2020-10-03 13:50:30 +02:00
|
|
|
|
2021-11-20 12:29:21 +01:00
|
|
|
// Request represents basic environment specs for debugging.
|
2020-10-03 13:50:30 +02:00
|
|
|
type Request struct {
|
|
|
|
ClientVersion string `json:"ClientVersion"`
|
2020-12-05 06:21:16 +01:00
|
|
|
ClientSerial string `json:"ClientSerial"`
|
2020-10-03 13:50:30 +02:00
|
|
|
ClientOS string `json:"ClientOS"`
|
|
|
|
ClientArch string `json:"ClientArch"`
|
|
|
|
ClientCPU int `json:"ClientCPU"`
|
2022-03-02 14:16:49 +01:00
|
|
|
ClientEnv string `json:"ClientEnv"`
|
|
|
|
PartnerID string `json:"PartnerID"`
|
2022-07-19 16:58:43 +02:00
|
|
|
ApiToken string `json:"ApiToken"`
|
2020-10-03 13:50:30 +02:00
|
|
|
}
|
|
|
|
|
2021-11-20 12:29:21 +01:00
|
|
|
// NewRequest creates a new backend key request instance.
|
2022-07-19 16:58:43 +02:00
|
|
|
func NewRequest(version, serial, env, partnerId, token string) *Request {
|
2020-10-03 13:50:30 +02:00
|
|
|
return &Request{
|
|
|
|
ClientVersion: version,
|
2020-12-05 06:21:16 +01:00
|
|
|
ClientSerial: serial,
|
2020-10-03 13:50:30 +02:00
|
|
|
ClientOS: runtime.GOOS,
|
|
|
|
ClientArch: runtime.GOARCH,
|
|
|
|
ClientCPU: runtime.NumCPU(),
|
2022-03-02 14:16:49 +01:00
|
|
|
ClientEnv: env,
|
|
|
|
PartnerID: partnerId,
|
2022-07-19 16:58:43 +02:00
|
|
|
ApiToken: token,
|
2020-10-03 13:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-08 08:52:03 +02:00
|
|
|
|
2021-11-20 12:29:21 +01:00
|
|
|
// ApiHost returns the backend host name.
|
2020-10-08 08:52:03 +02:00
|
|
|
func ApiHost() string {
|
2020-12-04 13:10:32 +01:00
|
|
|
u, err := url.Parse(ServiceURL)
|
2020-10-08 08:52:03 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return u.Host
|
|
|
|
}
|