mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-04 13:27:21 +08:00 
			
		
		
		
	Add an endpoint for returning a most-compatible logo (non-svg) used in sharing and indexing. Closes #1286
This commit is contained in:
		@ -91,7 +91,7 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Panicln(err)
 | 
							log.Panicln(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	imageURL, err := url.Parse(fmt.Sprintf("%s://%s%s", scheme, r.Host, "/logo"))
 | 
						imageURL, err := url.Parse(fmt.Sprintf("%s://%s%s", scheme, r.Host, "/logo/external"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Panicln(err)
 | 
							log.Panicln(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,39 @@ func GetLogo(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	writeBytesAsImage(imageBytes, contentType, w, cacheTime)
 | 
						writeBytesAsImage(imageBytes, contentType, w, cacheTime)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetCompatibleLogo will return the logo unless it's a SVG
 | 
				
			||||||
 | 
					// and in that case will return a default placeholder.
 | 
				
			||||||
 | 
					// Used for sharing to external social networks that generally
 | 
				
			||||||
 | 
					// don't support SVG.
 | 
				
			||||||
 | 
					func GetCompatibleLogo(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						imageFilename := data.GetLogoPath()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If the logo image is not a SVG then we can return it
 | 
				
			||||||
 | 
						// without any problems.
 | 
				
			||||||
 | 
						if imageFilename != "" && filepath.Ext(imageFilename) != ".svg" {
 | 
				
			||||||
 | 
							GetLogo(w, r)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Otherwise use a fallback logo.png.
 | 
				
			||||||
 | 
						imagePath := filepath.Join(config.WebRoot, "img", "logo.png")
 | 
				
			||||||
 | 
						contentType := "image/png"
 | 
				
			||||||
 | 
						imageBytes, err := getImage(imagePath)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							returnDefault(w)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cacheTime := utils.GetCacheDurationSecondsForPath(imagePath)
 | 
				
			||||||
 | 
						writeBytesAsImage(imageBytes, contentType, w, cacheTime)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						referrer := r.Referer()
 | 
				
			||||||
 | 
						if referrer == "" {
 | 
				
			||||||
 | 
							referrer = "an external site"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						log.Warnf("%s requested your logo. because many social networks do not support SVGs we returned a placeholder instead. change your current logo \"%s\" to a png or jpeg to be most compatible with external social networking sites.", referrer, imageFilename)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func returnDefault(w http.ResponseWriter) {
 | 
					func returnDefault(w http.ResponseWriter) {
 | 
				
			||||||
	imagePath := filepath.Join(config.WebRoot, "img", "logo.svg")
 | 
						imagePath := filepath.Join(config.WebRoot, "img", "logo.svg")
 | 
				
			||||||
	imageBytes, err := getImage(imagePath)
 | 
						imageBytes, err := getImage(imagePath)
 | 
				
			||||||
 | 
				
			|||||||
@ -57,6 +57,9 @@ func Start() error {
 | 
				
			|||||||
	// return the logo
 | 
						// return the logo
 | 
				
			||||||
	http.HandleFunc("/logo", controllers.GetLogo)
 | 
						http.HandleFunc("/logo", controllers.GetLogo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// return a logo that's compatible with external social networks
 | 
				
			||||||
 | 
						http.HandleFunc("/logo/external", controllers.GetCompatibleLogo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// return the list of video variants available
 | 
						// return the list of video variants available
 | 
				
			||||||
	http.HandleFunc("/api/video/variants", controllers.GetVideoStreamOutputVariants)
 | 
						http.HandleFunc("/api/video/variants", controllers.GetVideoStreamOutputVariants)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user