mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-31 18:01:35 -04:00
feat(server): share machines, post settings, clamps and nest defaults
Schema v13 adds shared_settings and shared_setting_revisions behind /api/settings: one revision-guarded JSON document per kind and key, with every revision (deletions included) kept with who saved it. Recreating a deleted document continues its revision count. OpenNest.Data gains the client (RemoteSharedSettings), a synchronous store that keeps the last copy read for offline use and refuses writes while the server is unreachable (SharedSettingsStore), a machine provider over it, and JSON parse/serialize entry points for clamp settings and nest defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f3c22dc4f
commit
90e2fd2e6e
20 files changed
+1266
-60
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OpenNest.Data;
|
||||
|
||||
/// <summary>
|
||||
/// The machine configurations shared through the nest server, in the same JSON as
|
||||
/// <see cref="LocalJsonProvider"/>'s files. Reads come from the store's last-read copy; saves
|
||||
/// and deletes go to the server and throw <see cref="IOException"/> when it cannot take them.
|
||||
/// </summary>
|
||||
public sealed class SharedMachineProvider(SharedSettingsStore store) : IDataProvider
|
||||
{
|
||||
public IReadOnlyList<MachineSummary> GetMachines() =>
|
||||
store.List(SharedSettingKinds.Machine)
|
||||
.Select(Read)
|
||||
.OfType<MachineConfig>()
|
||||
.Select(machine => new MachineSummary(machine.Id, machine.Name))
|
||||
.ToList();
|
||||
|
||||
public MachineConfig? GetMachine(Guid id) =>
|
||||
store.Get(SharedSettingKinds.Machine, id.ToString("D")) is { } record ? Read(record) : null;
|
||||
|
||||
public void SaveMachine(MachineConfig machine) =>
|
||||
store.Save(SharedSettingKinds.Machine, machine.Id.ToString("D"), Serialize(machine));
|
||||
|
||||
public void DeleteMachine(Guid id) => store.Delete(SharedSettingKinds.Machine, id.ToString("D"));
|
||||
|
||||
/// <summary>A machine's shared document, the same JSON its local file holds.</summary>
|
||||
public static string Serialize(MachineConfig machine) => JsonSerializer.Serialize(machine, LocalJsonProvider.JsonOptions);
|
||||
|
||||
private static MachineConfig? Read(SharedSettingRecord record)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<MachineConfig>(record.Json, LocalJsonProvider.JsonOptions);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user