2020-10-02 09:55:38 +03:00
|
|
|
package yp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
"github.com/owncast/owncast/models"
|
2024-11-16 06:20:58 +03:00
|
|
|
"github.com/owncast/owncast/persistence/configrepository"
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/utils"
|
2020-11-15 05:39:53 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-10-02 09:55:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type ypDetailsResponse struct {
|
2023-05-30 20:31:43 +03:00
|
|
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
StreamTitle string `json:"streamTitle,omitempty"`
|
|
|
|
Logo string `json:"logo"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Social []models.SocialHandle `json:"social"`
|
|
|
|
|
|
|
|
ViewerCount int `json:"viewerCount"`
|
|
|
|
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
|
|
|
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
|
|
|
NSFW bool `json:"nsfw"`
|
|
|
|
Online bool `json:"online"`
|
2020-10-02 09:55:38 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// GetYPResponse gets the status of the server for YP purposes.
|
2020-10-02 09:55:38 +03:00
|
|
|
func GetYPResponse(w http.ResponseWriter, r *http.Request) {
|
2024-11-16 06:20:58 +03:00
|
|
|
configRepository := configrepository.Get()
|
|
|
|
if !configRepository.GetDirectoryEnabled() {
|
2021-02-19 10:05:52 +03:00
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-02 09:55:38 +03:00
|
|
|
status := getStatus()
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
streamTitle := configRepository.GetStreamTitle()
|
2021-02-19 10:05:52 +03:00
|
|
|
|
2020-10-02 09:55:38 +03:00
|
|
|
response := ypDetailsResponse{
|
2024-11-16 06:20:58 +03:00
|
|
|
Name: configRepository.GetServerName(),
|
|
|
|
Description: configRepository.GetServerSummary(),
|
2021-02-19 10:05:52 +03:00
|
|
|
StreamTitle: streamTitle,
|
2021-02-23 10:32:51 +03:00
|
|
|
Logo: "/logo",
|
2024-11-16 06:20:58 +03:00
|
|
|
NSFW: configRepository.GetNSFW(),
|
|
|
|
Tags: configRepository.GetServerMetadataTags(),
|
2020-10-02 09:55:38 +03:00
|
|
|
Online: status.Online,
|
|
|
|
ViewerCount: status.ViewerCount,
|
|
|
|
OverallMaxViewerCount: status.OverallMaxViewerCount,
|
|
|
|
SessionMaxViewerCount: status.SessionMaxViewerCount,
|
|
|
|
LastConnectTime: status.LastConnectTime,
|
2024-11-16 06:20:58 +03:00
|
|
|
Social: configRepository.GetSocialHandles(),
|
2020-10-02 09:55:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
2020-11-15 05:39:53 +03:00
|
|
|
err := json.NewEncoder(w).Encode(response)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
2020-10-02 09:55:38 +03:00
|
|
|
}
|