Skip to content

Commit

Permalink
add .mp4 endpoint so discord can parse the og video tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed May 28, 2024
1 parent 4101df0 commit fa375eb
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Config struct {
Host string `validate:"required,min=1,max=120"`

AppName string
BaseUrl string

Project string
ProjectDocumentation string
Expand Down Expand Up @@ -74,6 +75,7 @@ type Config struct {

type PublicConfig struct {
AppName string
BaseUrl string
Project string
EncodingEnabled bool
UploadEnabled bool
Expand All @@ -93,6 +95,7 @@ type PublicConfig struct {
func (c Config) PublicConfig() PublicConfig {
return PublicConfig{
AppName: c.AppName,
BaseUrl: c.BaseUrl,
Project: c.Project,
EncodingEnabled: *c.EncodingEnabled,
UploadEnabled: *c.UploadEnabled,
Expand Down
1 change: 1 addition & 0 deletions configdb/configdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Setup() {
}

config.ENV.AppName = getEnvDb(&setting.AppName, "VideoCMS")
config.ENV.BaseUrl = getEnvDb(&setting.BaseUrl, "http://127.0.0.1:3000")

config.ENV.Project = getEnvDb(&setting.Project, "https://github.com/notfound")
config.ENV.ProjectDocumentation = getEnvDb(&setting.ProjectDocumentation, "https://github.com/notfound")
Expand Down
2 changes: 1 addition & 1 deletion controllers/DownloadVideoController.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func DownloadVideoController(c echo.Context) error {
type Request struct {
UUID string `validate:"required,uuid_rfc4122" param:"UUID"`
QUALITY string `validate:"required,min=1,max=10" param:"QUALITY"`
Stream *bool `validate:"omitempty,boolean" query:"stream"`
Stream *bool `validate:"omitempty,boolean" param:"STREAM"`
}
var requestValidation Request
if status, err := helpers.Validate(c, &requestValidation); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion controllers/PlayerController.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func PlayerController(c echo.Context) error {
"height": strconv.Itoa(int(qualiItem.Height)),
"width": strconv.Itoa(int(qualiItem.Width)),
})
streamUrl = fmt.Sprintf("%s/%s/%s/download/video.mkv?stream=1&jwt=%s", config.ENV.FolderVideoQualitysPub, dbLink.UUID, qualiItem.Name, tkn)
streamUrl = fmt.Sprintf("%s/%s/%s/%s/1/stream/video.mp4", config.ENV.FolderVideoQualitysPub, dbLink.UUID, qualiItem.Name, tkn)
streamUrlHeight = strconv.Itoa(int(qualiItem.Height))
streamUrlWidth = strconv.Itoa(int(qualiItem.Width))
}
Expand Down Expand Up @@ -159,5 +159,6 @@ func PlayerController(c echo.Context) error {
"Folder": config.ENV.FolderVideoQualitysPub,
"JWT": tkn,
"AppName": config.ENV.AppName,
"BaseUrl": config.ENV.BaseUrl,
})
}
1 change: 1 addition & 0 deletions controllers/UpdateSettingsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func UpdateSettings(c echo.Context) error {
var setting models.Setting
setting.ID = validation.ID
setting.AppName = validation.AppName
setting.BaseUrl = validation.BaseUrl
setting.Project = validation.Project
setting.ProjectDocumentation = validation.ProjectDocumentation
setting.ProjectDownload = validation.ProjectDownload
Expand Down
5 changes: 4 additions & 1 deletion middlewares/JwtStream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ func JwtStream() echo.MiddlewareFunc {
}
tknStr := c.QueryParam("jwt")
if tknStr == "" {
return c.String(http.StatusBadRequest, "UUID parameter match issue")
tknStr = c.Param("JWT")
if tknStr == "" {
return c.String(http.StatusBadRequest, "UUID parameter match issue")
}
}
token, claims, err := auth.VerifyJWTStream(tknStr)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions models/Setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type SettingValidation struct {
type Setting struct {
Model
AppName string `validate:"required,min=1,max=120" gorm:"size:120;"`
BaseUrl string `validate:"required,min=1,max=255" gorm:"size:255;"`

Project string `validate:"required,min=1,max=512" gorm:"size:512;"`
ProjectDocumentation string `validate:"required,min=1,max=512" gorm:"size:512;"`
Expand Down
1 change: 1 addition & 0 deletions routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Web() {
videoData.GET("/:UUID/:SUBUUID/subtitle/:FILE", controllers.GetSubtitleData, middlewares.JwtStream())
videoData.GET("/:UUID/:AUDIOUUID/stream/master.m3u8", controllers.GetM3u8Data, middlewares.JwtStream())
videoData.GET("/:UUID/:QUALITY/download/video.mkv", controllers.DownloadVideoController, middlewares.JwtStream())
videoData.GET("/:UUID/:QUALITY/:JWT/:STREAM/stream/video.mp4", controllers.DownloadVideoController, middlewares.JwtStream())
// no jwt stream
videoData.GET("/:UUID/:QUALITY/:FILE", controllers.GetVideoData)
videoData.GET("/:UUID/:AUDIOUUID/audio/:FILE", controllers.GetAudioData)
Expand Down
4 changes: 2 additions & 2 deletions views/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<meta name="twitter:image" content="{{ .Thumbnail}}" />
<meta property="og:type" content="video">
<meta property="og:url" content="/v/{{.UUID}}">
<meta property="og:video" content="{{.StreamUrl}}">
<meta property="og:video:secure_url" content="{{.StreamUrl}}">
<meta property="og:video" content="{{.BaseUrl}}{{.StreamUrl}}">
<meta property="og:video:secure_url" content="{{.BaseUrl}}{{.StreamUrl}}">
<meta property="og:video:width" content="{{.StreamUrlWidth}}">
<meta property="og:video:height" content="{{.StreamUrlHeight}}">
<meta property="og:site_name" content="{{.AppName}}">
Expand Down

0 comments on commit fa375eb

Please sign in to comment.