-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo the logical method and path would be something like
Suggested change
|
||||||
thumbs.POST("/customvod", routes.putCustomLiveThumbnail) | ||||||
} | ||||||
} | ||||||
{ | ||||||
|
@@ -894,3 +896,45 @@ func (r streamRoutes) updateChatEnabled(c *gin.Context) { | |||||
return | ||||||
} | ||||||
} | ||||||
|
||||||
func (r streamRoutes) putCustomLiveThumbnail(c *gin.Context) { | ||||||
tumLiveContext := c.MustGet("TUMLiveContext").(tools.TUMLiveContext) | ||||||
streamID := tumLiveContext.Stream.ID | ||||||
course := tumLiveContext.Course | ||||||
file, err := c.FormFile("file") | ||||||
if err != nil { | ||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid file"}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,
}) |
||||||
return | ||||||
} | ||||||
|
||||||
filename := file.Filename | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the filename if it's unused |
||||||
fileUuid := uuid.NewV1() | ||||||
|
||||||
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)) | ||||||
Comment on lines
+913
to
+918
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use path.Join from the standard library to construct this filepath: |
||||||
|
||||||
//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"}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use RequestError here too |
||||||
return | ||||||
} | ||||||
|
||||||
thumb := model.File{ | ||||||
StreamID: streamID, | ||||||
Path: path, | ||||||
Filename: file.Filename, | ||||||
Type: model.FILETYPE_THUMB_CAM, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
} | ||||||
|
||||||
fileDao := dao.NewFileDao() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to create a new DAO, just use r.DaoWrapper.FileDao |
||||||
if err := fileDao.SetThumbnail(streamID, thumb); err != nil { | ||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to set thumbnail"}) | ||||||
return | ||||||
} | ||||||
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Thumbnail uploaded successfully"}) | ||||||
} |
There was a problem hiding this comment.
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