From 2a36bcddf348479adeaebed1ebc6ecd5314b5878 Mon Sep 17 00:00:00 2001 From: Danny August Ramaputra Date: Sat, 6 Feb 2021 19:34:43 +1000 Subject: [PATCH 1/6] refactor: author cast list hides unlisted --- cast-be/controller/v1/video.go | 2 +- cast-be/handlers/init.go | 2 +- cast-be/handlers/user.go | 2 +- cast-be/handlers/video.go | 4 ++-- cast-be/models/video.go | 16 ++++++++++------ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cast-be/controller/v1/video.go b/cast-be/controller/v1/video.go index b5d20c1..89b8d5a 100644 --- a/cast-be/controller/v1/video.go +++ b/cast-be/controller/v1/video.go @@ -33,7 +33,7 @@ func (c *VideoController) GetList(variant, author string, count, offset int) dat if author == "" { videos, err = c.Handler.CastList(variant, count, offset) } else { - videos, err = c.Handler.AuthorList(author, count, offset) + videos, err = c.Handler.AuthorList(author, false, count, offset) } if err != nil { fmt.Printf("[VideoController::GetList] failed retrieving video list. %+v\n", err) diff --git a/cast-be/handlers/init.go b/cast-be/handlers/init.go index 0f3f29e..6eaca93 100644 --- a/cast-be/handlers/init.go +++ b/cast-be/handlers/init.go @@ -71,7 +71,7 @@ type Handler interface { UserDetails(userID string) (detail data.UserDetail, err error) CastList(variant string, count, offset int, userID ...string) (videos []data.Video, err error) - AuthorList(author string, count, offset int) (videos []data.Video, err error) + AuthorList(author string, withUnlisted bool, count, offset int) (videos []data.Video, err error) SearchVideo(query string, tags []string, count, offset int) (videos []data.Video, err error) VideoDetails(hash string) (video data.Video, err error) CreateVOD(upload data.VideoUpload, controller beego.Controller, userID string) (ID primitive.ObjectID, err error) diff --git a/cast-be/handlers/user.go b/cast-be/handlers/user.go index c8ebae5..75b8730 100644 --- a/cast-be/handlers/user.go +++ b/cast-be/handlers/user.go @@ -15,7 +15,7 @@ func (m *module) UserDetails(userID string) (detail data.UserDetail, err error) if user, err = m.db.userOrm.GetOneByID(userID); err != nil { return data.UserDetail{}, errors.New(fmt.Sprintf("[UserDetails] user not found. %+v\n", err)) } - if videos, err = m.db.videoOrm.GetAllVODByAuthor(userID); err != nil { + if videos, err = m.db.videoOrm.GetAllVODByAuthor(userID, true); err != nil { return data.UserDetail{}, errors.New(fmt.Sprintf("[UserDetails] cannot retrieve all user videos. %+v\n", err)) } if subscriberCount, err = m.db.subscriptionOrm.GetCountByAuthorID(user.ID); err != nil { diff --git a/cast-be/handlers/video.go b/cast-be/handlers/video.go index d1f28bb..9970cfa 100644 --- a/cast-be/handlers/video.go +++ b/cast-be/handlers/video.go @@ -49,12 +49,12 @@ func (m *module) CastList(variant string, count int, offset int, userID ...strin } return } -func (m *module) AuthorList(username string, count, offset int) (videos []data.Video, err error) { +func (m *module) AuthorList(username string, withUnlisted bool, count, offset int) (videos []data.Video, err error) { var author data.User if author, err = m.db.userOrm.GetOneByUsername(username); err != nil { return nil, errors.New(fmt.Sprintf("[AuthorList] author not found. %+v", err)) } - if videos, err = m.db.videoOrm.GetAllVODByAuthorPaginated(author.ID, count, offset); err != nil { + if videos, err = m.db.videoOrm.GetAllVODByAuthorPaginated(author.ID, withUnlisted, count, offset); err != nil { return nil, errors.New(fmt.Sprintf("[AuthorList] error retrieving VODs. %+v", err)) } return diff --git a/cast-be/models/video.go b/cast-be/models/video.go index c9df857..9443e37 100644 --- a/cast-be/models/video.go +++ b/cast-be/models/video.go @@ -20,8 +20,8 @@ type VideoOrmer interface { GetTrending(count int, offset int) (videos []datatransfers.Video, err error) GetLiked(userID string, count int, offset int) (videos []datatransfers.Video, err error) GetSubscribed(userID string, count int, offset int) (videos []datatransfers.Video, err error) - GetAllVODByAuthor(author string) (videos []datatransfers.Video, err error) - GetAllVODByAuthorPaginated(author string, count int, offset int) (videos []datatransfers.Video, err error) + GetAllVODByAuthor(author string, withUnlisted bool) (videos []datatransfers.Video, err error) + GetAllVODByAuthorPaginated(author string, withUnlisted bool, count int, offset int) (videos []datatransfers.Video, err error) Search(query string, count, offset int) (videos []datatransfers.Video, err error) GetLiveByAuthor(userID string) (datatransfers.Video, error) GetOneByHash(hash string) (datatransfers.Video, error) @@ -187,7 +187,7 @@ func (o *videoOrm) GetTrending(count int, offset int) (result []datatransfers.Vi return } -func (o *videoOrm) GetAllVODByAuthor(author string) (videos []datatransfers.Video, err error) { +func (o *videoOrm) GetAllVODByAuthor(author string, withUnlisted bool) (videos []datatransfers.Video, err error) { query := &mongo.Cursor{} if query, err = o.collection.Aggregate(context.Background(), mongo.Pipeline{ // unlisted VODs included {{"$match", bson.D{{"author", author}}}}, @@ -207,12 +207,14 @@ func (o *videoOrm) GetAllVODByAuthor(author string) (videos []datatransfers.Vide if err = query.Decode(&video); err != nil { return } - videos = append(videos, video) + if withUnlisted || !video.Unlisted { + videos = append(videos, video) + } } return } -func (o *videoOrm) GetAllVODByAuthorPaginated(author string, count int, offset int) (videos []datatransfers.Video, err error) { +func (o *videoOrm) GetAllVODByAuthorPaginated(author string, withUnlisted bool, count int, offset int) (videos []datatransfers.Video, err error) { query := &mongo.Cursor{} if query, err = o.collection.Aggregate(context.Background(), mongo.Pipeline{ // unlisted VODs included {{"$match", bson.D{{"author", author}}}}, @@ -244,7 +246,9 @@ func (o *videoOrm) GetAllVODByAuthorPaginated(author string, count int, offset i if err = query.Decode(&video); err != nil { return } - videos = append(videos, video) + if withUnlisted || !video.Unlisted { + videos = append(videos, video) + } } return } From 77d7a76a687eaf05b1d76e09f272002b6dbfd403 Mon Sep 17 00:00:00 2001 From: Danny August Ramaputra Date: Sat, 6 Feb 2021 19:48:49 +1000 Subject: [PATCH 2/6] feat: added protected endpoint for owned cast list --- cast-be/controller/v1/video.go | 12 +++++++++++- cast-be/handlers/init.go | 1 + cast-be/handlers/user.go | 7 +++++++ cast-be/routers/commentsRouter_controller_v1.go | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cast-be/controller/v1/video.go b/cast-be/controller/v1/video.go index 89b8d5a..0ab6cb3 100644 --- a/cast-be/controller/v1/video.go +++ b/cast-be/controller/v1/video.go @@ -91,13 +91,23 @@ func (c *VideoControllerAuth) Prepare() { // @Title Get List // @Success 200 {object} models.Object // @Param variant query string false "variant" +// @Param author query string false "author" // @Param count query int false 8 "count" // @Param offset query int false 0 "offset" // @router /list [get] -func (c *VideoControllerAuth) GetList(variant string, count, offset int) datatransfers.Response { +func (c *VideoControllerAuth) GetList(variant, author string, count, offset int) datatransfers.Response { var videos []datatransfers.Video var err error videos, err = c.Handler.CastList(variant, count, offset, c.userID) + if author == "" { + videos, err = c.Handler.CastList(variant, count, offset) + } else { + // var user datatransfers.User + if _, err = c.Handler.UserGetOneByID(c.userID); err != nil { + return datatransfers.Response{Error: "Failed retrieving user info", Code: http.StatusInternalServerError} + } + // videos, err = c.Handler.AuthorList(author, author == user.Username, count, offset) + } if err != nil { fmt.Printf("[VideoControllerAuth::GetList] failed retrieving video list. %+v\n", err) return datatransfers.Response{Error: "Failed retrieving video list", Code: http.StatusInternalServerError} diff --git a/cast-be/handlers/init.go b/cast-be/handlers/init.go index 6eaca93..2bce829 100644 --- a/cast-be/handlers/init.go +++ b/cast-be/handlers/init.go @@ -69,6 +69,7 @@ type Handler interface { Register(idToken data.UserRegister) (err error) UserDetails(userID string) (detail data.UserDetail, err error) + UserGetOneByID(userID string) (user data.User, err error) CastList(variant string, count, offset int, userID ...string) (videos []data.Video, err error) AuthorList(author string, withUnlisted bool, count, offset int) (videos []data.Video, err error) diff --git a/cast-be/handlers/user.go b/cast-be/handlers/user.go index 75b8730..b4905c3 100644 --- a/cast-be/handlers/user.go +++ b/cast-be/handlers/user.go @@ -34,3 +34,10 @@ func (m *module) UserDetails(userID string) (detail data.UserDetail, err error) } return } + +func (m *module) UserGetOneByID(userID string) (user data.User, err error) { + if user, err = m.db.userOrm.GetOneByID(userID); err != nil { + return data.User{}, fmt.Errorf("[UserGetOneByID] user not found. %+v\n", err) + } + return +} diff --git a/cast-be/routers/commentsRouter_controller_v1.go b/cast-be/routers/commentsRouter_controller_v1.go index d344f80..41c6ca6 100644 --- a/cast-be/routers/commentsRouter_controller_v1.go +++ b/cast-be/routers/commentsRouter_controller_v1.go @@ -172,6 +172,7 @@ func init() { AllowHTTPMethods: []string{"get"}, MethodParams: param.Make( param.New("variant"), + param.New("author"), param.New("count", param.Default("false")), param.New("offset", param.Default("false")), ), From f19c8e3e8c8813cf53703c78704e6bbe4416ed02 Mon Sep 17 00:00:00 2001 From: Danny August Ramaputra Date: Sat, 6 Feb 2021 19:49:27 +1000 Subject: [PATCH 3/6] chore: improved styling --- cast-fe/src/views/Scene.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cast-fe/src/views/Scene.jsx b/cast-fe/src/views/Scene.jsx index e3bbf3c..c1f1776 100644 --- a/cast-fe/src/views/Scene.jsx +++ b/cast-fe/src/views/Scene.jsx @@ -448,7 +448,7 @@ class Scene extends Component {
-

Comments

+

Comments

Date: Sat, 6 Feb 2021 19:49:45 +1000 Subject: [PATCH 4/6] feat: used protected endpoint for owned cast list --- cast-fe/src/views/Manage.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cast-fe/src/views/Manage.jsx b/cast-fe/src/views/Manage.jsx index 8c0dceb..523b984 100644 --- a/cast-fe/src/views/Manage.jsx +++ b/cast-fe/src/views/Manage.jsx @@ -68,9 +68,9 @@ class Manage extends Component { fetchVideos() { api.cast - .list({ + .listCurated({ author: authManager.getUser().preferred_username, - count: 8, + count: 512, offset: 0, }) .then((response) => { @@ -482,7 +482,7 @@ class Manage extends Component { )) ) : ( -
No videos uploaded yet!
+
No casts uploaded yet!
))} {this.state.loading && ( Date: Sat, 6 Feb 2021 19:59:54 +1000 Subject: [PATCH 5/6] feat: added unlisted tag --- cast-fe/src/components/Cast.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cast-fe/src/components/Cast.jsx b/cast-fe/src/components/Cast.jsx index 78934e0..7e61e2d 100644 --- a/cast-fe/src/components/Cast.jsx +++ b/cast-fe/src/components/Cast.jsx @@ -33,7 +33,12 @@ function Cast(props) { LIVE )} - + {props.video.unlisted && ( + + Unlisted + + )} + {abbreviate().number(props.video.views)}{" "} {props.video.type === "live" ? "viewers" : "views"} @@ -94,7 +99,7 @@ let style = { fontSize: 16, fontWeight: 400, }, - cast_viewer_tag: { + cast_tag: { background: "#8B2803AA", color: "#DDD", borderRadius: 8, @@ -106,6 +111,9 @@ let style = { marginRight: 8, marginBottom: 8, }, + cast_tag_unlisted: { + background: "rgb(3,69,139)", + }, cast_detail: { display: "flex", }, From 27ccbb6eef611ded4c8dd6ae161345b42f9e0343 Mon Sep 17 00:00:00 2001 From: Danny August Ramaputra Date: Sat, 6 Feb 2021 20:00:29 +1000 Subject: [PATCH 6/6] refactor: improved unavailable cast error response --- cast-fe/src/views/Scene.jsx | 575 +++++++++++++++++++----------------- 1 file changed, 303 insertions(+), 272 deletions(-) diff --git a/cast-fe/src/views/Scene.jsx b/cast-fe/src/views/Scene.jsx index c1f1776..5988a21 100644 --- a/cast-fe/src/views/Scene.jsx +++ b/cast-fe/src/views/Scene.jsx @@ -52,6 +52,7 @@ class Scene extends Component { comments: [], error_comment: "", not_found: false, + not_loadable: false, }; this.handleDownload = this.handleDownload.bind(this); this.handleShare = this.handleShare.bind(this); @@ -160,7 +161,10 @@ class Scene extends Component { }) .catch((error) => { console.log(error); - this.setState({ loading: { ...this.state.loading, current: false } }); + this.setState({ + not_loadable: true, + loading: { ...this.state.loading, current: false }, + }); }); } @@ -289,298 +293,325 @@ class Scene extends Component { if (this.state.loading.live) return <>; return ( <> - {!this.state.not_found && !this.state.offline && ( - - - - - - - - -
- {this.state.live && - Object.values(this.state.live).map((video) => ( - - this.incrementView(a, b)} - /> - - ))} - {this.state.loading.live && ( - - )} -
- - - - - - {this.state.video?.unlisted && ( - - Unlisted - + {!this.state.not_found && + !this.state.not_loadable && + !this.state.offline && ( + + + + + + + + +
+ {this.state.live && + Object.values(this.state.live).map((video) => ( + + this.incrementView(a, b)} + /> + + ))} + {this.state.loading.live && ( + )} - {this.state.video?.tags && - Object.values(this.state.video?.tags).map((tag) => ( - - {tag} +
+ + + + + + {this.state.video?.unlisted && ( + + Unlisted - ))} - - - {this.state.video?.type === VIDEO_TYPE_VOD && ( + )} + {this.state.video?.tags && + Object.values(this.state.video?.tags).map((tag) => ( + + {tag} + + ))} + + + {this.state.video?.type === VIDEO_TYPE_VOD && ( + + get_app download + + )} - get_app download + share share - )} - - share share - - - - thumb_up - {" "} - {`${abbreviate().number(this.state.likes) || 0} like${ - this.state.likes === 1 ? "" : "s" - }`} - - - remove_red_eye{" "} - {abbreviate().number(this.state.video?.views) || 0}{" "} - {this.state.video?.type === VIDEO_TYPE_LIVE - ? "viewers" - : "views"} - - - -

{this.state.video?.title}

-

- {format().date(this.state.video?.created_at)} -

-
-
- -
-

- {this.state.video?.author.name} -

-

- {abbreviate().number( - this.state.video?.author.subscribers - ) || 0}{" "} - subscriber - {this.state.video?.author.subscribers !== 1 && "s"} -

+ + thumb_up + {" "} + {`${abbreviate().number(this.state.likes) || 0} like${ + this.state.likes === 1 ? "" : "s" + }`} + + + remove_red_eye{" "} + {abbreviate().number(this.state.video?.views) || 0}{" "} + {this.state.video?.type === VIDEO_TYPE_LIVE + ? "viewers" + : "views"} + + + +

{this.state.video?.title}

+

+ {format().date(this.state.video?.created_at)} +

+
+
+ +
+

+ {this.state.video?.author.name} +

+

+ {abbreviate().number( + this.state.video?.author.subscribers + ) || 0}{" "} + subscriber + {this.state.video?.author.subscribers !== 1 && "s"} +

+
-
-
- -
-
- - -
- {this.state.video?.description} +
+
- - -
-

Comments

- - -
- {this.state.error_submit && ( - - {this.state.error_submit} - - )} - - - - - - - - {this.state.error_comment} - - - -
-
- {this.state.comments ? ( - Object.values(this.state.comments).map((comment) => { - return ( -
- +
+ + +
+ {this.state.video?.description} +
+ +
+
+

Comments

+ + +
+ {this.state.error_submit && ( + + {this.state.error_submit} + + )} + + + + + + + + {this.state.error_comment} + + + +
+
+ {this.state.comments ? ( + Object.values(this.state.comments).map((comment) => { + return (
-

- {comment.author.name} -

-

- -

-

+

- {comment.content} -

+

+ {comment.author.name} +

+

+ +

+

+ {comment.content} +

+
-
- ); - }) - ) : ( -
Post the first comment!
- )} -
- -
- -
-
- - - -
- {this.state.vod && - Object.values(this.state.vod).map((video) => ( - - this.incrementView(a, b)} - /> - - ))} - {this.state.loading.vod && ( - - )} -
- - - - )} + ); + }) + ) : ( +
Post the first comment!
+ )} +
+ +
+ +
+
+ + + +
+ {this.state.vod && + Object.values(this.state.vod).map((video) => ( + + this.incrementView(a, b)} + /> + + ))} + {this.state.loading.vod && ( + + )} +
+ + + + )} {this.state.not_found && ( <> {"Video +

+ Cast Not Found +

+ + )} + {this.state.not_loadable && ( + <> + {"Currently - Video Unavailable + Currently Unavailable )}