2 #ifndef NAF_FUNCTIONS_FUNCTION
3 #define NAF_FUNCTIONS_FUNCTION
12 #include "files/file_manager.h"
13 #include "functions/action.h"
14 #include "http/methods.h"
15 #include "query/parameter.h"
16 #include "http/request.h"
17 #include "http/common_responses.h"
18 #include "security/user.h"
19 #include "security/users_manager.h"
34 using Ptr = std::shared_ptr<Functions::Function>;
36 enum class ResponseType
44 Function(std::string endpoint, HTTP::EnumMethods method, ResponseType response_type = ResponseType::kJSON);
46 std::string get_endpoint()
const {
return endpoint_; }
47 std::string get_target()
const {
return target_; }
48 bool get_error()
const {
return error_; }
49 std::string get_error_message()
const {
return error_message_; }
50 bool get_remove_file_on_modify()
const {
return remove_file_on_modify_; }
51 ResponseType get_response_type()
const {
return response_type_; }
52 HTTP::EnumMethods get_method()
const {
return method_; }
55 auto& var = current_user_;
58 std::vector<Action::Ptr>& get_actions()
68 Files::FileManager::Ptr& get_file_manager()
70 auto& var = file_manager_;
74 void set_endpoint(std::string endpoint) { endpoint_ = endpoint; }
75 void set_target(std::string target) { target_ = target; }
76 void set_remove_file_on_modify(
bool remove_file_on_modify) { remove_file_on_modify_ = remove_file_on_modify; }
77 void set_method(HTTP::EnumMethods type) { method_ = type; }
78 void set_response_type(ResponseType response_type) { response_type_ = response_type; }
80 Action::Ptr AddAction_(std::string identifier);
81 void Process_(HTTP::Request::HTTPServerRequestPtr request, HTTP::Request::HTTPServerResponsePtr response);
82 bool ProcessAction_(Action::Ptr action);
83 bool ProcessJSON_(JSON::Object::Ptr& json_result);
84 bool ProcessFile_(std::string& filepath);
85 void DownloadProcess_(std::string& filepath);
86 void UploadProcess_();
87 void ModifyProcess_(std::string& filepath);
88 void RemoveProcess_(std::string& filepath);
89 void SetupCustomProcess_(std::function<
void(
Function&)> custom_process);
92 void Setup_(HTTP::Request::HTTPServerRequestPtr request, HTTP::Request::HTTPServerResponsePtr response);
95 std::string endpoint_;
98 std::string error_message_;
99 bool remove_file_on_modify_;
100 ResponseType response_type_;
101 HTTP::EnumMethods method_;
103 std::vector<Action::Ptr> actions_;
105 Files::FileManager::Ptr file_manager_;
106 std::function<void(
Function&)> custom_process_;
Definition: function.h:32
Definition: common_responses.h:69