Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Custom Thumbnail for a Lecture #1479

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft

Conversation

feriel97
Copy link

@feriel97 feriel97 commented Jan 15, 2025

Motivation and Context

resolves #1155

Description

Currently the thumbnail for the videos is generated automatically. The new Upload Custom Thumbnail button allows the admin users to be able to drag and drop an image file as a custom thumbnail for a lecture. The UI is still a work in progress and the file upload without drag and drop will be supported for better support on other devices such as mobiles.

The current to-dos:

  • Visual Feedback for the upload to the user
  • Preview the thumbnail
  • Option to go back to the automatically generated thumbnail

Steps for Testing

Prerequisites:

  • 1 Lecturer
  • 1 Lecture
  • 1 Picture
  1. Log in
  2. Navigate to the Admin Panel
  3. Select a Course
  4. Select a Lecture
  5. Edit Lecture
  6. Toggle the button
  7. Drag and drop the file
  8. Select Save Lecture

Screenshots

UploadCustomThumbnailButton

Copy link
Member

@joschahenningsen joschahenningsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start! This is only a draft but I thought I could leave some input already.
In addition to my thoughts, we need a way during livestreams, to prevent the thumbnail from being overwritten by the automatomatically generated one. My suggestion is, creating a new FileType for costum thumbnails, which is preferred over automatically generated ones.

@@ -50,6 +50,8 @@ func configGinStreamRestRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) {
thumbs.GET(":fid", routes.getThumbs)
thumbs.GET("/live", routes.getLiveThumbs)
thumbs.GET("/vod", routes.getVODThumbs)
thumbs.POST("/customlive", routes.putCustomLiveThumbnail)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need two routes to do the same thing? I'd argue there's no need to distinguish livestreams from vods when uploading thumbnails

@@ -50,6 +50,8 @@ func configGinStreamRestRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) {
thumbs.GET(":fid", routes.getThumbs)
thumbs.GET("/live", routes.getLiveThumbs)
thumbs.GET("/vod", routes.getVODThumbs)
thumbs.POST("/customlive", routes.putCustomLiveThumbnail)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo the logical method and path would be something like POST /api/stream/:streamID/thumbnails

Suggested change
thumbs.POST("/customlive", routes.putCustomLiveThumbnail)
thumbs.POST("/", routes.putCustomLiveThumbnail)

return
}

filename := file.Filename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the filename if it's unused

course := tumLiveContext.Course
file, err := c.FormFile("file")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid file"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use our RequestError to abort:

_ = c.AbortWithError(http.StatusForbidden, tools.RequestError{
	Status:        http.StatudBadRequest,
	CustomMessage: "Couldn't read file",
	Err:           err,
})

Comment on lines +913 to +918
filesFolder := fmt.Sprintf("%s/%s.%d/%s.%s/files",
tools.Cfg.Paths.Mass,
course.Name, course.Year,
course.Name, course.TeachingTerm)

path := fmt.Sprintf("%s/%s%s", filesFolder, fileUuid, filepath.Ext(filename))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use path.Join from the standard library to construct this filepath:
https://pkg.go.dev/path#example-Join


//tempFilePath := pathprovider.LiveThumbnail(strconv.Itoa(int(streamID)))
if err := c.SaveUploadedFile(file, path); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save file"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use RequestError here too

StreamID: streamID,
Path: path,
Filename: file.Filename,
Type: model.FILETYPE_THUMB_CAM,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc this filetype is for the scrubbar, not the preview. To be sure, use FILETYPE_THUMB_LG_CAM_PRES, which is always elected default

Type: model.FILETYPE_THUMB_CAM,
}

fileDao := dao.NewFileDao()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to create a new DAO, just use r.DaoWrapper.FileDao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Thumbnail Upload
2 participants