Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure profileId is set when testing API token #77

Merged
merged 7 commits into from
May 29, 2024

Conversation

Owaan
Copy link
Contributor

@Owaan Owaan commented May 28, 2024

Resolves #73

Not sure if the profile ID needs to be mapped to the API key as TarkovTracker isn't separating profiles (yet). This should do the job though 👍

This also fixes the scenario where a user could be confused launching TarkovMonitor before launching Tarkov or having a profile reported in their logs. You'll still need to handle launching TarkovMonitor without even having Tarkov installed though....

@Razzmatazzz
Copy link
Member

@Owaan Thank you for this PR! Can you explain a bit more the reasoning behind the changes? Is the current code for associating profiles with tarkov tracker tokens not working as intended?

@Owaan
Copy link
Contributor Author

Owaan commented May 28, 2024

@Razzmatazzz All good!

I've fixed two issues in this PR caused by the profileId changes. My general thoughts are that both of these issues are caused by using a dictionary to map a profileId to the API tokens when you might not need to. I have left that the same in my changes incase you had future plans regarding that.

Issue 1:

Fixed by this commit

Testing Steps:

  1. Remove AppData/Local/TarkovMonitor/<path>/<version>/user.config
  2. Launch TarkovMonitor
  3. Paste TarkovTracker API key into Settings API Key
  4. Click "Test Token"

Expected Result:
API success response

Actual Result:
"TarkovTracker API error: The given key '' was not present in the dictionary."

Solution:
The original code here, currentProfile could be an empty string so you'd never find the token in the dictionary.

return Task.Run<string>(() => {
    return tokens[currentProfile];
});

I'm now passing the profileId into the TestToken method.

Issue 2:

Fixed by this commit
and this commit

Testing Steps:

  1. Remove AppData/Local/TarkovMonitor/<path>/<version>/user.config
  2. Empty your C:\Battlestate Games\EFT\Logs directory (leaving one log which doesn't include a profileId)
  3. Launch TarkovMonitor

Expected Result:
A graceful error indicating the game needs to be started at least once to track progress

Actual Result:
An ambiguous error (I can't even recall exactly what it was at this point)

Solution:
I've just tried to catch a few places to handle if the profileId couldn't be found.

@Razzmatazzz
Copy link
Member

Thanks for the explanation, and for the fixes!

Copy link
Member

@Razzmatazzz Razzmatazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm misunderstanding things, I think some of these changes can be streamlined a bit. Thanks again for the PR!

TarkovMonitor/TarkovTracker.cs Outdated Show resolved Hide resolved
TarkovMonitor/TarkovTracker.cs Outdated Show resolved Hide resolved
TarkovMonitor/TarkovTracker.cs Outdated Show resolved Hide resolved
TarkovMonitor/Blazor/Pages/Settings/Settings.razor Outdated Show resolved Hide resolved
@Owaan
Copy link
Contributor Author

Owaan commented May 29, 2024

@Razzmatazzz oh yeah you might be right I think I misread something and also forgot to use the profileId I passed in anyways lol... Will clean it up in a bit, test and recommit

@Owaan Owaan changed the title Pass the profileId through when testing an API token Ensure profileId is set when testing API token May 29, 2024
@Owaan
Copy link
Contributor Author

Owaan commented May 29, 2024

@Razzmatazzz All changes fixed, first time using C#, apologies that wasn't so clean the first go around

I've just used your existing GetToken method in the AuthorizationHeaderValueGetter method now.

The main issue was in InitializeProgress, we needed to set the TarkovTracker profile before calling TarkovTracker.TestToken()

Copy link
Member

@Razzmatazzz Razzmatazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks again! Can you update the branch so it isn't out of date from the main branch? That's a result of my merging your other PR.

@Razzmatazzz Razzmatazzz merged commit e6131e5 into the-hideout:master May 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TarkovTracker API error: The given key '' was not present in the dictionary.
2 participants