diff --git a/README.md b/README.md index 14e9d1c..a6f6eb7 100644 --- a/README.md +++ b/README.md @@ -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* diff --git a/src/NexusUploader/Http/HttpClientExtensions.cs b/src/NexusUploader/Http/HttpClientExtensions.cs index 66f4989..41292d3 100644 --- a/src/NexusUploader/Http/HttpClientExtensions.cs +++ b/src/NexusUploader/Http/HttpClientExtensions.cs @@ -12,7 +12,7 @@ public static IHttpClientBuilder AddNexusClient(this ServiceCollection services) return services.AddHttpClient(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(); } @@ -22,7 +22,7 @@ public static IHttpClientBuilder AddUploadClient(this IServiceCollection service return services.AddHttpClient(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(); } @@ -31,6 +31,7 @@ public static IHttpClientBuilder AddNexusApiClient(this IServiceCollection servi return services.AddHttpClient(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")); }); } } diff --git a/src/NexusUploader/NexusUploader.csproj b/src/NexusUploader/NexusUploader.csproj index d48e543..540f0d1 100644 --- a/src/NexusUploader/NexusUploader.csproj +++ b/src/NexusUploader/NexusUploader.csproj @@ -5,7 +5,7 @@ net6.0;net7.0;net8.0 unex embedded - 1.0.2 + 2.0.0 true @@ -36,4 +36,10 @@ + + + PreserveNewest + + + diff --git a/src/NexusUploader/Services/CookieService.cs b/src/NexusUploader/Services/CookieService.cs index 9bc2cf3..7e53635 100644 --- a/src/NexusUploader/Services/CookieService.cs +++ b/src/NexusUploader/Services/CookieService.cs @@ -25,23 +25,16 @@ public Dictionary 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 {["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 {["nexusmods_session"] = Uri.EscapeDataString(raw)}; } } diff --git a/src/NexusUploader/Services/ManageClient.cs b/src/NexusUploader/Services/ManageClient.cs index 6298c8a..df46fdd 100644 --- a/src/NexusUploader/Services/ManageClient.cs +++ b/src/NexusUploader/Services/ManageClient.cs @@ -25,9 +25,8 @@ public ManageClient(HttpClient httpClient, CookieService cookieService, ILogger< public async Task 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) { @@ -45,7 +44,7 @@ public async Task 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')) diff --git a/src/NexusUploader/Test.7z b/src/NexusUploader/Test.7z new file mode 100644 index 0000000..52dacec Binary files /dev/null and b/src/NexusUploader/Test.7z differ