Update dependencies and add unique UUID route
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
environment: development
|
environment: development
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 3000
|
port: 3000
|
||||||
|
auth_key: ""
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -5,7 +5,7 @@ go 1.18
|
|||||||
require (
|
require (
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/gofiber/fiber/v2 v2.44.0
|
github.com/gofiber/fiber/v2 v2.44.0
|
||||||
github.com/mineatar-io/skin-render v1.0.6
|
github.com/mineatar-io/skin-render v1.0.8
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -30,6 +30,10 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV
|
|||||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mineatar-io/skin-render v1.0.6 h1:tvuS/L1w4Awx4qxZDbrnvmHG8C4UGUFPaw9IDD/r1jg=
|
github.com/mineatar-io/skin-render v1.0.6 h1:tvuS/L1w4Awx4qxZDbrnvmHG8C4UGUFPaw9IDD/r1jg=
|
||||||
github.com/mineatar-io/skin-render v1.0.6/go.mod h1:KkgHwrhTIqD73dkmeQwh5k2aHuWS8cDahVmd64gM128=
|
github.com/mineatar-io/skin-render v1.0.6/go.mod h1:KkgHwrhTIqD73dkmeQwh5k2aHuWS8cDahVmd64gM128=
|
||||||
|
github.com/mineatar-io/skin-render v1.0.7 h1:mJ7KIcekZFFKFffjF6swYTchTl2tjD86/4OJdprdTso=
|
||||||
|
github.com/mineatar-io/skin-render v1.0.7/go.mod h1:KkgHwrhTIqD73dkmeQwh5k2aHuWS8cDahVmd64gM128=
|
||||||
|
github.com/mineatar-io/skin-render v1.0.8 h1:5HJGqYJ2t2UxQtfN00v1+VWelG32d0TQZip7Htz4cR4=
|
||||||
|
github.com/mineatar-io/skin-render v1.0.8/go.mod h1:KkgHwrhTIqD73dkmeQwh5k2aHuWS8cDahVmd64gM128=
|
||||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ var (
|
|||||||
Environment: "development",
|
Environment: "development",
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: 3001,
|
Port: 3001,
|
||||||
|
AuthKey: "",
|
||||||
Redis: RedisConfig{
|
Redis: RedisConfig{
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: 6379,
|
Port: 6379,
|
||||||
@@ -95,6 +96,7 @@ type Config struct {
|
|||||||
Environment string `yaml:"environment"`
|
Environment string `yaml:"environment"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port uint16 `yaml:"port"`
|
Port uint16 `yaml:"port"`
|
||||||
|
AuthKey string `yaml:"auth_key"`
|
||||||
Redis RedisConfig `yaml:"redis"`
|
Redis RedisConfig `yaml:"redis"`
|
||||||
Routes RoutesConfig `yaml:"routes"`
|
Routes RoutesConfig `yaml:"routes"`
|
||||||
Cache CacheConfig `yaml:"cache"`
|
Cache CacheConfig `yaml:"cache"`
|
||||||
|
|||||||
17
src/redis.go
17
src/redis.go
@@ -34,6 +34,23 @@ func (r *Redis) Connect(conf RedisConfig) error {
|
|||||||
return c.Ping(ctx).Err()
|
return c.Ping(ctx).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan returns all keys by the pattern in the Redis database.
|
||||||
|
func (r *Redis) Scan(cursor uint64, pattern string) ([]string, uint64, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
res := r.conn.Scan(ctx, cursor, pattern, 25)
|
||||||
|
|
||||||
|
if err := res.Err(); err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
keys, newCursor := res.Val()
|
||||||
|
|
||||||
|
return keys, newCursor, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetString gets the value from Redis by the key and returns the value as a string.
|
// GetString gets the value from Redis by the key and returns the value as a string.
|
||||||
func (r *Redis) GetString(key string) (string, bool, error) {
|
func (r *Redis) GetString(key string) (string, bool, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/mineatar-io/skin-render"
|
"github.com/mineatar-io/skin-render"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app.Get("/ping", PingHandler)
|
app.Get("/ping", PingHandler)
|
||||||
|
app.Get("/list", ListHandler)
|
||||||
app.Get("/skin/:uuid", SkinHandler)
|
app.Get("/skin/:uuid", SkinHandler)
|
||||||
app.Get("/face/:uuid", FaceHandler)
|
app.Get("/face/:uuid", FaceHandler)
|
||||||
app.Get("/head/:uuid", HeadHandler)
|
app.Get("/head/:uuid", HeadHandler)
|
||||||
@@ -27,6 +29,39 @@ func PingHandler(ctx *fiber.Ctx) error {
|
|||||||
return ctx.SendStatus(http.StatusOK)
|
return ctx.SendStatus(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListHandler is the API handler used for the `/list` route.
|
||||||
|
func ListHandler(ctx *fiber.Ctx) error {
|
||||||
|
authKey := ctx.Get("Authorization")
|
||||||
|
|
||||||
|
if len(authKey) < 1 {
|
||||||
|
return ctx.SendStatus(http.StatusUnauthorized)
|
||||||
|
}
|
||||||
|
|
||||||
|
if authKey != conf.AuthKey {
|
||||||
|
return ctx.SendStatus(http.StatusForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0)
|
||||||
|
|
||||||
|
for {
|
||||||
|
keys, cursor, err := r.Scan(0, "unique:*")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, uuid := range keys {
|
||||||
|
result = append(result, strings.TrimPrefix(uuid, "unique:"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cursor == 0 || len(keys) < 1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.JSON(result)
|
||||||
|
}
|
||||||
|
|
||||||
// FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
|
// FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
|
||||||
func FullBodyHandler(ctx *fiber.Ctx) error {
|
func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
|||||||
return skin.GetDefaultSkin(slim), slim, nil
|
return skin.GetDefaultSkin(slim), slim, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = r.Set(fmt.Sprintf("unique:%s", textures.UUID), "0", 0); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
value := ""
|
value := ""
|
||||||
|
|
||||||
for _, property := range textures.Properties {
|
for _, property := range textures.Properties {
|
||||||
|
|||||||
Reference in New Issue
Block a user