12 Commits

Author SHA1 Message Date
0cc3db4842 fix(deps): update dependency org.springframework.boot:spring-boot-starter-parent to v3.3.5 2024-10-24 14:02:32 +00:00
Lee
f24b907b1a Merge pull request 'fix(deps): update dependency org.jetbrains:annotations to v25' (#17) from renovate/org.jetbrains-annotations-25.x into master
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 11s
Reviewed-on: #17
2024-09-25 23:49:35 +00:00
88e8c4d3e8 fix(deps): update dependency org.jetbrains:annotations to v25 2024-09-25 08:01:40 +00:00
7b560075ba mod: cleanup auth
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 35s
Release Mod / Build (push) Successful in 30s
2024-08-15 18:22:16 +01:00
d888ab1eb5 Merge remote-tracking branch 'origin/master'
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 1m21s
2024-08-09 00:52:04 +01:00
8371344a7d change account refresh interval 2024-08-09 00:51:36 +01:00
Lee
ea0e4bd20a Merge pull request 'Update actions/checkout action to v4' (#10) from renovate/actions-checkout-4.x into master
All checks were successful
Release Mod / Build (push) Successful in 28s
Reviewed-on: #10
2024-08-07 07:44:10 +00:00
Lee
02290e5bde Merge pull request 'Update actions/setup-dotnet action to v4' (#11) from renovate/actions-setup-dotnet-4.x into master
Some checks failed
Release Mod / Build (push) Has been cancelled
Reviewed-on: #11
2024-08-07 07:44:00 +00:00
Lee
ef2aeb5f0a Merge pull request 'Update dependency BepInEx.AssemblyPublicizer.MSBuild to v0.4.2' (#12) from renovate/bepinex.assemblypublicizer.msbuild-0.x into master
Some checks failed
Release Mod / Build (push) Has been cancelled
Reviewed-on: #12
2024-08-07 07:43:47 +00:00
456f2afff0 Update actions/setup-dotnet action to v4 2024-08-07 07:01:18 +00:00
e0eda1a053 Update actions/checkout action to v4 2024-08-07 07:01:17 +00:00
f9b95744f8 Update dependency BepInEx.AssemblyPublicizer.MSBuild to v0.4.2 2024-08-07 06:01:08 +00:00
9 changed files with 54 additions and 89 deletions

View File

@ -12,13 +12,13 @@ jobs:
run: run:
working-directory: "./Mod" working-directory: "./Mod"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Setup Running in CI Variable - name: Setup Running in CI Variable
run: echo "RUNNING_IN_CI=true" >> $GITHUB_ENV run: echo "RUNNING_IN_CI=true" >> $GITHUB_ENV
- name: Setup dotnet - name: Setup dotnet
uses: actions/setup-dotnet@v3 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: 7.0.x dotnet-version: 7.0.x

View File

@ -11,7 +11,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version> <version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
@ -116,7 +116,7 @@
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>24.1.0</version> <version>25.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -39,7 +39,5 @@ public class Main {
// Start the app // Start the app
SpringApplication.run(Main.class, args); SpringApplication.run(Main.class, args);
} }
} }

View File

@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit;
@Log4j2(topic = "User Service") @Log4j2(topic = "User Service")
public class UserService { public class UserService {
/** /**
* The interval to force update the user's account. * The interval to refresh the user's account data from external services
*/ */
private static long FORCE_UPDATE_INTERVAL = TimeUnit.HOURS.toMillis(4); private static long ACCOUNT_REFRESH_INTERVAL = TimeUnit.HOURS.toMillis(1);
/** /**
* The user repository to use * The user repository to use
@ -103,9 +103,9 @@ public class UserService {
// Ensure the users ScoreSaber account is up-to-date // Ensure the users ScoreSaber account is up-to-date
ScoreSaberAccount scoresaberAccount = user.getScoresaberAccount(); ScoreSaberAccount scoresaberAccount = user.getScoresaberAccount();
if (scoresaberAccount == null || scoresaberAccount.getLastUpdated().before(new Date(System.currentTimeMillis() - FORCE_UPDATE_INTERVAL))) { if (scoresaberAccount == null || scoresaberAccount.getLastUpdated().before(new Date(System.currentTimeMillis() - ACCOUNT_REFRESH_INTERVAL))) {
try { try {
log.info("Updating account for '{}', last update: {}", log.info("[Scoresaber] Updating account for '{}', last update: {}",
steamId, steamId,
scoresaberAccount == null ? "now" : TimeUtils.format(System.currentTimeMillis() - scoresaberAccount.getLastUpdated().getTime()) scoresaberAccount == null ? "now" : TimeUtils.format(System.currentTimeMillis() - scoresaberAccount.getLastUpdated().getTime())
); );
@ -118,7 +118,7 @@ public class UserService {
historyToday.setCountryRank(accountToken.getCountryRank()); historyToday.setCountryRank(accountToken.getCountryRank());
historyToday.setPp(accountToken.getPp()); historyToday.setPp(accountToken.getPp());
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to update ScoreSaber account for '{}'", steamId, ex); log.error("[Scoresaber] Failed to update account for '{}'", steamId, ex);
} }
shouldUpdate = true; shouldUpdate = true;
} }

View File

@ -2,42 +2,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ScoreTracker.API namespace ScoreTracker.API
{ {
internal class AuthHelper internal class SigninResponse
{ {
public bool IsLoggedIn; public bool Success { get; set; }
public string FailReason = ""; public string Response { get; set; }
/// <summary>
/// Ensure the user is logged in
/// </summary>
/// <returns>the task</returns>
public async Task EnsureLoggedIn()
{
if (Authentication.IsSignedIn() && await Authentication.ValidateAuthToken())
{
return; // Already logged in with a valid token
}
await Authentication.LoginUser(
token => {
IsLoggedIn = true;
Request.PersistHeaders(new Dictionary<string, string>
{
{ "Authorization", $"Bearer {token}" }
});
},
reason =>
{
FailReason = reason; // Store the reason for failure
Request.HttpClient.DefaultRequestHeaders.Clear(); // Clear headers
}
);
}
} }
internal class Authentication internal class Authentication
@ -46,11 +18,42 @@ namespace ScoreTracker.API
private static string _authToken; private static string _authToken;
/// <summary> /// <summary>
/// Are we signed in? /// Validate the auth token and sign in if necessary
/// </summary> /// </summary>
public static bool IsSignedIn() public static async Task<SigninResponse> ValidateAndSignIn()
{ {
return _signedIn; if (_signedIn && await ValidateAuthToken())
{
return new SigninResponse
{
Success = true,
Response = null
}; // Already signed in
}
bool success = false;
string response = null;
await LoginUser(
token => {
success = true;
Request.PersistHeaders(new Dictionary<string, string>
{
{ "Authorization", $"Bearer {token}" }
});
},
reason =>
{
response = reason;
Request.HttpClient.DefaultRequestHeaders.Clear(); // Clear headers
}
);
return new SigninResponse
{
Success = success,
Response = response
};
} }
/// <summary> /// <summary>

View File

@ -35,11 +35,10 @@ namespace ScoreTracker.API
{ {
if (checkAuth) if (checkAuth)
{ {
var authHelper = new AuthHelper(); var signinResponse = await Authentication.ValidateAndSignIn();
await authHelper.EnsureLoggedIn(); if (!signinResponse.Success)
if (!authHelper.IsLoggedIn)
{ {
throw new Exception($"Failed to log in: {authHelper.FailReason}"); throw new Exception($"Failed to log in: {signinResponse.Response}");
} }
} }
var jsonString = JsonConvert.SerializeObject(json, Formatting.None); var jsonString = JsonConvert.SerializeObject(json, Formatting.None);

View File

@ -40,8 +40,7 @@ namespace ScoreTracker
// Ensure the user is logged in // Ensure the user is logged in
Task.Factory.StartNew(async () => Task.Factory.StartNew(async () =>
{ {
var authHelper = new AuthHelper(); await Authentication.ValidateAndSignIn(); // Ensure the user is signed in
await authHelper.EnsureLoggedIn();
}); });
} }

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ScoreTracker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScoreTracker")]
[assembly: AssemblyCopyright("Copyright © Fascinated 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8d4a32fe-ab2a-4d8e-a53b-6a1d4f1d7bb9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1")]
[assembly: AssemblyFileVersion("0.0.1")]

View File

@ -5,7 +5,6 @@
<TargetFramework>net472</TargetFramework> <TargetFramework>net472</TargetFramework>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<LangVersion>7.3</LangVersion> <LangVersion>7.3</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LocalRefsDir Condition="Exists('..\Refs')">..\Refs</LocalRefsDir> <LocalRefsDir Condition="Exists('..\Refs')">..\Refs</LocalRefsDir>
<BeatSaberDir>$(LocalRefsDir)</BeatSaberDir> <BeatSaberDir>$(LocalRefsDir)</BeatSaberDir>
<AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase> <AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase>
@ -17,6 +16,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<Configurations>Release</Configurations> <Configurations>Release</Configurations>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="BS_Utils, Version=1.12.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="BS_Utils, Version=1.12.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private> <Private>False</Private>
@ -104,6 +106,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks" Version="2.0.0-beta7" PrivateAssets="all" /> <PackageReference Include="BeatSaberModdingTools.Tasks" Version="2.0.0-beta7" PrivateAssets="all" />
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" /> <PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
</Project> </Project>