2020-06-29 01:10:00 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-01-13 00:53:10 +03:00
|
|
|
"fmt"
|
2020-06-29 01:10:00 +03:00
|
|
|
"net/http"
|
2022-01-13 00:53:10 +03:00
|
|
|
"net/url"
|
2020-06-29 01:10:00 +03:00
|
|
|
|
2022-01-13 00:53:10 +03:00
|
|
|
"github.com/owncast/owncast/activitypub"
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/config"
|
2021-02-19 10:05:52 +03:00
|
|
|
"github.com/owncast/owncast/core/data"
|
|
|
|
"github.com/owncast/owncast/models"
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/router/middleware"
|
2021-02-19 10:05:52 +03:00
|
|
|
"github.com/owncast/owncast/utils"
|
2022-03-18 23:33:23 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-06-29 01:10:00 +03:00
|
|
|
)
|
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
type webConfigResponse struct {
|
2023-05-30 20:31:43 +03:00
|
|
|
AppearanceVariables map[string]string `json:"appearanceVariables"`
|
2023-10-09 00:22:28 +03:00
|
|
|
Name string `json:"name"`
|
2023-05-30 20:31:43 +03:00
|
|
|
CustomStyles string `json:"customStyles"`
|
2023-10-09 00:22:28 +03:00
|
|
|
StreamTitle string `json:"streamTitle,omitempty"` // What's going on with the current stream
|
2022-08-10 08:09:43 +03:00
|
|
|
OfflineMessage string `json:"offlineMessage"`
|
2022-04-22 00:55:26 +03:00
|
|
|
Logo string `json:"logo"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
SocketHostOverride string `json:"socketHostOverride,omitempty"`
|
|
|
|
ExtraPageContent string `json:"extraPageContent"`
|
2023-10-09 00:22:28 +03:00
|
|
|
Summary string `json:"summary"`
|
|
|
|
Tags []string `json:"tags"`
|
2022-04-22 00:55:26 +03:00
|
|
|
SocialHandles []models.SocialHandle `json:"socialHandles"`
|
|
|
|
ExternalActions []models.ExternalAction `json:"externalActions"`
|
2023-10-09 00:22:28 +03:00
|
|
|
Notifications notificationsConfigResponse `json:"notifications"`
|
|
|
|
Federation federationConfigResponse `json:"federation"`
|
2022-04-22 00:55:26 +03:00
|
|
|
MaxSocketPayloadSize int `json:"maxSocketPayloadSize"`
|
2023-10-09 00:22:28 +03:00
|
|
|
HideViewerCount bool `json:"hideViewerCount"`
|
2023-05-30 20:31:43 +03:00
|
|
|
ChatDisabled bool `json:"chatDisabled"`
|
|
|
|
NSFW bool `json:"nsfw"`
|
2022-04-22 00:55:26 +03:00
|
|
|
Authentication authenticationConfigResponse `json:"authentication"`
|
2022-01-13 00:53:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type federationConfigResponse struct {
|
|
|
|
Account string `json:"account,omitempty"`
|
|
|
|
FollowerCount int `json:"followerCount,omitempty"`
|
2023-05-30 20:31:43 +03:00
|
|
|
Enabled bool `json:"enabled"`
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
|
|
|
|
2022-03-18 23:33:23 +03:00
|
|
|
type browserNotificationsConfigResponse struct {
|
|
|
|
PublicKey string `json:"publicKey,omitempty"`
|
2023-05-30 20:31:43 +03:00
|
|
|
Enabled bool `json:"enabled"`
|
2022-03-18 23:33:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type notificationsConfigResponse struct {
|
|
|
|
Browser browserNotificationsConfigResponse `json:"browser"`
|
|
|
|
}
|
|
|
|
|
2022-04-22 00:55:26 +03:00
|
|
|
type authenticationConfigResponse struct {
|
|
|
|
IndieAuthEnabled bool `json:"indieAuthEnabled"`
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// GetWebConfig gets the status of the server.
|
2020-06-29 01:10:00 +03:00
|
|
|
func GetWebConfig(w http.ResponseWriter, r *http.Request) {
|
2021-10-01 22:40:13 +03:00
|
|
|
middleware.EnableCors(w)
|
2021-11-17 07:58:03 +03:00
|
|
|
middleware.DisableCache(w)
|
2020-11-20 02:26:43 +03:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
2020-06-29 01:10:00 +03:00
|
|
|
|
2022-09-11 01:37:07 +03:00
|
|
|
configuration := getConfigResponse()
|
|
|
|
|
|
|
|
if err := json.NewEncoder(w).Encode(configuration); err != nil {
|
|
|
|
BadRequestHandler(w, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getConfigResponse() webConfigResponse {
|
2021-02-19 10:05:52 +03:00
|
|
|
pageContent := utils.RenderPageContentMarkdown(data.GetExtraPageBodyContent())
|
2023-05-02 05:45:27 +03:00
|
|
|
offlineMessage := utils.RenderSimpleMarkdown(data.GetCustomOfflineMessage())
|
2021-02-19 10:05:52 +03:00
|
|
|
socialHandles := data.GetSocialHandles()
|
|
|
|
for i, handle := range socialHandles {
|
|
|
|
platform := models.GetSocialHandle(handle.Platform)
|
|
|
|
if platform != nil {
|
|
|
|
handle.Icon = platform.Icon
|
|
|
|
socialHandles[i] = handle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-23 03:09:57 +03:00
|
|
|
serverSummary := data.GetServerSummary()
|
|
|
|
|
2022-01-13 00:53:10 +03:00
|
|
|
var federationResponse federationConfigResponse
|
|
|
|
federationEnabled := data.GetFederationEnabled()
|
|
|
|
|
|
|
|
followerCount, _ := activitypub.GetFollowerCount()
|
|
|
|
if federationEnabled {
|
|
|
|
serverURLString := data.GetServerURL()
|
|
|
|
serverURL, _ := url.Parse(serverURLString)
|
|
|
|
account := fmt.Sprintf("%s@%s", data.GetDefaultFederationUsername(), serverURL.Host)
|
|
|
|
federationResponse = federationConfigResponse{
|
|
|
|
Enabled: federationEnabled,
|
|
|
|
FollowerCount: int(followerCount),
|
|
|
|
Account: account,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:33:23 +03:00
|
|
|
browserPushEnabled := data.GetBrowserPushConfig().Enabled
|
|
|
|
browserPushPublicKey, err := data.GetBrowserPushPublicKey()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln("unable to fetch browser push notifications public key", err)
|
|
|
|
browserPushEnabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationsResponse := notificationsConfigResponse{
|
|
|
|
Browser: browserNotificationsConfigResponse{
|
|
|
|
Enabled: browserPushEnabled,
|
|
|
|
PublicKey: browserPushPublicKey,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-04-22 00:55:26 +03:00
|
|
|
authenticationResponse := authenticationConfigResponse{
|
|
|
|
IndieAuthEnabled: data.GetServerURL() != "",
|
|
|
|
}
|
|
|
|
|
2022-09-11 01:37:07 +03:00
|
|
|
return webConfigResponse{
|
2021-07-20 05:22:29 +03:00
|
|
|
Name: data.GetServerName(),
|
|
|
|
Summary: serverSummary,
|
2023-05-02 05:45:27 +03:00
|
|
|
OfflineMessage: offlineMessage,
|
2021-07-20 05:22:29 +03:00
|
|
|
Logo: "/logo",
|
|
|
|
Tags: data.GetServerMetadataTags(),
|
|
|
|
Version: config.GetReleaseString(),
|
|
|
|
NSFW: data.GetNSFW(),
|
2022-03-07 04:11:51 +03:00
|
|
|
SocketHostOverride: data.GetWebsocketOverrideHost(),
|
2021-07-20 05:22:29 +03:00
|
|
|
ExtraPageContent: pageContent,
|
|
|
|
StreamTitle: data.GetStreamTitle(),
|
|
|
|
SocialHandles: socialHandles,
|
|
|
|
ChatDisabled: data.GetChatDisabled(),
|
|
|
|
ExternalActions: data.GetExternalActions(),
|
|
|
|
CustomStyles: data.GetCustomStyles(),
|
|
|
|
MaxSocketPayloadSize: config.MaxSocketPayloadSize,
|
2022-01-13 00:53:10 +03:00
|
|
|
Federation: federationResponse,
|
2022-03-18 23:33:23 +03:00
|
|
|
Notifications: notificationsResponse,
|
2022-04-22 00:55:26 +03:00
|
|
|
Authentication: authenticationResponse,
|
2022-11-13 07:26:55 +03:00
|
|
|
AppearanceVariables: data.GetCustomColorVariableValues(),
|
2023-04-01 08:15:24 +03:00
|
|
|
HideViewerCount: data.GetHideViewerCount(),
|
2021-02-19 10:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAllSocialPlatforms will return a list of all social platform types.
|
|
|
|
func GetAllSocialPlatforms(w http.ResponseWriter, r *http.Request) {
|
2021-10-01 22:40:13 +03:00
|
|
|
middleware.EnableCors(w)
|
2021-02-19 10:05:52 +03:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
platforms := models.GetAllSocialHandles()
|
|
|
|
if err := json.NewEncoder(w).Encode(platforms); err != nil {
|
|
|
|
InternalErrorHandler(w, err)
|
2020-11-15 05:39:53 +03:00
|
|
|
}
|
2020-06-29 01:10:00 +03:00
|
|
|
}
|