Skip to content

Commit

Permalink
Adapted to the newer site revision
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed May 23, 2024
1 parent 13329ab commit dd1a324
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ The remaining two configuration keys are sensitive and should not be made public

- If you have the raw Cookie header from a valid session, you can include the whole header in the `UNEX_COOKIES` variable
- If you have an exported `cookies.txt` file, you can include the relative path to the file in the `UNEX_COOKIES` variable (like `./cookies.txt`)
- If you have the `sid_develop` variable, include it in the `UNEX_COOKIES` variable
- If you have the `nexusmods_session` variable, include it in the `UNEX_COOKIES` variable
- The lifetime of the `nexusmods_session` value is a week, so you may need to update it regularly

> All relative paths will be parsed relative to the *current working directory*

Expand Down
5 changes: 3 additions & 2 deletions src/NexusUploader/Http/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static IHttpClientBuilder AddNexusClient(this ServiceCollection services)
return services.AddHttpClient<ManageClient>(client =>
{
client.BaseAddress = new System.Uri("https://www.nexusmods.com");
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("NexusUploader", "1.0.1"));
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("NexusUploader", "2.0.0"));
}).ConfigurePrimaryHttpMessageHandler<NexusCookieHandler>();
}

Expand All @@ -22,7 +22,7 @@ public static IHttpClientBuilder AddUploadClient(this IServiceCollection service
return services.AddHttpClient<UploadClient>(client =>
{
client.BaseAddress = new System.Uri("https://upload.nexusmods.com");
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("NexusUploader", "1.0.1"));
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("NexusUploader", "2.0.0"));
}).ConfigurePrimaryHttpMessageHandler<NexusCookieHandler>();
}

Expand All @@ -31,6 +31,7 @@ public static IHttpClientBuilder AddNexusApiClient(this IServiceCollection servi
return services.AddHttpClient<ApiClient>(client =>
{
client.BaseAddress = new System.Uri("https://api.nexusmods.com/v1/");
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("NexusUploader", "2.0.0"));
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/NexusUploader/NexusUploader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<AssemblyName>unex</AssemblyName>
<DebugType>embedded</DebugType>
<Version>1.0.2</Version>
<Version>2.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<PackAsTool>true</PackAsTool>
Expand Down Expand Up @@ -36,4 +36,10 @@
<PackageReference Include="Spectre.Console.Extensions.Logging" Version="0.2.1" />
</ItemGroup>

<ItemGroup>
<None Update="Test.7z">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
19 changes: 6 additions & 13 deletions src/NexusUploader/Services/CookieService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@ public Dictionary<string, string> GetCookies()
var ckSet = ParseCookiesTxt(ckTxt);
return ckSet;
}
else if (_config.Cookies.StartsWith("{") || _config.Cookies.StartsWith("%7B"))
else if (_config.Cookies.Contains('\n'))
{
//almost certainly a raw sid, we'll assume it is
var raw = Uri.UnescapeDataString(_config.Cookies);
return new Dictionary<string, string> {["sid_develop"] = Uri.EscapeDataString(raw)};
var ckSet = ParseCookiesTxt(_config.Cookies.Split('\n'));
return ckSet;
}
else
{
if (_config.Cookies.Contains('\n'))
{
var ckSet = ParseCookiesTxt(_config.Cookies.Split('\n'));
return ckSet;
}
else
{
return _config.Cookies.Split(';').Select(s => s.Trim(' ')).ToDictionary(s => s.Split('=').First(), s => s.Split('=').Last());
}
//almost certainly a session id, we'll assume it is
var raw = Uri.UnescapeDataString(_config.Cookies);
return new Dictionary<string, string> {["nexusmods_session"] = Uri.EscapeDataString(raw)};
}

}
Expand Down
5 changes: 2 additions & 3 deletions src/NexusUploader/Services/ManageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public ManageClient(HttpClient httpClient, CookieService cookieService, ILogger<
public async Task<bool> CheckValidSession()
{
var uri = "/Core/Libs/Common/Managers/Mods?GetDownloadHistory";
using var req = new HttpRequestMessage(HttpMethod.Post, uri);
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
req.Headers.Add("X-Requested-With", "XMLHttpRequest");
req.Content = new StringContent("", Encoding.UTF8);
var resp = await _httpClient.SendAsync(req);
if (!resp.IsSuccessStatusCode)
{
Expand All @@ -45,7 +44,7 @@ public async Task<bool> AddChangelog(GameRef game, int modId, string version, st
message.Headers.Add("X-Requested-With", "XMLHttpRequest");
message.Headers.Add("Referer", $"https://www.nexusmods.com/{game.Name}/mods/edit/?step=docs&id={modId}");
var content = new MultipartFormDataContent();
content.Add(new StringContent(game.Id.ToString()), "game_id");
content.Add(new StringContent(game.Id), "game_id");
content.Add(new StringContent(string.Empty), "new_version[]");
content.Add(new StringContent(string.Empty), "new_change[]");
foreach (var change in changeMessage.Split('\n'))
Expand Down
Binary file added src/NexusUploader/Test.7z
Binary file not shown.

0 comments on commit dd1a324

Please sign in to comment.