From 09e1f0e9aec4bdce275d20917800d2fc8b62c21a Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Tue, 16 Apr 2024 14:17:15 -0700 Subject: [PATCH] Add a handler for /download that directs you to the device-appropriate store --- bskyweb/cmd/bskyweb/server.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index 54a3925c..17d62101 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -170,6 +170,9 @@ func serve(cctx *cli.Context) error { // home e.GET("/", server.WebHome) + // download + e.GET("/download", server.Download) + // generic routes e.GET("/hashtag/:tag", server.WebGeneric) e.GET("/search", server.WebGeneric) @@ -271,6 +274,20 @@ func (srv *Server) errorHandler(err error, c echo.Context) { c.Render(code, "error.html", data) } +// Handler for redirecting to the download page. +func (srv *Server) Download(c echo.Context) error { + ua := c.Request().UserAgent() + if strings.Contains(ua, "Android") { + return c.Redirect(http.StatusFound, "https://play.google.com/store/apps/details?id=xyz.blueskyweb.app") + } + + if strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod") { + return c.Redirect(http.StatusFound, "https://apps.apple.com/tr/app/bluesky-social/id6444370199") + } + + return c.Redirect(http.StatusFound, "/") +} + // handler for endpoint that have no specific server-side handling func (srv *Server) WebGeneric(c echo.Context) error { data := pongo2.Context{}