add function map viewer
Some checks failed
Test / test (push) Has been cancelled

This commit is contained in:
2026-06-20 10:53:49 +07:00
parent a6cf06d7eb
commit 819323f8c8
22 changed files with 3332 additions and 67 deletions

View File

@@ -307,6 +307,17 @@ std::optional<std::filesystem::path> MapStore::imagePath(const std::string& id)
return path;
}
std::optional<std::filesystem::path> MapStore::yamlPath(const std::string& id) const
{
const auto map = find(id);
if (!map || !(*map)["yaml_file"].is_string())
return std::nullopt;
const auto path = mapDir(id) / map->value("yaml_file", "");
if (!std::filesystem::exists(path))
return std::nullopt;
return path;
}
bool MapStore::saveImageFile(const std::string& id,
const std::string& filename,
const std::string& bytes,
@@ -349,4 +360,44 @@ bool MapStore::saveImageFile(const std::string& id,
return ok;
}
bool MapStore::saveYamlFile(const std::string& id, const std::string& yaml_text, std::string& err)
{
if (!find(id))
{
err = "map not found";
return false;
}
constexpr const char* kYamlName = "map.yaml";
std::error_code ec;
std::filesystem::create_directories(mapDir(id), ec);
const auto path = mapDir(id) / kYamlName;
if (!FileUtil::writeBinaryAtomic(path, yaml_text))
{
err = "failed to write yaml file";
return false;
}
const std::string now = IdUtil::nowIso8601();
std::lock_guard<std::mutex> lock(mu_);
sqlite3_stmt* stmt = nullptr;
if (sqlite3_prepare_v2(db_.handle(),
"UPDATE maps SET yaml_file = ?2, updated_at = ?3 WHERE id = ?1",
-1,
&stmt,
nullptr) != SQLITE_OK)
{
err = sqlite3_errmsg(db_.handle());
return false;
}
sqlite3_bind_text(stmt, 1, id.c_str(), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, kYamlName, -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, now.c_str(), -1, SQLITE_TRANSIENT);
const bool ok = sqlite3_step(stmt) == SQLITE_DONE;
if (!ok)
err = sqlite3_errmsg(db_.handle());
sqlite3_finalize(stmt);
return ok;
}
} // namespace lm