Clarify some constants
This commit is contained in:
@@ -27,14 +27,14 @@ pub const ALLOWED_ISO_MIME_TYPES: [&str; 4] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/// ISO max size
|
/// ISO max size
|
||||||
pub const ISO_MAX_SIZE: usize = 10 * 1000 * 1000 * 1000;
|
pub const ISO_MAX_SIZE: FileSize = FileSize::from_gb(10);
|
||||||
|
|
||||||
/// Allowed uploaded disk images formats
|
/// Allowed uploaded disk images formats
|
||||||
pub const ALLOWED_DISK_IMAGES_MIME_TYPES: [&str; 2] =
|
pub const ALLOWED_DISK_IMAGES_MIME_TYPES: [&str; 2] =
|
||||||
["application/x-qemu-disk", "application/gzip"];
|
["application/x-qemu-disk", "application/gzip"];
|
||||||
|
|
||||||
/// Disk image max size
|
/// Disk image max size
|
||||||
pub const DISK_IMAGE_MAX_SIZE: usize = 10 * 1000 * 1000 * 1000 * 1000;
|
pub const DISK_IMAGE_MAX_SIZE: FileSize = FileSize::from_gb(10 * 1000);
|
||||||
|
|
||||||
/// Min VM memory size (MB)
|
/// Min VM memory size (MB)
|
||||||
pub const MIN_VM_MEMORY: usize = 100;
|
pub const MIN_VM_MEMORY: usize = 100;
|
||||||
|
@@ -24,7 +24,7 @@ pub async fn upload(MultipartForm(mut form): MultipartForm<UploadDiskImageForm>)
|
|||||||
let file = form.files.remove(0);
|
let file = form.files.remove(0);
|
||||||
|
|
||||||
// Check uploaded file size
|
// Check uploaded file size
|
||||||
if file.size > constants::DISK_IMAGE_MAX_SIZE {
|
if file.size > constants::DISK_IMAGE_MAX_SIZE.as_bytes() {
|
||||||
return Ok(HttpResponse::BadRequest().json("Disk image max size exceeded!"));
|
return Ok(HttpResponse::BadRequest().json("Disk image max size exceeded!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ pub async fn upload_file(MultipartForm(mut form): MultipartForm<UploadIsoForm>)
|
|||||||
|
|
||||||
let file = form.files.remove(0);
|
let file = form.files.remove(0);
|
||||||
|
|
||||||
if file.size > constants::ISO_MAX_SIZE {
|
if file.size > constants::ISO_MAX_SIZE.as_bytes() {
|
||||||
log::error!("Uploaded ISO file is too large!");
|
log::error!("Uploaded ISO file is too large!");
|
||||||
return Ok(HttpResponse::BadRequest().json("File is too large!"));
|
return Ok(HttpResponse::BadRequest().json("File is too large!"));
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ pub async fn upload_from_url(req: web::Json<DownloadFromURLReq>) -> HttpResult {
|
|||||||
let response = reqwest::get(&req.url).await?;
|
let response = reqwest::get(&req.url).await?;
|
||||||
|
|
||||||
if let Some(len) = response.content_length() {
|
if let Some(len) = response.content_length() {
|
||||||
if len > constants::ISO_MAX_SIZE as u64 {
|
if len > constants::ISO_MAX_SIZE.as_bytes() as u64 {
|
||||||
return Ok(HttpResponse::BadRequest().json("File is too large!"));
|
return Ok(HttpResponse::BadRequest().json("File is too large!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,8 +71,8 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
|
|||||||
builtin_nwfilter_rules: &constants::BUILTIN_NETWORK_FILTER_RULES,
|
builtin_nwfilter_rules: &constants::BUILTIN_NETWORK_FILTER_RULES,
|
||||||
nwfilter_chains: &constants::NETWORK_CHAINS,
|
nwfilter_chains: &constants::NETWORK_CHAINS,
|
||||||
constraints: ServerConstraints {
|
constraints: ServerConstraints {
|
||||||
iso_max_size: constants::ISO_MAX_SIZE,
|
iso_max_size: constants::ISO_MAX_SIZE.as_bytes(),
|
||||||
disk_image_max_size: constants::DISK_IMAGE_MAX_SIZE,
|
disk_image_max_size: constants::DISK_IMAGE_MAX_SIZE.as_bytes(),
|
||||||
|
|
||||||
vnc_token_duration: VNC_TOKEN_LIFETIME,
|
vnc_token_duration: VNC_TOKEN_LIFETIME,
|
||||||
|
|
||||||
|
@@ -122,10 +122,9 @@ async fn main() -> std::io::Result<()> {
|
|||||||
}))
|
}))
|
||||||
.app_data(conn.clone())
|
.app_data(conn.clone())
|
||||||
// Uploaded files
|
// Uploaded files
|
||||||
.app_data(
|
.app_data(MultipartFormConfig::default().total_limit(
|
||||||
MultipartFormConfig::default()
|
max(constants::DISK_IMAGE_MAX_SIZE, constants::ISO_MAX_SIZE).as_bytes(),
|
||||||
.total_limit(max(constants::DISK_IMAGE_MAX_SIZE, constants::ISO_MAX_SIZE)),
|
))
|
||||||
)
|
|
||||||
.app_data(TempFileConfig::default().directory(&AppConfig::get().temp_dir))
|
.app_data(TempFileConfig::default().directory(&AppConfig::get().temp_dir))
|
||||||
// Server controller
|
// Server controller
|
||||||
.route(
|
.route(
|
||||||
|
Reference in New Issue
Block a user