diff --git a/README.md b/README.md index 1171cd8..94f5c92 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ ARGUMENTS: OPTIONS: -h, --help Prints help information + -s, --session-cookie Value of the 'nexusmods_session' cookie. Can be a file path or the raw cookie value. Available Environment Variable: UNEX_SESSION_COOKIE -k, --api-key The NexusMods API key. Available Environment Variable: UNEX_APIKEY -g, --game The NexusMods game name (domain) to upload the mod to. Can be found in the URL of the game page. Available Environment Variable: UNEX_GAME -f, --file-name Name for the file on NexusMods. Available Environment Variable: UNEX_FILENAME diff --git a/src/BUTR.NexusUploader/BUTR.NexusUploader.csproj b/src/BUTR.NexusUploader/BUTR.NexusUploader.csproj index 786feae..2702b4a 100644 --- a/src/BUTR.NexusUploader/BUTR.NexusUploader.csproj +++ b/src/BUTR.NexusUploader/BUTR.NexusUploader.csproj @@ -4,7 +4,7 @@ Exe net6.0;net7.0;net8.0 embedded - 3.0.3 + 3.0.4 12 enable diff --git a/src/BUTR.NexusUploader/Commands/UploadCommand.cs b/src/BUTR.NexusUploader/Commands/UploadCommand.cs index 61fd081..2dc43c7 100644 --- a/src/BUTR.NexusUploader/Commands/UploadCommand.cs +++ b/src/BUTR.NexusUploader/Commands/UploadCommand.cs @@ -22,13 +22,15 @@ namespace BUTR.NexusUploader.Commands; public class UploadCommand : AsyncCommand { private readonly ILogger _logger; + private readonly CookieService _cookieService; private readonly ManageClient _manager; private readonly ApiV1Client _apiV1Client; private readonly UploadClient _uploader; - public UploadCommand(ILogger logger, ManageClient client, ApiV1Client apiV1Client, UploadClient uploader) + public UploadCommand(ILogger logger, CookieService cookieService, ManageClient client, ApiV1Client apiV1Client, UploadClient uploader) { _logger = logger; + _cookieService = cookieService; _manager = client; _apiV1Client = apiV1Client; _uploader = uploader; @@ -36,6 +38,8 @@ public UploadCommand(ILogger logger, ManageClient client, ApiV1Cl public override async Task ExecuteAsync(CommandContext context, Settings settings) { + _cookieService.SetSessionCookie(settings.SessionCookie); + var fileOpts = new FileOptions(settings.FileName, settings.FileVersion) { Description = settings.FileDescription @@ -131,6 +135,11 @@ public class Settings : CommandSettings [Description("Path to the mod archive file to upload.")] public string ModFilePath { get; set; } = string.Empty; + [CommandOption("-s|--session-cookie ")] + [EnvironmentVariable("SESSION_COOKIE")] + [Description("Value of the 'nexusmods_session' cookie. Can be a file path or the raw cookie value. Available Environment Variable: UNEX_SESSION_COOKIE")] + public string SessionCookie { get; set; } = string.Empty; + [CommandOption("-k|--api-key")] [EnvironmentVariable("APIKEY")] [Description("The NexusMods API key. Available Environment Variable: UNEX_APIKEY")] diff --git a/src/BUTR.NexusUploader/Services/UploadClient.cs b/src/BUTR.NexusUploader/Services/UploadClient.cs index d38c30d..6374cc9 100644 --- a/src/BUTR.NexusUploader/Services/UploadClient.cs +++ b/src/BUTR.NexusUploader/Services/UploadClient.cs @@ -90,7 +90,7 @@ string GetIdentifier() resumableTotalChunks = totalChunks }); var getResp = await _httpClient.GetAsync(path.ToString()); - if (getResp.StatusCode != HttpStatusCode.NoContent) + if (getResp.StatusCode is not HttpStatusCode.OK and not HttpStatusCode.NoContent) { throw new Exception("I don't even know what this means"); }