mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 22:01:07 -04:00
fix(server): reject duplicate nest ids, invalid metadata and bare --database
- POST /api/nests with an existing id (active or deleted) now returns 409 with the current record instead of a 500 from the UNIQUE constraint. - Uploaded nest metadata must have string text fields and a defined status; null fields and undefined statuses (e.g. 99) are 400 instead of a 500 or a stored invalid value. - --database <path> is accepted alongside --database=<path>; a missing or repeated path fails startup instead of silently using OPENNEST_DB/default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a7073d38c
commit
5dff83cfb8
7 files changed
+309
-37
No files matched your search
@@ -0,0 +1,43 @@
|
||||
namespace OpenNest.Server;
|
||||
|
||||
/// <summary>Startup settings read from the command line and environment.</summary>
|
||||
public static class ServerOptions
|
||||
{
|
||||
public const string DatabaseVariable = "OPENNEST_DB";
|
||||
|
||||
/// <summary>
|
||||
/// The database path: <c>--database=<path></c> or <c>--database <path></c>, then
|
||||
/// <c>OPENNEST_DB</c>, then <c>./data/nests.db</c>. A <c>--database</c> without a path,
|
||||
/// or given twice, fails startup instead of silently storing nests elsewhere.
|
||||
/// </summary>
|
||||
public static string DatabasePath(IReadOnlyList<string> args, string? environmentPath)
|
||||
{
|
||||
string? path = null;
|
||||
for (var i = 0; i < args.Count; i++)
|
||||
{
|
||||
string value;
|
||||
if (args[i] == "--database")
|
||||
{
|
||||
if (i + 1 >= args.Count || args[i + 1].StartsWith("--", StringComparison.Ordinal))
|
||||
throw new ArgumentException("--database requires a path.", nameof(args));
|
||||
value = args[++i];
|
||||
}
|
||||
else if (args[i].StartsWith("--database=", StringComparison.Ordinal))
|
||||
{
|
||||
value = args[i]["--database=".Length..];
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw new ArgumentException("--database requires a path.", nameof(args));
|
||||
if (path is not null)
|
||||
throw new ArgumentException("--database was given more than once.", nameof(args));
|
||||
path = value;
|
||||
}
|
||||
|
||||
return path ?? environmentPath ?? Path.Combine("data", "nests.db");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user