Major code cleanup
This commit is contained in:
@@ -11,56 +11,47 @@ routes:
|
|||||||
face:
|
face:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
head:
|
head:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
full_body:
|
full_body:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
front_body:
|
front_body:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
back_body:
|
back_body:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
left_body:
|
left_body:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
right_body:
|
right_body:
|
||||||
default_overlay: true
|
default_overlay: true
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
default_scale: 4
|
default_scale: 4
|
||||||
min_scale: 1
|
min_scale: 1
|
||||||
max_scale: 64
|
max_scale: 64
|
||||||
raw_skin:
|
raw_skin:
|
||||||
default_download: false
|
default_download: false
|
||||||
default_fallback: true
|
|
||||||
cache:
|
cache:
|
||||||
uuid_cache_duration: 168h # 1 week
|
|
||||||
skin_cache_duration: 12h # 12 hours
|
skin_cache_duration: 12h # 12 hours
|
||||||
render_cache_duration: 12h # 12 hours
|
render_cache_duration: 12h # 12 hours
|
||||||
6
go.mod
6
go.mod
@@ -4,7 +4,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.47.0
|
github.com/gofiber/fiber/v2 v2.48.0
|
||||||
github.com/mineatar-io/skin-render v1.0.9
|
github.com/mineatar-io/skin-render v1.0.9
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
@@ -19,11 +19,7 @@ require (
|
|||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
github.com/philhofer/fwd v1.1.2 // indirect
|
|
||||||
github.com/rivo/uniseg v0.4.4 // indirect
|
github.com/rivo/uniseg v0.4.4 // indirect
|
||||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
|
||||||
github.com/tinylib/msgp v1.1.8 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.48.0 // indirect
|
github.com/valyala/fasthttp v1.48.0 // indirect
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
|
|||||||
57
go.sum
57
go.sum
@@ -8,8 +8,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
|
|||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||||
github.com/gofiber/fiber/v2 v2.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs=
|
github.com/gofiber/fiber/v2 v2.48.0 h1:cRVMCb9aUJDsyHxGFLwz/sGzDggdailZZyptU9F9cU0=
|
||||||
github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU=
|
github.com/gofiber/fiber/v2 v2.48.0/go.mod h1:xqJgfqrc23FJuqGOW6DVgi3HyZEm2Mn9pRqUb2kHSX8=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||||
@@ -33,78 +33,25 @@ github.com/mineatar-io/skin-render v1.0.9/go.mod h1:KkgHwrhTIqD73dkmeQwh5k2aHuWS
|
|||||||
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=
|
||||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
|
||||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
|
||||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
|
|
||||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
|
|
||||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
|
||||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
|
||||||
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
|
||||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
|
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
|
||||||
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
|
||||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ var (
|
|||||||
Face: RouteConfig{
|
Face: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -32,7 +31,6 @@ var (
|
|||||||
Head: RouteConfig{
|
Head: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -40,7 +38,6 @@ var (
|
|||||||
FullBody: RouteConfig{
|
FullBody: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -48,7 +45,6 @@ var (
|
|||||||
FrontBody: RouteConfig{
|
FrontBody: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -56,7 +52,6 @@ var (
|
|||||||
BackBody: RouteConfig{
|
BackBody: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -64,7 +59,6 @@ var (
|
|||||||
LeftBody: RouteConfig{
|
LeftBody: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
@@ -72,20 +66,17 @@ var (
|
|||||||
RightBody: RouteConfig{
|
RightBody: RouteConfig{
|
||||||
DefaultOverlay: true,
|
DefaultOverlay: true,
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
DefaultScale: 4,
|
DefaultScale: 4,
|
||||||
MinScale: 1,
|
MinScale: 1,
|
||||||
MaxScale: 64,
|
MaxScale: 64,
|
||||||
},
|
},
|
||||||
RawSkin: RouteConfig{
|
RawSkin: RouteConfig{
|
||||||
DefaultDownload: false,
|
DefaultDownload: false,
|
||||||
DefaultFallback: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Cache: CacheConfig{
|
Cache: CacheConfig{
|
||||||
UUIDCacheDuration: time.Hour * 168,
|
SkinCacheDuration: PointerOf(time.Hour * 12),
|
||||||
SkinCacheDuration: time.Hour * 12,
|
RenderCacheDuration: PointerOf(time.Hour * 12),
|
||||||
RenderCacheDuration: time.Hour * 12,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -116,7 +107,6 @@ type RoutesConfig struct {
|
|||||||
type RouteConfig struct {
|
type RouteConfig struct {
|
||||||
DefaultScale int `yaml:"default_scale"`
|
DefaultScale int `yaml:"default_scale"`
|
||||||
DefaultOverlay bool `yaml:"default_overlay"`
|
DefaultOverlay bool `yaml:"default_overlay"`
|
||||||
DefaultFallback bool `yaml:"default_fallback"`
|
|
||||||
DefaultDownload bool `yaml:"default_download"`
|
DefaultDownload bool `yaml:"default_download"`
|
||||||
MinScale int `yaml:"min_scale"`
|
MinScale int `yaml:"min_scale"`
|
||||||
MaxScale int `yaml:"max_scale"`
|
MaxScale int `yaml:"max_scale"`
|
||||||
@@ -133,9 +123,8 @@ type RedisConfig struct {
|
|||||||
|
|
||||||
// CacheConfig is the configuration data used to set TTL values for Redis keys.
|
// CacheConfig is the configuration data used to set TTL values for Redis keys.
|
||||||
type CacheConfig struct {
|
type CacheConfig struct {
|
||||||
UUIDCacheDuration time.Duration `yaml:"uuid_cache_duration"`
|
SkinCacheDuration *time.Duration `yaml:"skin_cache_duration"`
|
||||||
SkinCacheDuration time.Duration `yaml:"skin_cache_duration"`
|
RenderCacheDuration *time.Duration `yaml:"render_cache_duration"`
|
||||||
RenderCacheDuration time.Duration `yaml:"render_cache_duration"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFile reads the configuration from the file and parses it as YAML.
|
// ReadFile reads the configuration from the file and parses it as YAML.
|
||||||
|
|||||||
26
src/main.go
26
src/main.go
@@ -1,11 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"strconv"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
@@ -61,13 +61,23 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if v := os.Getenv("PROFILE"); len(v) > 0 {
|
||||||
|
port, err := strconv.ParseUint(v, 10, 16)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go Profile(uint16(port))
|
||||||
|
|
||||||
|
log.Printf("Profiler is listening on :%d\n", port)
|
||||||
|
}
|
||||||
|
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
go ListenAndServe(conf.Host, conf.Port+instanceID)
|
log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID)
|
||||||
|
|
||||||
defer app.Shutdown()
|
if err := app.Listen(fmt.Sprintf("%s:%d", conf.Host, conf.Port+instanceID)); err != nil {
|
||||||
|
panic(err)
|
||||||
s := make(chan os.Signal, 1)
|
}
|
||||||
signal.Notify(s, os.Interrupt, syscall.SIGTERM)
|
|
||||||
<-s
|
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/profiler.go
Normal file
16
src/profiler.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Profile is a Goroutine for automatically profiling the program for optimization and debug reasons.
|
||||||
|
func Profile(port uint16) {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/", pprof.Profile)
|
||||||
|
|
||||||
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), mux))
|
||||||
|
}
|
||||||
561
src/routes.go
561
src/routes.go
@@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/mineatar-io/skin-render"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -64,347 +63,6 @@ func ListHandler(ctx *fiber.Ctx) error {
|
|||||||
return ctx.JSON(result)
|
return ctx.JSON(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
|
|
||||||
func FullBodyHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:fullbody-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if data, err = EncodePNG(skin.RenderBody(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
})); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FrontBodyHandler is the API handler used for the `/body/front/:uuid` route.
|
|
||||||
func FrontBodyHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.FrontBody)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:frontbody-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderFrontBody(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BackBodyHandler is the API handler used for the `/body/back/:uuid` route.
|
|
||||||
func BackBodyHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.BackBody)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:backbody-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderBackBody(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LeftBodyHandler is the API handler used for the `/body/left/:uuid` route.
|
|
||||||
func LeftBodyHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.LeftBody)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:leftbody-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderLeftBody(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RightBodyHandler is the API handler used for the `/body/right/:uuid` route.
|
|
||||||
func RightBodyHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.RightBody)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:rightbody-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderRightBody(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FaceHandler is the API handler used for the `/face/:uuid` route.
|
|
||||||
func FaceHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.Face)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:face-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderFace(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeadHandler is the API handler used for the `/head/:uuid` route.
|
|
||||||
func HeadHandler(ctx *fiber.Ctx) error {
|
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.Head)
|
|
||||||
|
|
||||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return SendUsernameDeprecation(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("result:head-%d-%t-%s", opts.Scale, opts.Overlay, uuid)
|
|
||||||
|
|
||||||
data, err := r.GetBytes(cacheKey)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Set("X-Cache-Hit", strconv.FormatBool(data != nil))
|
|
||||||
|
|
||||||
if data == nil {
|
|
||||||
rawSkin, slim, err := GetPlayerSkin(uuid)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err = EncodePNG(skin.RenderHead(rawSkin, skin.Options{
|
|
||||||
Overlay: opts.Overlay,
|
|
||||||
Slim: slim,
|
|
||||||
Scale: opts.Scale,
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.Set(cacheKey, data, conf.Cache.RenderCacheDuration); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Download {
|
|
||||||
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.Type("png").Send(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SkinHandler is the API handler used for the `/skin/:uuid` route.
|
// SkinHandler is the API handler used for the `/skin/:uuid` route.
|
||||||
func SkinHandler(ctx *fiber.Ctx) error {
|
func SkinHandler(ctx *fiber.Ctx) error {
|
||||||
opts := ParseQueryParams(ctx, conf.Routes.RawSkin)
|
opts := ParseQueryParams(ctx, conf.Routes.RawSkin)
|
||||||
@@ -412,7 +70,7 @@ func SkinHandler(ctx *fiber.Ctx) error {
|
|||||||
uuid, ok := ParseUUID(ctx.Params("uuid"))
|
uuid, ok := ParseUUID(ctx.Params("uuid"))
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return SendUsernameDeprecation(ctx)
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
}
|
}
|
||||||
|
|
||||||
rawSkin, _, err := GetPlayerSkin(uuid)
|
rawSkin, _, err := GetPlayerSkin(uuid)
|
||||||
@@ -434,6 +92,223 @@ func SkinHandler(ctx *fiber.Ctx) error {
|
|||||||
return ctx.Type("png").Send(data)
|
return ctx.Type("png").Send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FaceHandler is the API handler used for the `/face/:uuid` route.
|
||||||
|
func FaceHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.Face)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeFace, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HeadHandler is the API handler used for the `/head/:uuid` route.
|
||||||
|
func HeadHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.Head)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeHead, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
|
||||||
|
func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeFullBody, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FrontBodyHandler is the API handler used for the `/body/front/:uuid` route.
|
||||||
|
func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.FrontBody)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeFrontBody, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackBodyHandler is the API handler used for the `/body/back/:uuid` route.
|
||||||
|
func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.BackBody)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeBackBody, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LeftBodyHandler is the API handler used for the `/body/left/:uuid` route.
|
||||||
|
func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.LeftBody)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeLeftBody, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RightBodyHandler is the API handler used for the `/body/right/:uuid` route.
|
||||||
|
func RightBodyHandler(ctx *fiber.Ctx) error {
|
||||||
|
opts := ParseQueryParams(ctx, conf.Routes.RightBody)
|
||||||
|
|
||||||
|
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return ctx.Status(http.StatusBadRequest).SendString("Invalid UUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSkin, isSlim, err := GetPlayerSkin(uuid)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, cache, err := Render(RenderTypeRightBody, uuid, rawSkin, isSlim, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Set("X-Cache-Hit", strconv.FormatBool(cache))
|
||||||
|
|
||||||
|
if opts.Download {
|
||||||
|
ctx.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Type("png").Send(result)
|
||||||
|
}
|
||||||
|
|
||||||
// NotFoundHandler is the API handler used for any requests that do not match an existing route.
|
// NotFoundHandler is the API handler used for any requests that do not match an existing route.
|
||||||
func NotFoundHandler(ctx *fiber.Ctx) error {
|
func NotFoundHandler(ctx *fiber.Ctx) error {
|
||||||
return ctx.SendStatus(http.StatusNotFound)
|
return ctx.SendStatus(http.StatusNotFound)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ListenAndServe(host string, port uint16) {
|
|
||||||
log.Printf("Listening on %s:%d\n", host, port)
|
|
||||||
|
|
||||||
if err := app.Listen(fmt.Sprintf("%s:%d", host, port)); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
194
src/util.go
194
src/util.go
@@ -20,6 +20,14 @@ import (
|
|||||||
var (
|
var (
|
||||||
//go:embed favicon.ico
|
//go:embed favicon.ico
|
||||||
favicon []byte
|
favicon []byte
|
||||||
|
|
||||||
|
RenderTypeFullBody = "fullbody"
|
||||||
|
RenderTypeFrontBody = "frontbody"
|
||||||
|
RenderTypeBackBody = "backbody"
|
||||||
|
RenderTypeLeftBody = "leftbody"
|
||||||
|
RenderTypeRightBody = "rightbody"
|
||||||
|
RenderTypeFace = "face"
|
||||||
|
RenderTypeHead = "head"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryParams is used by most all API routes as options for how the image should be rendered, or how errors should be handled.
|
// QueryParams is used by most all API routes as options for how the image should be rendered, or how errors should be handled.
|
||||||
@@ -27,6 +35,119 @@ type QueryParams struct {
|
|||||||
Scale int `query:"scale"`
|
Scale int `query:"scale"`
|
||||||
Download bool `query:"download"`
|
Download bool `query:"download"`
|
||||||
Overlay bool `query:"overlay"`
|
Overlay bool `query:"overlay"`
|
||||||
|
Fallback bool `query:"fallback"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointerOf returns the value of the first argument as a pointer.
|
||||||
|
func PointerOf[T any](v T) *T {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render will render the image using the specified details and return the result.
|
||||||
|
func Render(renderType, uuid string, rawSkin *image.NRGBA, isSlim bool, opts *QueryParams) ([]byte, bool, error) {
|
||||||
|
cache, err := GetCachedRenderResult(renderType, uuid, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cache != nil {
|
||||||
|
if conf.Environment == "development" {
|
||||||
|
log.Printf("Retrieved render from cache (type=%s, uuid=%s, slim=%v, scale=%d)\n", renderType, uuid, isSlim, opts.Scale)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
result *image.NRGBA
|
||||||
|
renderOpts skin.Options = skin.Options{
|
||||||
|
Overlay: opts.Overlay,
|
||||||
|
Slim: isSlim,
|
||||||
|
Scale: opts.Scale,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
switch renderType {
|
||||||
|
case RenderTypeFullBody:
|
||||||
|
{
|
||||||
|
result = skin.RenderBody(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeFrontBody:
|
||||||
|
{
|
||||||
|
result = skin.RenderFrontBody(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeBackBody:
|
||||||
|
{
|
||||||
|
result = skin.RenderBackBody(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeLeftBody:
|
||||||
|
{
|
||||||
|
result = skin.RenderLeftBody(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeRightBody:
|
||||||
|
{
|
||||||
|
result = skin.RenderRightBody(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeHead:
|
||||||
|
{
|
||||||
|
result = skin.RenderHead(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case RenderTypeFace:
|
||||||
|
{
|
||||||
|
result = skin.RenderFace(rawSkin, renderOpts)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Errorf("unknown render type: %s", renderType))
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := EncodePNG(result)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = SetCachedRenderResult(renderType, uuid, opts, data); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if conf.Environment == "development" {
|
||||||
|
log.Printf("Rendered image (type=%s, uuid=%s, slim=%v, scale=%d)\n", renderType, uuid, isSlim, opts.Scale)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCachedRenderResult returns the render result from Redis cache, or nil if it does not exist or cache is disabled.
|
||||||
|
func GetCachedRenderResult(renderType, uuid string, opts *QueryParams) ([]byte, error) {
|
||||||
|
if conf.Cache.RenderCacheDuration == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.GetBytes(fmt.Sprintf("result:%s-%d-%t-%s", renderType, opts.Scale, opts.Overlay, uuid))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCachedRenderResult puts the render result into cache, or does nothing is cache is disabled.
|
||||||
|
func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []byte) error {
|
||||||
|
if conf.Cache.RenderCacheDuration == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Set(fmt.Sprintf("result:%s-%d-%t-%s", renderType, opts.Scale, opts.Overlay, uuid), data, *conf.Cache.RenderCacheDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatUUID returns the UUID string without any dashes.
|
// FormatUUID returns the UUID string without any dashes.
|
||||||
@@ -74,32 +195,38 @@ func FetchImage(url string) (*image.NRGBA, error) {
|
|||||||
|
|
||||||
// GetPlayerSkin fetches the skin of the Minecraft player by the UUID.
|
// GetPlayerSkin fetches the skin of the Minecraft player by the UUID.
|
||||||
func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||||
cache, ok, err := r.GetNRGBA(fmt.Sprintf("skin:%s", uuid))
|
if conf.Cache.SkinCacheDuration != nil {
|
||||||
|
cache, ok, err := r.GetNRGBA(fmt.Sprintf("skin:%s", uuid))
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
slim, err := r.Exists(fmt.Sprintf("slim:%s", uuid))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache, slim, nil
|
if ok {
|
||||||
|
slim, err := r.Exists(fmt.Sprintf("slim:%s", uuid))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if conf.Environment == "development" {
|
||||||
|
log.Printf("Retrieved player skin from cache (uuid=%s, slim=%v)\n", uuid, slim)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache, slim, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSlimFromUUID := skin.IsSlimFromUUID(uuid)
|
||||||
|
|
||||||
textures, err := GetProfileTextures(uuid)
|
textures, err := GetProfileTextures(uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return skin.GetDefaultSkin(isSlimFromUUID), true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if textures == nil {
|
if textures == nil {
|
||||||
slim := skin.IsSlimFromUUID(uuid)
|
return skin.GetDefaultSkin(isSlimFromUUID), isSlimFromUUID, nil
|
||||||
|
|
||||||
return skin.GetDefaultSkin(slim), slim, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = r.Set(fmt.Sprintf("unique:%s", textures.UUID), "0", 0); err != nil {
|
if err = r.Set(fmt.Sprintf("unique:%s", textures.UUID), "0", 0); err != nil {
|
||||||
@@ -117,9 +244,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(value) < 1 {
|
if len(value) < 1 {
|
||||||
slim := skin.IsSlimFromUUID(uuid)
|
return skin.GetDefaultSkin(isSlimFromUUID), isSlimFromUUID, nil
|
||||||
|
|
||||||
return skin.GetDefaultSkin(slim), slim, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
texturesResult, err := GetDecodedTexturesValue(value)
|
texturesResult, err := GetDecodedTexturesValue(value)
|
||||||
@@ -129,9 +254,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(texturesResult.Textures.Skin.URL) < 1 {
|
if len(texturesResult.Textures.Skin.URL) < 1 {
|
||||||
slim := skin.IsSlimFromUUID(uuid)
|
return skin.GetDefaultSkin(isSlimFromUUID), isSlimFromUUID, nil
|
||||||
|
|
||||||
return skin.GetDefaultSkin(slim), slim, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slim := texturesResult.Textures.Skin.Metadata.Model == "slim"
|
slim := texturesResult.Textures.Skin.Metadata.Model == "slim"
|
||||||
@@ -148,18 +271,24 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
|||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = r.Set(fmt.Sprintf("skin:%s", uuid), encodedSkin, conf.Cache.SkinCacheDuration); err != nil {
|
if conf.Cache.SkinCacheDuration != nil {
|
||||||
return nil, false, err
|
if err = r.Set(fmt.Sprintf("skin:%s", uuid), encodedSkin, *conf.Cache.SkinCacheDuration); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if slim {
|
||||||
|
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", *conf.Cache.SkinCacheDuration); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err = r.Delete(fmt.Sprintf("slim:%s", uuid)); err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slim {
|
if conf.Environment == "development" {
|
||||||
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", conf.Cache.SkinCacheDuration); err != nil {
|
log.Printf("Fetched player skin from Mojang (uuid=%s, slim=%v)\n", uuid, slim)
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err = r.Delete(fmt.Sprintf("slim:%s", uuid)); err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return skin, slim, nil
|
return skin, slim, nil
|
||||||
@@ -167,7 +296,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
|||||||
|
|
||||||
// Clamp clamps the input value between the minimum and maximum values.
|
// Clamp clamps the input value between the minimum and maximum values.
|
||||||
// This method is preferred over `math.Min()` and `math.Max()` to prevent any type coercion between floats and integers.
|
// This method is preferred over `math.Min()` and `math.Max()` to prevent any type coercion between floats and integers.
|
||||||
func Clamp(value, min, max int) int {
|
func Clamp[T int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64](value, min, max T) T {
|
||||||
if value > max {
|
if value > max {
|
||||||
return max
|
return max
|
||||||
}
|
}
|
||||||
@@ -236,8 +365,3 @@ func GetInstanceID() (uint16, error) {
|
|||||||
func ExtractUUID(ctx *fiber.Ctx) string {
|
func ExtractUUID(ctx *fiber.Ctx) string {
|
||||||
return strings.Split(ctx.Params("uuid"), ".")[0]
|
return strings.Split(ctx.Params("uuid"), ".")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendUsernameDeprecation sends a deprecation warning about usernames.
|
|
||||||
func SendUsernameDeprecation(ctx *fiber.Ctx) error {
|
|
||||||
return ctx.Status(http.StatusBadRequest).SendString("Deprecated: Username support has been deprecated since 23 April 2023, please use a valid UUID instead.")
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user