Browse Source

Add GetVideoCoverUrl()

HEAD
Yang Luo 2 years ago
parent
commit
bed07e06af
4 changed files with 45 additions and 1 deletions
  1. +23
    -0
      controllers/video.go
  2. +14
    -0
      video/vod_api.go
  3. +7
    -0
      video/vod_api_test.go
  4. +1
    -1
      web/src/VideoEditPage.js

+ 23
- 0
controllers/video.go View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"time"

"github.com/casbin/casbase/object"
"github.com/casbin/casbase/util"
@@ -65,6 +66,26 @@ func (c *ApiController) DeleteVideo() {
c.ServeJSON()
}

func startCoverUrlJob(owner string, name string, videoId string) {
go func(owner string, name string, videoId string) {
for i := 0; i < 20; i++ {
coverUrl := video.GetVideoCoverUrl(videoId)
if coverUrl != "" {
video := object.GetVideo(util.GetIdFromOwnerAndName(owner, name))
if video.CoverUrl != "" {
break
}

video.CoverUrl = coverUrl
object.UpdateVideo(util.GetIdFromOwnerAndName(owner, name), video)
break
}

time.Sleep(time.Second * 5)
}
}(owner, name, videoId)
}

func (c *ApiController) UploadVideo() {
owner := c.GetSessionUsername()

@@ -94,6 +115,8 @@ func (c *ApiController) UploadVideo() {

videoId := video.UploadVideo(fileId, filename, fileBuffer)
if videoId != "" {
startCoverUrlJob(owner, fileId, videoId)

video := &object.Video{
Owner: owner,
Name: fileId,


+ 14
- 0
video/vod_api.go View File

@@ -77,3 +77,17 @@ func UploadVideo(fileId string, filename string, fileBuffer *bytes.Buffer) strin

return videoId
}

func GetVideoCoverUrl(videoId string) string {
r := vod.CreateGetVideoInfoRequest()
r.VideoId = videoId
r.AcceptFormat = "JSON"

resp, err := vodClient.GetVideoInfo(r)
if err != nil {
fmt.Println(err)
return err.Error()
}

return resp.Video.CoverURL
}

+ 7
- 0
video/vod_api_test.go View File

@@ -0,0 +1,7 @@
package video

import "testing"

func TestGetVideoCoverUrl(t *testing.T) {
println(GetVideoCoverUrl(""))
}

+ 1
- 1
web/src/VideoEditPage.js View File

@@ -151,7 +151,7 @@ class VideoEditPage extends React.Component {
{i18next.t("general:URL")} :
</Col>
<Col span={23} >
<Input prefix={<LinkOutlined/>} value={this.state.video.coverUrl} onChange={e => {
<Input disabled={true} prefix={<LinkOutlined/>} value={this.state.video.coverUrl} onChange={e => {
this.updateVideoField('coverUrl', e.target.value);
}} />
</Col>


Loading…
Cancel
Save