MCPcopy Create free account
hub / github.com/chrxh/alien / uploadResource

Method uploadResource

source/Network/NetworkService.cpp:434–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432}
433
434bool NetworkService::uploadResource(
435 std::string& resourceId,
436 std::string const& resourceName,
437 std::string const& description,
438 IntVector2D const& worldSize,
439 int numParticles,
440 std::string const& mainData,
441 std::string const& settings,
442 std::string const& statistics,
443 NetworkResourceType resourceType,
444 WorkspaceType workspaceType)
445{
446 log(Priority::Important, "network: upload resource with name='" + resourceName + "'");
447
448 std::vector<std::string> chunks;
449
450 for (size_t i = 0; i < mainData.length(); i += MaxChunkSize) {
451 std::string chunk = mainData.substr(i, MaxChunkSize);
452 chunks.emplace_back(chunk);
453 }
454
455 httplib::SSLClient client(_serverAddress);
456 configureClient(client);
457
458 httplib::MultipartFormDataItems items = {
459 {"userName", *_loggedInUserName, "", ""},
460 {"password", *_password, "", ""},
461 {"simName", resourceName, "", ""},
462 {"simDesc", description, "", ""},
463 {"width", std::to_string(worldSize.x), "", ""},
464 {"height", std::to_string(worldSize.y), "", ""},
465 {"particles", std::to_string(numParticles), "", ""},
466 {"version", Const::ProgramVersion, "", ""},
467 {"content", chunks.front(), "", "application/octet-stream"},
468 {"settings", settings, "", ""},
469 {"symbolMap", "", "", ""},
470 {"type", std::to_string(resourceType), "", ""},
471 {"workspace", std::to_string(workspaceType), "", ""},
472 {"statistics", statistics, "", ""},
473 };
474
475 try {
476 auto result = executeRequest([&] { return client.Post("/alien-server/uploadsimulation.php", items); });
477 if (parseBoolResult(result->body)) {
478 resourceId = parseValueFromKey<std::string>(result->body, "simId");
479 } else {
480 return false;
481 }
482 } catch (...) {
483 logNetworkError();
484 return false;
485 }
486
487 int index = 1;
488 for (auto const& chunk : chunks | std::views::drop(1)) {
489 if (!appendResourceData(resourceId, chunk, toInt(index))) {
490 deleteResource(resourceId);
491 return false;

Callers 1

processRequestMethod · 0.80

Calls 10

logFunction · 0.85
configureClientFunction · 0.85
to_stringFunction · 0.85
executeRequestFunction · 0.85
parseBoolResultFunction · 0.85
logNetworkErrorFunction · 0.85
toIntFunction · 0.85
lengthMethod · 0.80
PostMethod · 0.80
insertOrAssignMethod · 0.80

Tested by

no test coverage detected