Browse Source

Merge branch 'separate-logo-and-offline-stream-image' into develop

develop
forest 2 months ago
parent
commit
1339c81072
9 changed files with 115 additions and 58 deletions
  1. +11
    -2
      controllers/admin/config.go
  2. +23
    -21
      controllers/admin/serverConfig.go
  3. +26
    -24
      controllers/config.go
  4. +13
    -4
      controllers/logo.go
  5. +6
    -5
      core/core.go
  6. +27
    -0
      core/data/config.go
  7. +6
    -0
      router/router.go
  8. +2
    -1
      webroot/js/app.js
  9. +1
    -1
      webroot/js/components/player.js

+ 11
- 2
controllers/admin/config.go View File

@ -182,6 +182,15 @@ func SetStreamKey(w http.ResponseWriter, r *http.Request) {
// SetLogo will handle a new logo image file being uploaded.
func SetLogo(w http.ResponseWriter, r *http.Request) {
handleSetImage(w, r, "logo", data.SetLogoPath)
}
// SetLogo will handle a new logo image file being uploaded.
func SetOfflineStreamImage(w http.ResponseWriter, r *http.Request) {
handleSetImage(w, r, "offlineStreamImage", data.SetOfflineStreamImagePath)
}
func handleSetImage(w http.ResponseWriter, r *http.Request, name string, imagePathSetter func(string) error) {
if !requirePOST(w, r) {
return
}
@ -224,13 +233,13 @@ func SetLogo(w http.ResponseWriter, r *http.Request) {
return
}
imgPath := filepath.Join("data", "logo"+extension)
imgPath := filepath.Join("data", name+extension)
if err := ioutil.WriteFile(imgPath, bytes, 0644); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())
return
}
if err := data.SetLogoPath("logo" + extension); err != nil {
if err := imagePathSetter(name + extension); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())
return
}


+ 23
- 21
controllers/admin/serverConfig.go View File

