@@ -42,6 +42,8 @@ const std::unordered_map<std::string, std::string> mime_type_map = {
|
||||
{ ".mkv" , "video/x-matroska" },
|
||||
{ ".mk3d" , "video/x-matroska" },
|
||||
{ ".mks" , "video/x-matroska" },
|
||||
|
||||
{ ".pdf" , "application/pdf" }
|
||||
};
|
||||
|
||||
template<typename InputIt>
|
||||
@@ -170,7 +172,9 @@ namespace api {
|
||||
try {
|
||||
if (file.fileLength() > 100 * 1024 * 1024) throw std::exception();
|
||||
std::filesystem::path filename(inode->getValueOfName());
|
||||
const std::string& mime = mime_type_map.at(filename.extension().string());
|
||||
std::string ext = filename.extension().string();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
const std::string& mime = mime_type_map.at(ext);
|
||||
if (!mime.starts_with("image")) throw std::exception();
|
||||
|
||||
cv::_InputArray image_arr(file.fileData(), (int) file.fileLength());
|
||||
@@ -332,12 +336,12 @@ namespace api {
|
||||
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());
|
||||
std::filesystem::path name(inode->getValueOfName());
|
||||
std::string ext = name.extension().string();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
|
||||
try {
|
||||
cbk(dto::Responses::get_type_res(mime_type_map.at(name.extension().string())));
|
||||
cbk(dto::Responses::get_type_res(mime_type_map.at(ext)));
|
||||
} catch (const std::exception&) {
|
||||
cbk(dto::Responses::get_badreq_res("Invalid file type"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user