From b5f1fdc4984d9682db003988467323b0a928bb48 Mon Sep 17 00:00:00 2001 From: AdamZ Date: Tue, 24 Nov 2026 16:00:03 -0800 Subject: [PATCH] Suggest build name for OAuth character imports --- src/Classes/ImportTab.lua | 36 +++++++++++++++++++++++++++++++----- src/Classes/PoEAPI.lua | 3 +++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Classes/ImportTab.lua b/src/Classes/ImportTab.lua index f4ad27a3e0a..362b7a92f02 100644 --- a/src/Classes/ImportTab.lua +++ b/src/Classes/ImportTab.lua @@ -257,6 +257,7 @@ local function addOAuthControls(self) local function importHandler(data, errMsg) if data and data.character then self.oauthErrCode = nil + self:SetOAuthPredefinedBuildName(selectedName) self:ImportPassiveTreeAndJewels(data.character, deleteJewels) else if errMsg then @@ -298,6 +299,7 @@ local function addOAuthControls(self) local ignoreWeaponSwap = self.controls.charImportItemsIgnoreWeaponSwap.state if data and data.character then self.oauthErrCode = nil + self:SetOAuthPredefinedBuildName(selectedName) self:ImportItemsAndSkills(data.character, clearItems, clearSkills, ignoreWeaponSwap) else if errMsg then @@ -1937,10 +1939,34 @@ function UrlDecode(url) return url end -function ImportTabClass:SetPredefinedBuildName() - local accountName = self.controls.siteAccountName.buf:gsub('%s+', ''):gsub("#%d+", "") - local charSelect = self.controls.siteCharSelect - local charData = charSelect.list[charSelect.selIndex].char - local charName = charData.name +function ImportTabClass:SetOAuthPredefinedBuildName(charName) + self.buildNameRequest = (self.buildNameRequest or 0) + 1 + local request = self.buildNameRequest + local api = main.api + local generation = api.accountGeneration + if api.accountName then + self:SetPredefinedBuildName(api.accountName, charName) + return + end + main.predefinedBuildName = charName + api:DownloadWithRefresh("/profile", function(response, errMsg) + local profile = not errMsg and response and response.body and dkjson.decode(response.body) + if main.api == api and api.accountGeneration == generation and type(profile) == "table" + and type(profile.name) == "string" and profile.name ~= "" then + api.accountName = profile.name + if self.buildNameRequest == request and main.predefinedBuildName == charName then + self:SetPredefinedBuildName(profile.name, charName) + end + end + end) +end + +function ImportTabClass:SetPredefinedBuildName(accountName, charName) + self.buildNameRequest = (self.buildNameRequest or 0) + 1 + accountName = (accountName or self.controls.siteAccountName.buf):gsub('%s+', ''):gsub("#%d+", "") + if not charName then + local charSelect = self.controls.siteCharSelect + charName = charSelect.list[charSelect.selIndex].char.name + end main.predefinedBuildName = accountName .. " - " .. charName end diff --git a/src/Classes/PoEAPI.lua b/src/Classes/PoEAPI.lua index 7a9031df059..9c1d038d018 100644 --- a/src/Classes/PoEAPI.lua +++ b/src/Classes/PoEAPI.lua @@ -22,6 +22,7 @@ function PoEAPIClass:PoEAPI(authToken, refreshToken, tokenExpiry) self.baseUrl = "https://api.pathofexile.com" self.rateLimiter = new("TradeQueryRateLimiter"):TradeQueryRateLimiter() self.tokenHasBeenValidated = false + self.accountGeneration = 0 self.ERROR_NO_AUTH = "No auth token" return self @@ -75,6 +76,8 @@ end --- resets current authorization details function PoEAPIClass:ResetDetails() + self.accountGeneration = self.accountGeneration + 1 + self.accountName = nil self.authToken = nil self.refreshToken = nil self.tokenExpiry = nil