Skip to content

Commit

Permalink
Fixed upload, it was missing the session cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed May 28, 2024
1 parent 1ee4ad5 commit 834e1d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ ARGUMENTS:
OPTIONS:
-h, --help Prints help information
-s, --session-cookie <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
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.NexusUploader/BUTR.NexusUploader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<DebugType>embedded</DebugType>
<Version>3.0.3</Version>
<Version>3.0.4</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>

Expand Down
11 changes: 10 additions & 1 deletion src/BUTR.NexusUploader/Commands/UploadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ namespace BUTR.NexusUploader.Commands;
public class UploadCommand : AsyncCommand<UploadCommand.Settings>
{
private readonly ILogger _logger;
private readonly CookieService _cookieService;
private readonly ManageClient _manager;
private readonly ApiV1Client _apiV1Client;
private readonly UploadClient _uploader;

public UploadCommand(ILogger<UploadCommand> logger, ManageClient client, ApiV1Client apiV1Client, UploadClient uploader)
public UploadCommand(ILogger<UploadCommand> logger, CookieService cookieService, ManageClient client, ApiV1Client apiV1Client, UploadClient uploader)
{
_logger = logger;
_cookieService = cookieService;
_manager = client;
_apiV1Client = apiV1Client;
_uploader = uploader;
}

public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
_cookieService.SetSessionCookie(settings.SessionCookie);

var fileOpts = new FileOptions(settings.FileName, settings.FileVersion)
{
Description = settings.FileDescription
Expand Down Expand Up @@ -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 <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")]
Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.NexusUploader/Services/UploadClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 834e1d7

Please sign in to comment.