Skip to content

Commit

Permalink
chore: add pkg deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Apr 2, 2022
1 parent da9d811 commit 6cb49ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
FlareTemplates "github.com/soulteary/flare/pkg/templates"

FlareAppearance "github.com/soulteary/flare/pkg/appearance"
FlareDeprecated "github.com/soulteary/flare/pkg/deprecated"
)

func startDaemon(AppFlags *FlareModel.Flags) {
Expand Down Expand Up @@ -49,6 +50,7 @@ func startDaemon(AppFlags *FlareModel.Flags) {

FlareTemplates.RegisterRouting(router)
FlareAppearance.RegisterRouting(router)
FlareDeprecated.RegisterRouting(router)

if !AppFlags.DisableLoginMode {
FlareAuth.RequestHandle(router)
Expand Down
41 changes: 41 additions & 0 deletions pkg/deprecated/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package deprecated

import (
"net/http"

"github.com/gin-gonic/gin"

FlareState "github.com/soulteary/flare/state"
)

// TODO:样式优化
func makeLandingPage(originURL string, currentURL string, delay string) []byte {
tpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Refresh" content="` + delay + `; url='` + currentURL + `'" />
<title>URL Deprecated</title>
</head>
<body>
<p>由于程序升级,<a href="` + currentURL + `"><code>` + originURL + `</code></a>变更为<a href="` + currentURL + `"><code>` + currentURL + `</code></a>,页面将在` + delay + `秒后自动跳转。</p>
<p>你也可以直接点击<a href="` + currentURL + `"><code>这里</code></a>,前往新的页面</p>
</body>
</html>`
return []byte(tpl)
}

// 展示临时的落地页,在几个版本后,彻底取消路由
func RegisterRouting(router *gin.Engine) {
const urlMDI = "/resources/mdi-cheat-sheets/"
router.GET(urlMDI, func(c *gin.Context) {
if FlareState.AppFlags.EnableDeprecatedNotice {
c.Data(http.StatusOK, "text/html; charset=utf-8", makeLandingPage(urlMDI, FlareState.RegularPages.Icons.Path, "5"))
} else {
c.Redirect(http.StatusTemporaryRedirect, FlareState.RegularPages.Icons.Path)
}
c.Abort()
})
}

0 comments on commit 6cb49ac

Please sign in to comment.