-
Notifications
You must be signed in to change notification settings - Fork 44
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 4 commits
878b1e7
45ac77d
3e6b50c
0bcc352
771ba03
59ca191
b31ac9c
1229fa4
bf44518
b98d972
5da618d
cfe00e2
977c613
00a4de9
d09c617
289b202
2f8294a
f9f65a6
0657fc5
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) | ||
feriel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 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. filename is needed to create an object of type File as it has the element Filename as part of it. |
||
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)) | ||
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 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. I will change the type now temporarily but the idea is as you suggested to have a new type for custom thumbnail |
||
} | ||
|
||
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
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.
yes the two routes were originally there in case a distinction was necessary but now of course one route is enough.