@ -32,16 +32,17 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
}
response := serverConfigAdminResponse{
InstanceDetails: webConfigResponse{
Name: data.GetServerName(),
Summary: data.GetServerSummary(),
Tags: data.GetServerMetadataTags(),
ExtraPageContent: data.GetExtraPageBodyContent(),
StreamTitle: data.GetStreamTitle(),
WelcomeMessage: data.GetServerWelcomeMessage(),
Logo: data.GetLogoPath(),
SocialHandles: data.GetSocialHandles(),
NSFW: data.GetNSFW(),
CustomStyles: data.GetCustomStyles(),
Name: data.GetServerName(),
Summary: data.GetServerSummary(),
Tags: data.GetServerMetadataTags(),
ExtraPageContent: data.GetExtraPageBodyContent(),
StreamTitle: data.GetStreamTitle(),
WelcomeMessage: data.GetServerWelcomeMessage(),
Logo: data.GetLogoPath(),
OfflineStreamImage: data.GetOfflineStreamImagePath(),
SocialHandles: data.GetSocialHandles(),
NSFW: data.GetNSFW(),
CustomStyles: data.GetCustomStyles(),
},
FFmpegPath: ffmpeg,
StreamKey: data.GetStreamKey(),
@ -95,17 +96,18 @@ type videoSettings struct {
}
type webConfigResponse struct {
Name string `json:"name"`
Summary string `json:"summary"`
WelcomeMessage string `json:"welcomeMessage"`
Logo string `json:"logo"`
Tags []string `json:"tags"`
Version string `json:"version"`
NSFW bool `json:"nsfw"`
ExtraPageContent string `json:"extraPageContent"`
StreamTitle string `json:"streamTitle"` // What's going on with the current stream
SocialHandles []models.SocialHandle `json:"socialHandles"`
CustomStyles string `json:"customStyles"`
Name string `json:"name"`
Summary string `json:"summary"`
WelcomeMessage string `json:"welcomeMessage"`
Logo string `json:"logo"`
OfflineStreamImage string `json:"offlineStreamImage"`
Tags []string `json:"tags"`
Version string `json:"version"`
NSFW bool `json:"nsfw"`
ExtraPageContent string `json:"extraPageContent"`
StreamTitle string `json:"streamTitle"` // What's going on with the current stream
SocialHandles []models.SocialHandle `json:"socialHandles"`
CustomStyles string `json:"customStyles"`
}
type yp struct {


+ 26
- 24
controllers/config.go View File

@ -12,18 +12,19 @@ import (
)
type webConfigResponse struct {
Name string `json:"name"`
Summary string `json:"summary"`
Logo string `json:"logo"`
Tags []string `json:"tags"`
Version string `json:"version"`
NSFW bool `json:"nsfw"`
ExtraPageContent string `json:"extraPageContent"`
StreamTitle string `json:"streamTitle,omitempty"` // What's going on with the current stream
SocialHandles []models.SocialHandle `json:"socialHandles"`
ChatDisabled bool `json:"chatDisabled"`
ExternalActions []models.ExternalAction `json:"externalActions"`
CustomStyles string `json:"customStyles"`
Name string `json:"name"`
Summary string `json:"summary"`
Logo string `json:"logo"`
OfflineStreamImage string `json:"offlineStreamImage"`
Tags []string `json:"tags"`
Version string `json:"version"`
NSFW bool `json:"nsfw"`
ExtraPageContent string `json:"extraPageContent"`
StreamTitle string `json:"streamTitle,omitempty"` // What's going on with the current stream
SocialHandles []models.SocialHandle `json:"socialHandles"`
ChatDisabled bool `json:"chatDisabled"`
ExternalActions []models.ExternalAction `json:"externalActions"`
CustomStyles string `json:"customStyles"`
}
// GetWebConfig gets the status of the server.
@ -45,18 +46,19 @@ func GetWebConfig(w http.ResponseWriter, r *http.Request) {
serverSummary = utils.RenderPageContentMarkdown(serverSummary)
configuration := webConfigResponse{
Name: data.GetServerName(),
Summary: serverSummary,
Logo: "/logo",
Tags: data.GetServerMetadataTags(),
Version: config.GetReleaseString(),
NSFW: data.GetNSFW(),
ExtraPageContent: pageContent,
StreamTitle: data.GetStreamTitle(),
SocialHandles: socialHandles,
ChatDisabled: data.GetChatDisabled(),
ExternalActions: data.GetExternalActions(),
CustomStyles: data.GetCustomStyles(),
Name: data.GetServerName(),
Summary: serverSummary,
Logo: "/logo",
OfflineStreamImage: "/offlineStreamImage",
Tags: data.GetServerMetadataTags(),
Version: config.GetReleaseString(),
NSFW: data.GetNSFW(),
ExtraPageContent: pageContent,
StreamTitle: data.GetStreamTitle(),
SocialHandles: socialHandles,
ChatDisabled: data.GetChatDisabled(),
ExternalActions: data.GetExternalActions(),
CustomStyles: data.GetCustomStyles(),
}
if err := json.NewEncoder(w).Encode(configuration); err != nil {


+ 13
- 4
controllers/logo.go View File

@ -14,15 +14,24 @@ import (
// GetLogo will return the logo image as a response.
func GetLogo(w http.ResponseWriter, r *http.Request) {
imageFilename := data.GetLogoPath()
handleGetImage(w, r, data.GetLogoPath(), returnDefault)
}
// GetLogo will return the logo image as a response.
func GetOfflineStreamImage(w http.ResponseWriter, r *http.Request) {
handleGetImage(w, r, data.GetOfflineStreamImagePath(), GetLogo)
}
func handleGetImage(w http.ResponseWriter, r *http.Request, imageFilename string, returnDefault func(http.ResponseWriter, *http.Request)) {
if imageFilename == "" {
returnDefault(w)
returnDefault(w, r)
return
}
imagePath := filepath.Join("data", imageFilename)
imageBytes, err := getImage(imagePath)
if err != nil {
returnDefault(w)
returnDefault(w, r)
return
}
@ -39,7 +48,7 @@ func GetLogo(w http.ResponseWriter, r *http.Request) {
writeBytesAsImage(imageBytes, contentType, w, cacheTime)
}
func returnDefault(w http.ResponseWriter) {
func returnDefault(w http.ResponseWriter, r *http.Request) {
imagePath := filepath.Join(config.WebRoot, "img", "logo.svg")
imageBytes, err := getImage(imagePath)
if err != nil {


+ 6
- 5
core/core.go View File

@ -83,6 +83,7 @@ func Start() error {
func createInitialOfflineState() error {
// Provide default files
if !utils.DoesFileExists(filepath.Join(config.WebRoot, "thumbnail.jpg")) {
// TODO use the offline stream image here somehow?
if err := utils.Copy("static/logo.png", filepath.Join(config.WebRoot, "thumbnail.jpg")); err != nil {
return err
}
@ -107,8 +108,8 @@ func transitionToOfflineVideoStreamContent() {
_transcoder.Start()
// Copy the logo to be the thumbnail
logo := data.GetLogoPath()
err := utils.Copy(filepath.Join("data", logo), "webroot/thumbnail.jpg")
offlineStreamImage := data.GetOfflineStreamImagePath()
err := utils.Copy(filepath.Join("data", offlineStreamImage), "webroot/thumbnail.jpg")
if err != nil {
log.Warnln(err)
}
@ -134,9 +135,9 @@ func resetDirectories() {
}
// Remove the previous thumbnail
logo := data.GetLogoPath()
if utils.DoesFileExists(logo) {
err = utils.Copy(path.Join("data", logo), filepath.Join(config.WebRoot, "thumbnail.jpg"))
offlineStreamImage := data.GetOfflineStreamImagePath()
if utils.DoesFileExists(offlineStreamImage) {
err = utils.Copy(path.Join("data", offlineStreamImage), filepath.Join(config.WebRoot, "thumbnail.jpg"))
if err != nil {
log.Warnln(err)
}


+ 27
- 0
core/data/config.go View File

@ -17,6 +17,7 @@ const extraContentKey = "extra_page_content"
const streamTitleKey = "stream_title"
const streamKeyKey = "stream_key"
const logoPathKey = "logo_path"
const offlineStreamImageKey = "offline_stream_image"
const serverSummaryKey = "server_summary"
const serverWelcomeMessageKey = "server_welcome_message"
const serverNameKey = "server_name"
@ -110,6 +111,26 @@ func SetLogoPath(logo string) error {
return _datastore.SetString(logoPathKey, logo)
}
// GetOfflineStreamImagePath will return the path for the offline stream image, relative to webroot.
func GetOfflineStreamImagePath() string {
offlineStreamImage, err := _datastore.GetString(offlineStreamImageKey)
if err != nil {
log.Traceln(offlineStreamImageKey, err)
return config.GetDefaults().Logo
}
if offlineStreamImage == "" {
return GetLogoPath()
}
return offlineStreamImage
}
// SetOfflineStreamImagePath will set the path for the offline stream image, relative to webroot.
func SetOfflineStreamImagePath(offlineStreamImage string) error {
return _datastore.SetString(offlineStreamImageKey, offlineStreamImage)
}
// GetServerSummary will return the server summary text.
func GetServerSummary() string {
summary, err := _datastore.GetString(serverSummaryKey)
@ -526,6 +547,12 @@ func VerifySettings() error {
return errors.New("no stream key set. Please set one in your config file")
}
offlineStreamImagePath := GetOfflineStreamImagePath()
if !utils.DoesFileExists(filepath.Join(config.DataDirectory, offlineStreamImagePath)) {
log.Traceln(offlineStreamImagePath, "not found in the data directory. disabling custom offline stream image.")
SetOfflineStreamImagePath("")
}
logoPath := GetLogoPath()
if !utils.DoesFileExists(filepath.Join(config.DataDirectory, logoPath)) {
defaultLogo := filepath.Join(config.WebRoot, "img/logo.svg")


+ 6
- 0
router/router.go View File

@ -58,6 +58,9 @@ func Start() error {
// return the logo
http.HandleFunc("/logo", controllers.GetLogo)
// return the offlineStreamImage
http.HandleFunc("/offlineStreamImage", controllers.GetOfflineStreamImage)
// return the list of video variants available
http.HandleFunc("/api/video/variants", controllers.GetVideoStreamOutputVariants)
@ -163,6 +166,9 @@ func Start() error {
// Logo path
http.HandleFunc("/api/admin/config/logo", middleware.RequireAdminAuth(admin.SetLogo))
// OfflineStreamImage path
http.HandleFunc("/api/admin/config/offlineStreamImage", middleware.RequireAdminAuth(admin.SetOfflineStreamImage))
// Server tags
http.HandleFunc("/api/admin/config/tags", middleware.RequireAdminAuth(admin.SetTags))


+ 2
- 1
webroot/js/app.js View File

@ -512,6 +512,7 @@ export default class App extends Component {
const {
version: appVersion,
logo = TEMP_IMAGE,
offlineStreamImage = TEMP_IMAGE,
socialHandles = [],
summary,
tags = [],
@ -552,7 +553,7 @@ export default class App extends Component {
const poster = isPlaying
? null
: html` <${VideoPoster} offlineImage=${logo} active=${streamOnline} /> `;
: html` <${VideoPoster} offlineImage=${offlineStreamImage} active=${streamOnline} /> `;
const externalActionButtons =
externalActions &&


+ 1
- 1
webroot/js/components/player.js View File

@ -34,7 +34,7 @@ const VIDEO_OPTIONS = {
sources: [VIDEO_SRC],
};
export const POSTER_DEFAULT = `/img/logo.png`;
export const POSTER_DEFAULT = `/offlineStreamImage`;
export const POSTER_THUMB = `/thumbnail.jpg`;
class OwncastPlayer {


Loading…
Cancel
Save