writes overview CID to file

This commit is contained in:
benbierens 2024-11-27 08:48:12 +01:00
parent f18ff24bb6
commit e91a574b2c
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 34 additions and 12 deletions

View File

@ -70,7 +70,8 @@ namespace AutoClient
try try
{ {
var cid = await codex.UploadFile(file); var cid = await codex.UploadFile(file);
return await codex.RequestStorage(cid); var response = await codex.RequestStorage(cid);
return response.PurchaseId;
} }
finally finally
{ {

View File

@ -82,7 +82,7 @@ namespace AutoClient
} }
} }
public async Task<string> RequestStorage(ContentId cid) public async Task<RequestStorageResult> RequestStorage(ContentId cid)
{ {
app.Log.Debug("Requesting storage for " + cid.Id); app.Log.Debug("Requesting storage for " + cid.Id);
var result = await codex.Codex.CreateStorageRequestAsync(cid.Id, new StorageRequestCreation() var result = await codex.Codex.CreateStorageRequestAsync(cid.Id, new StorageRequestCreation()
@ -101,7 +101,24 @@ namespace AutoClient
var encoded = await GetEncodedCid(result); var encoded = await GetEncodedCid(result);
app.CidRepo.AddEncoded(cid.Id, encoded); 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<StoragePurchase?> GetStoragePurchase(string pid) public async Task<StoragePurchase?> GetStoragePurchase(string pid)

View File

@ -186,25 +186,26 @@ namespace AutoClient.Modes.FolderStore
Log($"Creating new purchase..."); Log($"Creating new purchase...");
var response = await codex.RequestStorage(new CodexPlugin.ContentId(State.Cid)); var response = await codex.RequestStorage(new CodexPlugin.ContentId(State.Cid));
if (string.IsNullOrEmpty(response) || var purchaseId = response.PurchaseId;
response == "Unable to encode manifest" || if (string.IsNullOrEmpty(purchaseId) ||
response == "Purchasing not available" || purchaseId == "Unable to encode manifest" ||
response == "Expiry required" || purchaseId == "Purchasing not available" ||
response == "Expiry needs to be in future" || purchaseId == "Expiry required" ||
response == "Expiry has to be before the request's end (now + duration)") 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 var newPurchase = new WorkerPurchase
{ {
Created = DateTime.UtcNow, Created = DateTime.UtcNow,
Pid = response Pid = purchaseId
}; };
State.Purchases = State.Purchases.Concat([newPurchase]).ToArray(); State.Purchases = State.Purchases.Concat([newPurchase]).ToArray();
SaveState(); SaveState();
Log($"New purchase created. PID: '{response}'. Waiting for submit..."); Log($"New purchase created. PID: '{purchaseId}'. Waiting for submit...");
Thread.Sleep(500); Thread.Sleep(500);
onNewPurchase(); onNewPurchase();

View File

@ -66,6 +66,9 @@ namespace AutoClient.Modes.FolderStore
Log("Requesting storage for it..."); Log("Requesting storage for it...");
var result = await codex.RequestStorage(cid); var result = await codex.RequestStorage(cid);
Log("Storage requested. Purchase ID: " + result); 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) catch (Exception exc)
{ {