|
|
@@ -4483,25 +4483,31 @@ void Server::handleLoadModelById(const httplib::Request& req, httplib::Response&
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Extract model ID from URL path (could be hash or name)
|
|
|
+ // Extract model hash from URL path (must be a hash)
|
|
|
std::string modelIdentifier = req.matches[1].str();
|
|
|
if (modelIdentifier.empty()) {
|
|
|
sendErrorResponse(res, "Missing model identifier", 400, "MISSING_MODEL_ID", requestId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Try to find by hash first (if it looks like a hash - 10+ hex chars)
|
|
|
- std::string modelId = modelIdentifier;
|
|
|
- if (modelIdentifier.length() >= 10 &&
|
|
|
- std::all_of(modelIdentifier.begin(), modelIdentifier.end(),
|
|
|
+ // Validate that the identifier is a hash (10+ hexadecimal characters)
|
|
|
+ if (modelIdentifier.length() < 10 ||
|
|
|
+ !std::all_of(modelIdentifier.begin(), modelIdentifier.end(),
|
|
|
[](char c) { return std::isxdigit(c); })) {
|
|
|
- std::string foundName = m_modelManager->findModelByHash(modelIdentifier);
|
|
|
- if (!foundName.empty()) {
|
|
|
- modelId = foundName;
|
|
|
- LOG_DEBUG("Resolved hash " + modelIdentifier + " to model: " + modelId);
|
|
|
- }
|
|
|
+ sendErrorResponse(res, "Invalid model identifier: must be a hash (10+ hexadecimal characters)", 400, "INVALID_MODEL_IDENTIFIER", requestId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Find model by hash
|
|
|
+ std::string foundName = m_modelManager->findModelByHash(modelIdentifier);
|
|
|
+ if (foundName.empty()) {
|
|
|
+ sendErrorResponse(res, "Model not found for hash: " + modelIdentifier, 404, "MODEL_NOT_FOUND", requestId);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ std::string modelId = foundName;
|
|
|
+ LOG_DEBUG("Resolved hash " + modelIdentifier + " to model: " + modelId);
|
|
|
+
|
|
|
// Parse optional parameters from request body
|
|
|
nlohmann::json requestJson;
|
|
|
if (!req.body.empty()) {
|