Templates + build
This commit is contained in:
parent
67e2e4d306
commit
7e821296a6
13 changed files with 202 additions and 15 deletions
|
|
@ -3,16 +3,25 @@ package routes
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.readonly.ch/bouzoure/gpx-downloader/helpers"
|
||||
"git.readonly.ch/bouzoure/gpx-downloader/providers"
|
||||
"git.readonly.ch/bouzoure/gpx-downloader/templates"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/tkrajina/gpxgo/gpx"
|
||||
)
|
||||
|
||||
func Fetch(c *fiber.Ctx) error {
|
||||
// In case of error
|
||||
baseParams := templates.BaseTemplateParams{
|
||||
Title: "Error - GPX downloader",
|
||||
}
|
||||
var indexParams templates.IndexParams
|
||||
|
||||
sourceUrl := c.FormValue("url")
|
||||
if len(sourceUrl) <= 0 {
|
||||
c.SendStatus(422)
|
||||
return c.SendString("Error: URL is empty")
|
||||
indexParams.Error = "Error: URL is empty"
|
||||
return helpers.TemplRender(c, templates.Index(baseParams, indexParams))
|
||||
}
|
||||
|
||||
var gpxFile gpx.GPX
|
||||
|
|
@ -29,18 +38,22 @@ func Fetch(c *fiber.Ctx) error {
|
|||
|
||||
gpxFile, err = providers.SuisseMobileFetch(suisseMobileId)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Error(err)
|
||||
indexParams.Error = "An error occured"
|
||||
return helpers.TemplRender(c, templates.Index(baseParams, indexParams))
|
||||
}
|
||||
}
|
||||
|
||||
if len(filename) <= 0 {
|
||||
c.SendStatus(422)
|
||||
return c.SendString("Error: URL is not supported")
|
||||
indexParams.Error = "Error: URL is not supported"
|
||||
return helpers.TemplRender(c, templates.Index(baseParams, indexParams))
|
||||
}
|
||||
|
||||
xml, err := gpxFile.ToXml(gpx.ToXmlParams{})
|
||||
if err != nil {
|
||||
return err
|
||||
log.Error(err)
|
||||
indexParams.Error = "An error occured"
|
||||
return helpers.TemplRender(c, templates.Index(baseParams, indexParams))
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "octet-stream")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue