mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Simplify routes, handle error route
Former-commit-id: a2be41df36132865f1f5ddee954a2c36cd15946a [formerly 952889d5fec4f3207cfd3a071bcf7278afeb09a8] [formerly 21c56db9a4a329ff6e70573734bbe7a33ee8b0a0 [formerly 8f4f07ce580467b241015b8b6291d7bce91bf66e [formerly9becf07745
]]] Former-commit-id: 1ad7a875ff4738230e09a4d46bf58c7d03c43a90 [formerly 5263a10dd6b8057bcfa7ac65509c7a87d5889175] Former-commit-id: 57c32446567ef6b8d219893ed93c6499cf0b0da8 Former-commit-id:95afa389bc
This commit is contained in:
parent
3a265a0979
commit
62c9e6ee1b
23
handlers.go
23
handlers.go
@ -57,7 +57,9 @@ func loadTemplates(list ...string) multitemplate.Render {
|
||||
func handlePageRequest(c *gin.Context) {
|
||||
page := c.Param("page")
|
||||
command := c.Param("command")
|
||||
|
||||
if len(command) < 2 {
|
||||
command = "/ "
|
||||
}
|
||||
// Serve static content from memory
|
||||
if page == "static" {
|
||||
filename := page + command
|
||||
@ -103,7 +105,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
versionsText[i] = time.Unix(v/1000000000, 0).String()
|
||||
}
|
||||
|
||||
if command == "/raw" {
|
||||
if command[0:2] == "/r" {
|
||||
c.Writer.Header().Set("Content-Type", contentType(p.Name))
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
||||
@ -114,11 +116,19 @@ func handlePageRequest(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
log.Debug(command)
|
||||
log.Debug("%v", command[0:2] != "/e" &&
|
||||
command[0:2] != "/v" &&
|
||||
command[0:2] != "/l" &&
|
||||
command[0:2] != "/h")
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
"EditPage": command == "/edit",
|
||||
"ViewPage": command == "/view",
|
||||
"ListPage": command == "/list",
|
||||
"HistoryPage": command == "/history",
|
||||
"EditPage": command[0:2] == "/e", // /edit
|
||||
"ViewPage": command[0:2] == "/v", // /view
|
||||
"ListPage": command[0:2] == "/l", // /list
|
||||
"HistoryPage": command[0:2] == "/h", // /history
|
||||
"DontKnowPage": command[0:2] != "/e" &&
|
||||
command[0:2] != "/v" &&
|
||||
command[0:2] != "/l" &&
|
||||
command[0:2] != "/h",
|
||||
"Page": p.Name,
|
||||
"RenderedPage": template.HTML([]byte(rawHTML)),
|
||||
"RawPage": rawText,
|
||||
@ -127,6 +137,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
"IsLocked": p.IsLocked,
|
||||
"IsEncrypted": p.IsEncrypted,
|
||||
"ListItems": renderList(rawText),
|
||||
"Route": "/" + page + command,
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user