-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[server] add basic game submissions #164
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,3 +178,4 @@ local_server/ | |
# Drogon logs | ||
*.log | ||
/games/codenames/client/client.zip | ||
uploads/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ set -eo pipefail | |
mkdir -p "$MNT_DIR" | ||
|
||
echo "Mounting GCS Fuse." | ||
gcsfuse --debug_gcs --debug_fuse --file-mode=005 "$BUCKET" "$MNT_DIR" | ||
gcsfuse --debug_gcs --debug_fuse --file-mode=777 "$BUCKET" "$MNT_DIR" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ого! Полные разрешения всем на всё! А это точно окей? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это для Google Cloud Storage. Ему теперь придётся читать, запускать и писать (собственно загружать файлы)... Поэтому можно 007, ну либо отдельно пользователя выделять. Не хотел этим заниматься в контейнере |
||
echo "Mounting completed." | ||
|
||
# Run the web service on container startup. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "gamesubmissions_controller.h" | ||
#include "filters/AuthFilter.h" | ||
|
||
namespace cavoke::server::controllers { | ||
|
||
void GameSubmissionsController::submit_game( | ||
const drogon::HttpRequestPtr &req, | ||
std::function<void(const drogon::HttpResponsePtr &)> &&callback) { | ||
// TODO: Auth. Currently problems with authenticating the form request. | ||
// parse web form | ||
drogon::MultiPartParser mpp; | ||
int res = mpp.parse(req); | ||
if (res == -1) { | ||
return CALLBACK_STATUS_CODE(k400BadRequest); | ||
} | ||
// form files | ||
auto files = mpp.getFilesMap(); | ||
// form params | ||
nlohmann::json j = mpp.getParameters(); | ||
if (!j.contains("git_repo")) { | ||
j["git_repo"] = "<empty>"; | ||
} | ||
// serialize | ||
GameSubmissionReq req_data; | ||
try { | ||
req_data = j.get<GameSubmissionReq>(); | ||
} catch (...) { | ||
return CALLBACK_STATUS_CODE(k400BadRequest); | ||
} | ||
// validation | ||
if (req_data.package_type != "Git Repository" && | ||
req_data.package_type != "Zip Archive") { | ||
return CALLBACK_STATUS_CODE(k400BadRequest); | ||
} | ||
|
||
auto id = drogon::utils::getUuid(); | ||
auto submission = req_data.to_orm(id); | ||
if (req_data.package_type == "Zip Archive") { | ||
try { | ||
files.at("client_zip").saveAs(id + "-client.zip"); | ||
files.at("server_zip").saveAs(id + "-server.zip"); | ||
} catch (...) { | ||
return CALLBACK_STATUS_CODE(k400BadRequest); | ||
} | ||
} | ||
// save to db | ||
mp_submissions.insert(submission); | ||
|
||
LOG_INFO << "New game submission! Game: " << req_data.display_name; | ||
auto resp = newStatusCodeResponse(drogon::k200OK); | ||
resp->setBody( | ||
"Thanks for your game submission! We will review it and publish your " | ||
"game shortly."); | ||
return callback(resp); | ||
} | ||
} // namespace cavoke::server::controllers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef CAVOKE_GAMESUBMISSIONS_CONTROLLER_H | ||
#define CAVOKE_GAMESUBMISSIONS_CONTROLLER_H | ||
|
||
#include <drogon/HttpController.h> | ||
#include <nlohmann/json.hpp> | ||
#include "sql-models/Gamesubmissions.h" | ||
#include "utils.h" | ||
|
||
namespace cavoke::server::controllers { | ||
|
||
class GameSubmissionsController | ||
: public drogon::HttpController<GameSubmissionsController, true> { | ||
public: | ||
METHOD_LIST_BEGIN | ||
ADD_METHOD_TO(GameSubmissionsController::submit_game, | ||
"/submit_game", | ||
drogon::Post, | ||
drogon::Options); | ||
METHOD_LIST_END | ||
|
||
struct GameSubmissionReq { | ||
std::string game_id; | ||
std::string display_name; | ||
std::string description; | ||
std::string package_type; | ||
std::string git_repo; | ||
|
||
auto to_orm(const std::string &id) { | ||
drogon_model::cavoke_orm::Gamesubmissions res; | ||
res.setId(id); | ||
res.setGameId(game_id); | ||
res.setPackageType(package_type); | ||
res.setGitRepo(git_repo); | ||
res.setDisplayName(display_name); | ||
return res; | ||
} | ||
}; | ||
|
||
protected: | ||
void submit_game( | ||
const drogon::HttpRequestPtr &req, | ||
std::function<void(const drogon::HttpResponsePtr &)> &&callback); | ||
|
||
private: | ||
MAPPER_TYPE(drogon_model::cavoke_orm::Gamesubmissions) | ||
mp_submissions = MAPPER_FOR(drogon_model::cavoke_orm::Gamesubmissions); | ||
}; | ||
|
||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GameSubmissionsController::GameSubmissionReq, | ||
game_id, | ||
display_name, | ||
description, | ||
package_type, | ||
git_repo); | ||
|
||
} // namespace cavoke::server::controllers | ||
|
||
#endif // CAVOKE_GAMESUBMISSIONS_CONTROLLER_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
//number_of_threads: The number of IO threads, 1 by default, if the value is set to 0, the number of threads | ||
//is the number of CPU cores | ||
"number_of_threads": 1, | ||
"upload_path": "uploads", | ||
//enable_session: False by default | ||
"enable_session": false, | ||
"session_timeout": 0, | ||
|
@@ -146,7 +147,7 @@ | |
"br_static": true, | ||
//client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M". | ||
//One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit. | ||
"client_max_body_size": "1M", | ||
"client_max_body_size": "128M", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А сколько у нас в среднем QML-ка весит с серверной частью? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 40кб......... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rzhek 🤷 |
||
//max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes. | ||
//If the body size of an HTTP request exceeds this limit, the body is stored to a temporary file for processing. | ||
//Setting it to "" means no limit. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кстати, а зачем тут слеш в начале строки?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хз