Simplify file size error creation.
This commit is contained in:
parent
a282cce5d4
commit
b4a643cffd
@ -995,23 +995,24 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64
|
|||||||
if (skip_file_size_checks) {
|
if (skip_file_size_checks) {
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto get_file_size_error = [&](Slice reason) {
|
||||||
|
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size
|
||||||
|
<< " bytes is too big" << reason);
|
||||||
|
};
|
||||||
if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) &&
|
if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) &&
|
||||||
size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map")) {
|
size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map")) {
|
||||||
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size
|
return get_file_size_error(" for a thumbnail");
|
||||||
<< " is too big for a thumbnail");
|
|
||||||
}
|
}
|
||||||
if (size > MAX_FILE_SIZE) {
|
if (size > MAX_FILE_SIZE) {
|
||||||
return Status::Error(
|
return get_file_size_error("");
|
||||||
400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size << " bytes is too big");
|
|
||||||
}
|
}
|
||||||
if (location.file_type_ == FileType::Photo && size > MAX_PHOTO_SIZE) {
|
if (location.file_type_ == FileType::Photo && size > MAX_PHOTO_SIZE) {
|
||||||
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size
|
return get_file_size_error(" for a photo");
|
||||||
<< " bytes is too big for a photo");
|
|
||||||
}
|
}
|
||||||
if (location.file_type_ == FileType::VideoNote &&
|
if (location.file_type_ == FileType::VideoNote &&
|
||||||
size > G()->shared_config().get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) {
|
size > G()->shared_config().get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) {
|
||||||
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size
|
return get_file_size_error(" for a video note");
|
||||||
<< " bytes is too big for a video note");
|
|
||||||
}
|
}
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user