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
|
|
|
|
2020-12-04 13:10:32 +01:00
|
|
|
// Backend api credentials request incl basic runtime specs.
|
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"`
|
|
|
|
}
|
|
|
|
|
2020-12-04 13:10:32 +01:00
|
|
|
// NewRequest creates a new hub key request instance.
|
2020-12-05 06:21:16 +01:00
|
|
|
func NewRequest(version, serial 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(),
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 08:52:03 +02:00
|
|
|
|
|
|
|
// ApiHost returns the full API URL host name.
|
|
|
|
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
|
|
|
|
}
|