mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-13 05:47:12 +02:00
Add clickable Markdown checkboxes (#182)
This commit is contained in:
@ -787,3 +787,39 @@ func forks(ctx echo.Context) error {
|
||||
setData(ctx, "revision", "HEAD")
|
||||
return html(ctx, "forks.html")
|
||||
}
|
||||
|
||||
func checkbox(ctx echo.Context) error {
|
||||
filename := ctx.FormValue("file")
|
||||
checkboxNb := ctx.FormValue("checkbox")
|
||||
|
||||
i, err := strconv.Atoi(checkboxNb)
|
||||
if err != nil {
|
||||
return errorRes(400, "Invalid number", nil)
|
||||
}
|
||||
|
||||
gist := getData(ctx, "gist").(*db.Gist)
|
||||
file, err := gist.File("HEAD", filename, false)
|
||||
if err != nil {
|
||||
return errorRes(500, "Error getting file content", err)
|
||||
} else if file == nil {
|
||||
return notFound("File not found")
|
||||
}
|
||||
|
||||
markdown, err := render.Checkbox(file.Content, i)
|
||||
if err != nil {
|
||||
return errorRes(500, "Error checking checkbox", err)
|
||||
}
|
||||
|
||||
if err = gist.AddAndCommitFile(&db.FileDTO{
|
||||
Filename: filename,
|
||||
Content: markdown,
|
||||
}); err != nil {
|
||||
return errorRes(500, "Error adding and committing files", err)
|
||||
}
|
||||
|
||||
if err = gist.UpdatePreviewAndCount(); err != nil {
|
||||
return errorRes(500, "Error updating the gist", err)
|
||||
}
|
||||
|
||||
return plainText(ctx, 200, "ok")
|
||||
}
|
||||
|
@ -265,6 +265,7 @@ func NewServer(isDev bool) *Server {
|
||||
g3.GET("/likes", likes)
|
||||
g3.POST("/fork", fork, logged)
|
||||
g3.GET("/forks", forks)
|
||||
g3.PUT("/checkbox", checkbox, logged, writePermission)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user