1 /* 2 * Copyright (c) 2023 Unionman Technology Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CONTROLLERS_DOWNLOAD_H 17 #define CONTROLLERS_DOWNLOAD_H 18 19 20 #include <drogon/HttpController.h> 21 #include <json/json.h> 22 #include <string> 23 #include "../dto/info.h" 24 class Download : public drogon::HttpController<Download> { 25 public: 26 void getFile(const drogon::HttpRequestPtr& req, std::function<void(const drogon::HttpResponsePtr&)>&& callback, 27 const std::string& filename); 28 void uploadFile(const drogon::HttpRequestPtr& req, std::function<void(const drogon::HttpResponsePtr&)>&& callback); 29 30 Json::Value readJsonFromFile(const std::string& path); 31 void saveJsonToFile(const std::string& path, const Json::Value json); 32 bool addInfoJsonFile(const std::string& path, const Info& info); 33 34 std::string getFileSha256(const std::string& path); 35 36 METHOD_LIST_BEGIN 37 ADD_METHOD_TO(Download::getFile, "/api/download/{filename}", drogon::Get); 38 ADD_METHOD_TO(Download::uploadFile, "/api/upload", drogon::Post); 39 METHOD_LIST_END 40 }; 41 #endif 42