2020-10-02 08:55:38 +02:00
|
|
|
package yp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/config"
|
|
|
|
"github.com/owncast/owncast/utils"
|
2020-10-02 08:55:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type ypDetailsResponse struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Logo string `json:"logo"`
|
|
|
|
NSFW bool `json:"nsfw"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Online bool `json:"online"`
|
|
|
|
ViewerCount int `json:"viewerCount"`
|
|
|
|
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
|
|
|
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
|
|
|
|
|
|
|
LastConnectTime utils.NullTime `json:"lastConnectTime"`
|
|
|
|
}
|
|
|
|
|
2020-11-13 00:14:59 +01:00
|
|
|
// GetYPResponse gets the status of the server for YP purposes.
|
2020-10-02 08:55:38 +02:00
|
|
|
func GetYPResponse(w http.ResponseWriter, r *http.Request) {
|
|
|
|
status := getStatus()
|
|
|
|
|
|
|
|
response := ypDetailsResponse{
|
|
|
|
Name: config.Config.InstanceDetails.Name,
|
|
|
|
Description: config.Config.InstanceDetails.Summary,
|
|
|
|
Logo: config.Config.InstanceDetails.Logo.Large,
|
|
|
|
NSFW: config.Config.InstanceDetails.NSFW,
|
|
|
|
Tags: config.Config.InstanceDetails.Tags,
|
|
|
|
Online: status.Online,
|
|
|
|
ViewerCount: status.ViewerCount,
|
|
|
|
OverallMaxViewerCount: status.OverallMaxViewerCount,
|
|
|
|
SessionMaxViewerCount: status.SessionMaxViewerCount,
|
|
|
|
LastConnectTime: status.LastConnectTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
json.NewEncoder(w).Encode(response)
|
|
|
|
|
|
|
|
}
|