ajout de plateforme de base pour les url TRN
This commit is contained in:
@@ -52,6 +52,12 @@ PLATFORM_CODES = {
|
||||
'Epic': 'epic',
|
||||
}
|
||||
|
||||
PLATFORM_DEFAULTS = {
|
||||
'Apex Legends': 'pc',
|
||||
'Rainbow Six Siege': 'ubi',
|
||||
'Rocket League': 'epic'
|
||||
}
|
||||
|
||||
TRN_URLS = {
|
||||
'Valorant': 'https://tracker.gg/valorant/profile/riot/{username}',
|
||||
'League of Legends': 'https://tracker.gg/lol/profile/{username}',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Store gamertag per game for each user."""
|
||||
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
|
||||
|
||||
|
||||
@@ -24,15 +24,19 @@ class UserGamertag(db.Model):
|
||||
return None
|
||||
url = TRN_URLS[self.game]
|
||||
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:
|
||||
platform_code = PLATFORM_CODES.get(
|
||||
self.platform,
|
||||
self.platform.lower().replace(' ', '-') if self.platform else '',
|
||||
platform,
|
||||
platform.lower().replace(' ', '-') if platform else '',
|
||||
)
|
||||
return url.format(platform_code=platform_code, username=encoded_gamertag)
|
||||
elif '{platform}' in url and '{username}' in url:
|
||||
return url.format(
|
||||
platform=self.platform.lower().replace(' ', '-'),
|
||||
platform=platform.lower().replace(' ', '-') if platform else '',
|
||||
username=encoded_gamertag,
|
||||
)
|
||||
elif '{username}' in url:
|
||||
|
||||
Reference in New Issue
Block a user