Skip to content

Commit

Permalink
[update] enable private videos
Browse files Browse the repository at this point in the history
  • Loading branch information
popper2710 committed May 12, 2020
1 parent d6072d4 commit 0738ae8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/src/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/go-playground/locales/currency"
"github.com/google/uuid"
"github.com/oklog/ulid/v2"
"golang.org/x/crypto/bcrypt"
Expand All @@ -22,6 +23,7 @@ func GetIndex(c *gin.Context) {
c.HTML(http.StatusOK, "index", gin.H{
"title": "Main Page",
"user": loginUser(c),
"msg": "Hello, World!",
})
}

Expand Down Expand Up @@ -150,6 +152,11 @@ func PostUpload(c *gin.Context) {
errorPage(c, 500)
}
videoName := c.PostForm("filename")
isPrivateStr := c.PostForm("is_private")
isPrivate := false
if isPrivateStr == "1" {
isPrivate = true
}
file, header, err := c.Request.FormFile("file")
if header == nil || err != nil {
errorPage(c, 400)
Expand All @@ -167,10 +174,11 @@ func PostUpload(c *gin.Context) {
defer db.Close()
currentUser := loginUser(c)
video := Video{
Uid: uid.String(),
Name: videoName,
UserId: currentUser.Id,
IsEncode: false,
Uid: uid.String(),
Name: videoName,
UserId: currentUser.Id,
IsPrivate: isPrivate,
IsEncode: false,
}
if err := video.Validate(); err != nil {
errorPage(c, 400)
Expand All @@ -196,7 +204,10 @@ func GetList(c *gin.Context) {
db := SqlConnect()
defer db.Close()
var videos []Video
db.Where(&Video{IsEncode: true}).Find(&videos)
if isAuthenticated(c) {
currentUser := loginUser(c)
db.Where(&Video{IsEncode: true, UserId: currentUser.Uid}).Find(&videos)
}
c.HTML(http.StatusOK, "videoList", gin.H{
"title": "Video List",
"user": loginUser(c),
Expand Down
1 change: 1 addition & 0 deletions app/src/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Video struct {
Id int `gorm:"type:int AUTO_INCREMENT"`
Uid string `gorm:"type:varchar(36);not null;unique"`
Name string `gorm:"type:varchar(500);not null;default:'Untitled'"`
IsPrivate bool `gorm:"type:bool;not null;default:true"`
IsEncode bool `gorm:"type:bool;not null;default:false"`
UpdatedAt time.Time `gorm:"not null"`
CreatedAt time.Time `gorm:"not null"`
Expand Down
1 change: 1 addition & 0 deletions app/templates/upload.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{define "body"}}
<form method="post" enctype="multipart/form-data">
<input type="text" name="filename">
<input type="checkbox" name="is_private" value="1">
<input type="file" name="file">
<input type="submit" value="Submit">
</form>
Expand Down

0 comments on commit 0738ae8

Please sign in to comment.