Changed Support to support, for consistency with other subsystems.
This commit is contained in:
1 parent
669da60852
commit
01d1753620
2 files changed
No files matched your search
@@ -0,0 +1,82 @@
|
||||
#include "ErrorReportService.h"
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
namespace bts {
|
||||
namespace support {
|
||||
|
||||
std::string get_report_dir() {
|
||||
return config::get<config::System>().data_path() + "error_reports/";
|
||||
}
|
||||
|
||||
ErrorReportServer::ErrorReportServer(bts::api::ServiceContext& context) :
|
||||
ErrorReportServiceBase(context) {
|
||||
// create directory
|
||||
auto report_dir = get_report_dir();
|
||||
if (!boost::filesystem::exists(report_dir)) {
|
||||
boost::filesystem::create_directories(report_dir);
|
||||
}
|
||||
}
|
||||
|
||||
ErrorReportServer::~ErrorReportServer() {}
|
||||
|
||||
void ErrorReportServer::send_report(
|
||||
const ErrorReport& request,
|
||||
const api::Response<ErrorResponse>& reply) {
|
||||
|
||||
// generate unique id using date
|
||||
auto dt = datetime::local_now();
|
||||
auto dir_name = request.user() + "-" + datetime::FIX_timestamp(dt);
|
||||
dir_name = os::sanitize_file_name(dir_name);
|
||||
dir_name = get_report_dir() + dir_name;
|
||||
|
||||
// create directory with that name
|
||||
boost::filesystem::create_directories(dir_name);
|
||||
|
||||
// Write data to files in that directory
|
||||
|
||||
// user_text.txt
|
||||
std::ofstream file;
|
||||
file.open(dir_name + "/user_text.txt");
|
||||
if (file.is_open()) {
|
||||
file << request.user() << " - " << request.contact() << std::endl;
|
||||
file << "================" << std::endl;
|
||||
file << "Error Description: " << request.error_message() << std::endl;
|
||||
file << "================" << std::endl;
|
||||
file << "User Description: " << request.user_description() << std::endl;
|
||||
file.close();
|
||||
}
|
||||
// logs.txt
|
||||
if (request.log().size() > 0) {
|
||||
file.open(dir_name + "/logs.txt");
|
||||
if (file.is_open()) {
|
||||
file << request.log();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
// screenshot.jpeg
|
||||
if (request.image().size() > 0) {
|
||||
file.open(dir_name + "/screenshot.jpeg", std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
file << request.image();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
// log error for visibility
|
||||
LOG(Gen, Error, "Support request from {} - {} \n{}", request.user(), request.contact(), request.user_description());
|
||||
|
||||
ErrorResponse r;
|
||||
reply(r);
|
||||
}
|
||||
|
||||
}}
|
||||
Reference in new issue
Block a user