Replaced base64 loading of images with blob, small fixes

This commit is contained in:
2022-09-04 00:11:11 +02:00
parent 95f921554b
commit d4ac3db189
7 changed files with 23 additions and 54 deletions

View File

@@ -57,7 +57,7 @@ namespace api {
std::string code = create_totp_qrcode(user, b32_secret);
cbk(dto::Responses::get_tfa_setup_res(b32_secret, code));
}
} catch (const std::exception& e) {
} catch (const std::exception&) {
cbk(dto::Responses::get_badreq_res("Validation error"));
}
}

View File

@@ -90,7 +90,6 @@ public:
METHOD_ADD(fs::download, "/download", drogon::Post, "Login");
METHOD_ADD(fs::download_multi, "/download_multi", drogon::Post, "Login");
METHOD_ADD(fs::download_preview, "/download_preview/{}", drogon::Get, "Login");
METHOD_ADD(fs::download_base64, "/download_base64/{}", drogon::Get, "Login");
METHOD_ADD(fs::get_type, "/get_type/{}", drogon::Get, "Login");
METHOD_LIST_END
@@ -124,7 +123,6 @@ public:
void download(req_type, cbk_type);
void download_multi(req_type, cbk_type);
void download_preview(req_type, cbk_type, uint64_t node);
void download_base64(req_type, cbk_type, uint64_t node);
void get_type(req_type, cbk_type, uint64_t node);
};

View File

@@ -554,28 +554,6 @@ namespace api {
cbk(dto::Responses::get_download_base64_res("data:image/png;base64," + Botan::base64_encode(image)));
}
void fs::download_base64(req_type req, cbk_type cbk, uint64_t node) {
db::User user = dto::get_user(req);
auto inode = get_node_and_validate(user, node);
if (!inode.has_value())
return cbk(dto::Responses::get_badreq_res("Unknown node"));
std::filesystem::path p("./files"), name(inode->getValueOfName());
p /= std::to_string(inode->getValueOfId());
try {
std::string mime = mime_type_map.at(name.extension().string());
std::ifstream file(p, std::ios::in | std::ios::binary);
std::vector<uint8_t> content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
cbk(dto::Responses::get_download_base64_res("data:" + mime + ";base64," + Botan::base64_encode(content)));
} catch (const std::exception&) {
cbk(dto::Responses::get_badreq_res("Invalid file type"));
}
}
void fs::get_type(req_type req, cbk_type cbk, uint64_t node){
db::User user = dto::get_user(req);

View File

@@ -22,9 +22,9 @@ namespace dto {
namespace Responses {
struct GetUsersEntry {
GetUsersEntry(int id, bool gitlab, bool tfa, std::string name, db::UserRole role)
GetUsersEntry(uint64_t id, bool gitlab, bool tfa, std::string name, db::UserRole role)
: id(id), gitlab(gitlab), tfa(tfa), name(std::move(name)), role(role) {}
int id;
uint64_t id;
bool gitlab, tfa;
std::string name;
db::UserRole role;