diff --git a/Tools/AutoClient/AutomaticPurchaser.cs b/Tools/AutoClient/AutomaticPurchaser.cs index 9c0c18d..1e21716 100644 --- a/Tools/AutoClient/AutomaticPurchaser.cs +++ b/Tools/AutoClient/AutomaticPurchaser.cs @@ -70,7 +70,8 @@ namespace AutoClient try { var cid = await codex.UploadFile(file); - return await codex.RequestStorage(cid); + var response = await codex.RequestStorage(cid); + return response.PurchaseId; } finally { diff --git a/Tools/AutoClient/CodexInstance.cs b/Tools/AutoClient/CodexInstance.cs index e240b74..5399b2b 100644 --- a/Tools/AutoClient/CodexInstance.cs +++ b/Tools/AutoClient/CodexInstance.cs @@ -82,7 +82,7 @@ namespace AutoClient } } - public async Task RequestStorage(ContentId cid) + public async Task RequestStorage(ContentId cid) { app.Log.Debug("Requesting storage for " + cid.Id); var result = await codex.Codex.CreateStorageRequestAsync(cid.Id, new StorageRequestCreation() @@ -101,7 +101,24 @@ namespace AutoClient var encoded = await GetEncodedCid(result); app.CidRepo.AddEncoded(cid.Id, encoded); - return result; + return new RequestStorageResult(result, new ContentId(encoded)); + } + + public class RequestStorageResult + { + public RequestStorageResult(string purchaseId, ContentId encodedCid) + { + PurchaseId = purchaseId; + EncodedCid = encodedCid; + } + + public string PurchaseId { get; } + public ContentId EncodedCid { get; } + + public override string ToString() + { + return $"{PurchaseId} (cid: {EncodedCid})"; + } } public async Task GetStoragePurchase(string pid) diff --git a/Tools/AutoClient/Modes/FolderStore/FileWorker.cs b/Tools/AutoClient/Modes/FolderStore/FileWorker.cs index 6118f8d..063602f 100644 --- a/Tools/AutoClient/Modes/FolderStore/FileWorker.cs +++ b/Tools/AutoClient/Modes/FolderStore/FileWorker.cs @@ -186,25 +186,26 @@ namespace AutoClient.Modes.FolderStore Log($"Creating new purchase..."); var response = await codex.RequestStorage(new CodexPlugin.ContentId(State.Cid)); - if (string.IsNullOrEmpty(response) || - response == "Unable to encode manifest" || - response == "Purchasing not available" || - response == "Expiry required" || - response == "Expiry needs to be in future" || - response == "Expiry has to be before the request's end (now + duration)") + var purchaseId = response.PurchaseId; + if (string.IsNullOrEmpty(purchaseId) || + purchaseId == "Unable to encode manifest" || + purchaseId == "Purchasing not available" || + purchaseId == "Expiry required" || + purchaseId == "Expiry needs to be in future" || + purchaseId == "Expiry has to be before the request's end (now + duration)") { - throw new InvalidOperationException(response); + throw new InvalidOperationException(purchaseId); } var newPurchase = new WorkerPurchase { Created = DateTime.UtcNow, - Pid = response + Pid = purchaseId }; State.Purchases = State.Purchases.Concat([newPurchase]).ToArray(); SaveState(); - Log($"New purchase created. PID: '{response}'. Waiting for submit..."); + Log($"New purchase created. PID: '{purchaseId}'. Waiting for submit..."); Thread.Sleep(500); onNewPurchase(); diff --git a/Tools/AutoClient/Modes/FolderStore/FolderWorkOverview.cs b/Tools/AutoClient/Modes/FolderStore/FolderWorkOverview.cs index 66a50d2..2489c79 100644 --- a/Tools/AutoClient/Modes/FolderStore/FolderWorkOverview.cs +++ b/Tools/AutoClient/Modes/FolderStore/FolderWorkOverview.cs @@ -66,6 +66,9 @@ namespace AutoClient.Modes.FolderStore Log("Requesting storage for it..."); var result = await codex.RequestStorage(cid); Log("Storage requested. Purchase ID: " + result); + + var outFile = Path.Combine(app.Config.DataPath, "OverviewZip.cid"); + File.WriteAllLines(outFile, [DateTime.UtcNow.ToString("o") + " - " + result.EncodedCid.Id]); } catch (Exception exc) {