ajout de plateforme de base pour les url TRN

This commit is contained in:
cedrick2711
2026-08-06 20:13:39 -04:00
parent f89e4deb30
commit bb0bc1c192
2 changed files with 15 additions and 5 deletions
+6
View File
@@ -52,6 +52,12 @@ PLATFORM_CODES = {
'Epic': 'epic', 'Epic': 'epic',
} }
PLATFORM_DEFAULTS = {
'Apex Legends': 'pc',
'Rainbow Six Siege': 'ubi',
'Rocket League': 'epic'
}
TRN_URLS = { TRN_URLS = {
'Valorant': 'https://tracker.gg/valorant/profile/riot/{username}', 'Valorant': 'https://tracker.gg/valorant/profile/riot/{username}',
'League of Legends': 'https://tracker.gg/lol/profile/{username}', 'League of Legends': 'https://tracker.gg/lol/profile/{username}',
+9 -5
View File
@@ -1,6 +1,6 @@
"""Store gamertag per game for each user.""" """Store gamertag per game for each user."""
from app.extensions import db from app.extensions import db
from app.models._constants import TRN_URLS, PLATFORM_CODES from app.models._constants import TRN_URLS, PLATFORM_CODES, PLATFORM_DEFAULTS
from urllib.parse import quote from urllib.parse import quote
@@ -24,17 +24,21 @@ class UserGamertag(db.Model):
return None return None
url = TRN_URLS[self.game] url = TRN_URLS[self.game]
encoded_gamertag = quote(self.gamertag, safe='') encoded_gamertag = quote(self.gamertag, safe='')
# Resolve platform: use user's selection, or fall back to game default
platform = self.platform
if not platform:
platform = PLATFORM_DEFAULTS.get(self.game, '')
if '{platform_code}' in url and '{username}' in url: if '{platform_code}' in url and '{username}' in url:
platform_code = PLATFORM_CODES.get( platform_code = PLATFORM_CODES.get(
self.platform, platform,
self.platform.lower().replace(' ', '-') if self.platform else '', platform.lower().replace(' ', '-') if platform else '',
) )
return url.format(platform_code=platform_code, username=encoded_gamertag) return url.format(platform_code=platform_code, username=encoded_gamertag)
elif '{platform}' in url and '{username}' in url: elif '{platform}' in url and '{username}' in url:
return url.format( return url.format(
platform=self.platform.lower().replace(' ', '-'), platform=platform.lower().replace(' ', '-') if platform else '',
username=encoded_gamertag, username=encoded_gamertag,
) )
elif '{username}' in url: elif '{username}' in url:
return url.format(username=encoded_gamertag) return url.format(username=encoded_gamertag)
return url return url