Merge branch 'master' of https://github.com/gabek/owncast
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"text/template"
|
||||
|
||||
"github.com/gabek/owncast/config"
|
||||
"github.com/gabek/owncast/core"
|
||||
"github.com/gabek/owncast/router/middleware"
|
||||
"github.com/gabek/owncast/utils"
|
||||
|
||||
"xojoc.pw/useragent"
|
||||
)
|
||||
|
||||
type MetadataPage struct {
|
||||
Config config.InstanceDetails
|
||||
RequestedURL string
|
||||
}
|
||||
|
||||
//IndexHandler handles the default index route
|
||||
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.EnableCors(&w)
|
||||
|
||||
ua := useragent.Parse(r.UserAgent())
|
||||
|
||||
if ua.Type == useragent.Crawler && r.URL.Path == "/" {
|
||||
handleScraperMetadataPage(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
|
||||
|
||||
if path.Ext(r.URL.Path) == ".m3u8" {
|
||||
@@ -22,3 +40,19 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
core.SetClientActive(clientID)
|
||||
}
|
||||
}
|
||||
|
||||
// Return a basic HTML page with server-rendered metadata from the config file
|
||||
// to give to Opengraph clients and web scrapers (bots, web crawlers, etc).
|
||||
func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.ParseFiles(path.Join("static", "metadata.html")))
|
||||
|
||||
fullURL := fmt.Sprintf("http://%s%s", r.Host, r.URL.Path)
|
||||
metadata := MetadataPage{config.Config.InstanceDetails, fullURL}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
err := tmpl.Execute(w, metadata)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@@ -18,4 +18,5 @@ require (
|
||||
github.com/yutopp/go-rtmp v0.0.0-20191212152852-4e41609a99bb
|
||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
xojoc.pw/useragent v0.0.0-20200116211053-1ec61d55e8fe
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1192,3 +1192,5 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
|
||||
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
|
||||
xojoc.pw/useragent v0.0.0-20200116211053-1ec61d55e8fe h1:KHyqPlOEFFT7OPh4WR7qFzNNndwj1VuwV+rZ+Tb3bio=
|
||||
xojoc.pw/useragent v0.0.0-20200116211053-1ec61d55e8fe/go.mod h1:71om/Qz9HbIEjbUrkrzmJiF26FSh6tcwqSFdBBkLtJQ=
|
||||
|
||||
54
static/metadata.html
Normal file
54
static/metadata.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>{{.Config.Name}}</title>
|
||||
<meta name="description" content="{{.Config.Summary}}">
|
||||
|
||||
<meta property="og:title" content="{{.Config.Title}}">
|
||||
<meta property="og:site_name" content="{{.Config.Title}}">
|
||||
<meta property="og:url" content="{{.RequestedURL}}">
|
||||
<meta property="og:description" content="{{.Config.Summary}}">
|
||||
<meta property="og:type" content="video">
|
||||
<meta property="og:image" content="{{.Config.Logo.large}}">
|
||||
<meta property="og:image:url" content="{{.Config.Logo.large}}">
|
||||
<meta property='og:video' content='{{.RequestedURL}}hls/stream.m3u8' />
|
||||
<meta property="og:video:height" content="640" />
|
||||
<meta property="og:video:width" content="385" />
|
||||
<meta property="og:video:type" content="application/x-mpegURL" />
|
||||
|
||||
<meta property="twitter:title" content="{{.Config.Title}}">
|
||||
<meta property="twitter:url" content="{{.RequestedURL}}">
|
||||
<meta property="twitter:description" content="{{.Config.Summary}}">
|
||||
<meta property="twitter:image" content="{{.Config.Logo.large}}">
|
||||
<meta property="twitter:site" content="{{.Config.SocialHandles.twitter}}">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>{{.Config.Title}}</h1>
|
||||
<h2>{{.Config.Name}}</h2>
|
||||
|
||||
<center>
|
||||
<img src="/thumbnail.jpg" width=10% />
|
||||
</center>
|
||||
|
||||
<h3>{{.Config.Summary}}</h3>
|
||||
|
||||
{{range .Config.Tags}}
|
||||
<li>{{.}}</li>
|
||||
{{end}}
|
||||
|
||||
<br/>
|
||||
|
||||
<h3>Connect with {{.Config.Name}} elsewhere by visiting:</h3>
|
||||
|
||||
{{range .Config.SocialHandles}}
|
||||
<li><a href="{{.}}">{{.}}</a></li>
|
||||
{{end}}
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user