Add links to the forge
This commit is contained in:
parent
562cd5b397
commit
6c471b5ec1
2 changed files with 21 additions and 1 deletions
20
works.go
20
works.go
|
|
@ -370,6 +370,26 @@ func declareAPIAuthWorksRoutes(router *gin.RouterGroup) {
|
|||
})
|
||||
|
||||
// Grades related to works
|
||||
worksRoutes.GET("/forge/*path", func(c *gin.Context) {
|
||||
w := c.MustGet("work").(*Work)
|
||||
|
||||
var u *User
|
||||
if user, ok := c.Get("user"); ok {
|
||||
u = user.(*User)
|
||||
} else {
|
||||
u = c.MustGet("LoggedUser").(*User)
|
||||
}
|
||||
|
||||
repo, err := u.getRepositoryByWork(w.Id)
|
||||
if err != nil {
|
||||
log.Printf("Unable to getRepositoryByWork(uid=%d, wid=%d): %s", u.Id, w.Id, err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to find a corresponding repository."})
|
||||
return
|
||||
}
|
||||
|
||||
c.Redirect(http.StatusFound, strings.TrimSuffix(strings.Replace(strings.Replace(repo.URI, ":", "/", 1), "git@", "https://", 1), ".git")+c.Param("path"))
|
||||
})
|
||||
|
||||
worksRoutes.GET("/score", func(c *gin.Context) {
|
||||
u := c.MustGet("LoggedUser").(*User)
|
||||
w := c.MustGet("work").(*Work)
|
||||
|
|
|
|||
Reference in a new issue