Able to list destinations

This commit is contained in:
LittleSheep 2024-12-28 22:27:39 +08:00
parent ebc3a6f09c
commit 8888f7661a
4 changed files with 24 additions and 21 deletions

View File

@ -7,6 +7,8 @@ const (
type BaseDestination struct {
Type string `json:"type"`
Label string `json:"label"`
LabelRegion string `json:"label_region"`
}
type LocalDestination struct {

View File

@ -0,0 +1,19 @@
package api
import (
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
"github.com/gofiber/fiber/v2"
jsoniter "github.com/json-iterator/go"
"github.com/spf13/viper"
)
func listDestination(c *fiber.Ctx) error {
var destinations []models.LocalDestination
for _, value := range viper.GetStringSlice("destinations") {
var parsed models.LocalDestination
raw, _ := jsoniter.Marshal(value)
_ = jsoniter.Unmarshal(raw, &parsed)
destinations = append(destinations, parsed)
}
return c.JSON(destinations)
}

View File

@ -6,10 +6,10 @@ import (
)
func MapAPIs(app *fiber.App, baseURL string) {
app.Get("/.well-known/destinations", getDestinations)
api := app.Group(baseURL).Name("API")
{
api.Get("/destinations", listDestination)
boost := api.Group("/boosts").Name("Boosts API")
{
boost.Get("/", listBoostByUser)

View File

@ -1,18 +0,0 @@
package api
import (
"github.com/gofiber/fiber/v2"
"github.com/spf13/viper"
)
func getDestinations(c *fiber.Ctx) error {
var data []string
for key := range viper.GetStringMap("destinations") {
data = append(data, key)
}
return c.JSON(fiber.Map{
"data": data,
"preferred": viper.GetString("preferred_destination"),
})
}