Fixed issue with B2 API calls

This commit is contained in:
Kenneth Skovhede
2025-12-16 21:23:24 +01:00
parent 734c761395
commit da32b8cbcb
2 changed files with 26 additions and 6 deletions
+7 -4
View File
@@ -465,7 +465,7 @@ public class B2 : IStreamingBackend, ILockingBackend
).ConfigureAwait(false)
).ConfigureAwait(false);
if (response?.FileRetention?.RetainUntilTimestamp is long timestamp && timestamp > 0)
if (response?.FileRetention?.Value?.RetainUntilTimestamp is long timestamp && timestamp > 0)
return Utility.Utility.EPOCH.AddMilliseconds(timestamp);
return null;
@@ -631,14 +631,14 @@ public class B2 : IStreamingBackend, ILockingBackend
var fileId = await GetFileId(remotename, cancellationToken).ConfigureAwait(false);
var config = await _b2AuthHelper.GetConfigAsync(cancellationToken).ConfigureAwait(false);
await Utility.Utility.WithTimeout(_timeouts.ShortTimeout, cancellationToken, async ct
=> await _b2AuthHelper.PostAndGetJsonDataAsync<GetFileInfoResponse>(
var res = await Utility.Utility.WithTimeout(_timeouts.ShortTimeout, cancellationToken, async ct
=> await _b2AuthHelper.PostAndGetJsonDataAsync<UpdateFileRetentionResponse>(
$"{config.APIUrl}/b2api/v2/b2_update_file_retention",
new UpdateFileRetentionRequest
{
FileId = fileId,
FileName = _prefix + remotename,
Retention = new FileRetention
FileRetention = new FileRetention
{
Mode = _lockMode.ToString().ToLower(),
RetainUntilTimestamp = (long)(lockUntilUtc.ToUniversalTime() - Utility.Utility.EPOCH).TotalMilliseconds
@@ -648,6 +648,9 @@ public class B2 : IStreamingBackend, ILockingBackend
ct
).ConfigureAwait(false)
).ConfigureAwait(false);
if (res.FileRetention?.RetainUntilTimestamp == null)
throw new Exception("Failed to set object lock, call succeeded but no retention info returned");
}
/// <summary>
@@ -32,6 +32,16 @@ internal class FileRetention
public long? RetainUntilTimestamp { get; set; }
}
internal class FileRetentionAccess
{
[JsonProperty("isClientAuthorizedToRead")]
public bool isClientAuthorizedToRead { get; set; }
[JsonProperty("value")]
public FileRetention? Value { get; set; }
}
internal class GetFileInfoRequest
{
[JsonProperty("fileId")]
@@ -39,11 +49,18 @@ internal class GetFileInfoRequest
}
internal class GetFileInfoResponse
{
[JsonProperty("fileRetention")]
public FileRetentionAccess? FileRetention { get; set; }
}
internal class UpdateFileRetentionResponse
{
[JsonProperty("fileRetention")]
public FileRetention? FileRetention { get; set; }
}
internal class UpdateFileRetentionRequest
{
[JsonProperty("fileId")]
@@ -52,8 +69,8 @@ internal class UpdateFileRetentionRequest
[JsonProperty("fileName")]
public string? FileName { get; set; }
[JsonProperty("retention")]
public FileRetention? Retention { get; set; }
[JsonProperty("fileRetention")]
public FileRetention? FileRetention { get; set; }
[JsonProperty("bypassGovernance")]
public bool BypassGovernance { get; set; }