File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- version : ' 3.8'
2-
31services :
42 # PostgreSQL Database
53 postgres :
@@ -13,8 +11,6 @@ services:
1311 volumes :
1412 - postgres_data:/var/lib/postgresql/data
1513 - ./migrations:/docker-entrypoint-initdb.d:ro
16- ports :
17- - " 5432:5432"
1814 healthcheck :
1915 test : ["CMD-SHELL", "pg_isready -U texture_user -d texture_provider"]
2016 interval : 10s
@@ -35,7 +31,7 @@ services:
3531 DATABASE_URL : postgresql://texture_user:texture_password@postgres/texture_provider
3632
3733 # JWT (You should replace this with your actual public key)
38- JWT_PUBLIC_KEY : BASE64_ECDSA_LAUNCHSERVER_KEY
34+ JWT_PUBLIC_KEY : MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEjKxPlWFkYXHKt3BpXEJLhF3F8qlKvLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqLqA==
3935
4036 # Base URL
4137 BASE_URL : http://localhost:3000
@@ -46,8 +42,11 @@ services:
4642
4743 # Retrieval Configuration
4844 RETRIEVAL_TYPE : storage
49- # RETRIEVAL_CHAIN: storage,mojang,default_skin
45+ RETRIEVAL_CHAIN : storage,mojang,default_skin
5046
47+ # Admin API (optional)
48+ ADMIN_TOKEN : test-admin-token-12345
49+
5150 # Server
5251 SERVER_PORT : 3000
5352 volumes :
Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ pub async fn upload_texture(
199199 // Store file with proper extension
200200 let file_url = state
201201 . storage
202- . store_file ( file_bytes. clone ( ) , & hash, texture_type. file_extension ( ) )
202+ . store_file ( file_bytes, & hash, texture_type. file_extension ( ) )
203203 . await
204204 . map_err ( |e| {
205205 tracing:: error!( "Failed to store file: {}" , e) ;
@@ -399,7 +399,7 @@ pub async fn admin_upload_texture(
399399 let username_str = field. text ( ) . await . map_err ( |e| {
400400 (
401401 StatusCode :: BAD_REQUEST ,
402- format ! ( "Failed to read user UUID : {}" , e) ,
402+ format ! ( "Failed to read username : {}" , e) ,
403403 )
404404 } ) ?;
405405 user_username = Some ( username_str) ;
@@ -448,7 +448,7 @@ pub async fn admin_upload_texture(
448448 // Store file with proper extension
449449 let file_url = state
450450 . storage
451- . store_file ( file_bytes. clone ( ) , & hash, texture_type. file_extension ( ) )
451+ . store_file ( file_bytes, & hash, texture_type. file_extension ( ) )
452452 . await
453453 . map_err ( |e| {
454454 tracing:: error!( "Failed to store file: {}" , e) ;
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ use crate::auth::decode_key;
2424
2525#[ tokio:: main]
2626async fn main ( ) -> anyhow:: Result < ( ) > {
27- // Load .env file
28- dotenvy:: dotenv ( ) ? ;
27+ // Load .env file (ignore error if file doesn't exist, e.g., in Docker)
28+ let _ = dotenvy:: dotenv ( ) ;
2929
3030 // Initialize tracing
3131 tracing_subscriber:: registry ( )
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ pub struct DefaultSkinRetriever {
1919impl DefaultSkinRetriever {
2020 pub fn new ( ) -> Self {
2121 // The official default Steve skin from Minecraft
22- let default_steve_url = "http ://textures.minecraft.net/texture/1a4af718455d58aab3011401517e43cb6f84b5f9cbd717f8df0334e0b88b8ecf" . to_string ( ) ;
22+ let default_steve_url = "https ://textures.minecraft.net/texture/1a4af718455d58aab3011401517e43cb6f84b5f9cbd717f8df0334e0b88b8ecf" . to_string ( ) ;
2323
2424 // Pre-computed hash of the default Steve skin
2525 let default_steve_hash =
@@ -151,7 +151,7 @@ impl EmbeddedDefaultSkinRetriever {
151151impl TextureRetriever for EmbeddedDefaultSkinRetriever {
152152 async fn get_texture (
153153 & self ,
154- user_uuid : Uuid ,
154+ _user_uuid : Uuid ,
155155 texture_type : TextureType ,
156156 ) -> Result < Option < RetrievedTexture > > {
157157 match texture_type {
@@ -172,7 +172,7 @@ impl TextureRetriever for EmbeddedDefaultSkinRetriever {
172172 }
173173 }
174174
175- async fn get_textures ( & self , user_uuid : Uuid ) -> Result < HashMap < String , RetrievedTexture > > {
175+ async fn get_textures ( & self , _user_uuid : Uuid ) -> Result < HashMap < String , RetrievedTexture > > {
176176 let mut map = HashMap :: new ( ) ;
177177 let url = format ! (
178178 "{}/download/{}" ,
@@ -192,7 +192,7 @@ impl TextureRetriever for EmbeddedDefaultSkinRetriever {
192192
193193 async fn get_texture_bytes (
194194 & self ,
195- user_uuid : Uuid ,
195+ _user_uuid : Uuid ,
196196 texture_type : TextureType ,
197197 ) -> Result < Option < RetrievedTextureBytes > > {
198198 match texture_type {
Original file line number Diff line number Diff line change @@ -232,6 +232,53 @@ impl MojangRetriever {
232232
233233#[ async_trait]
234234impl TextureRetriever for MojangRetriever {
235+ async fn get_texture (
236+ & self ,
237+ user_uuid : Uuid ,
238+ texture_type : TextureType ,
239+ ) -> Result < Option < RetrievedTexture > > {
240+ let mut fetch_uuid = user_uuid;
241+
242+ if self . use_database_username_in_mojang_requests {
243+ if let Some ( db) = & self . db {
244+ match sqlx:: query!(
245+ r#"
246+ SELECT username
247+ FROM username_mappings
248+ WHERE user_uuid = $1
249+ LIMIT 1
250+ "# ,
251+ user_uuid
252+ ) . fetch_optional ( db) . await {
253+ Ok ( Some ( record) ) => {
254+ match self . resolve_username_to_uuid ( & record. username ) . await {
255+ Ok ( Some ( resolved_uuid) ) => {
256+ fetch_uuid = resolved_uuid;
257+ }
258+ Ok ( None ) => {
259+ tracing:: warn!(
260+ "Username '{}' not found in Mojang API, using original UUID" ,
261+ record. username
262+ ) ;
263+ }
264+ Err ( e) => {
265+ tracing:: error!( "Failed to resolve username from Mojang: {}" , e) ;
266+ }
267+ }
268+ }
269+ Ok ( None ) => {
270+ tracing:: debug!( "No username mapping found for UUID {}" , user_uuid) ;
271+ }
272+ Err ( e) => {
273+ tracing:: error!( "Failed to lookup username from database: {}" , e) ;
274+ }
275+ }
276+ }
277+ }
278+
279+ self . get_texture_from_mojang ( fetch_uuid, texture_type) . await
280+ }
281+
235282 async fn get_textures ( & self , user_uuid : Uuid ) -> Result < HashMap < String , RetrievedTexture > > {
236283 let mut fetch_uuid = user_uuid;
237284
You can’t perform that action at this time.
0 commit comments