prevent filling up the disk
This commit is contained in:
		
							parent
							
								
									37695b8bbd
								
							
						
					
					
						commit
						71fe7fed24
					
				
					 5 changed files with 77 additions and 20 deletions
				
			
		
							
								
								
									
										19
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -36,6 +36,7 @@ struct AppData {
 | 
			
		|||
struct Config {
 | 
			
		||||
    base_url: String,
 | 
			
		||||
    max_storage_size: u64,
 | 
			
		||||
    min_disk_free: u64,
 | 
			
		||||
    max_upload_size: u64,
 | 
			
		||||
    max_lifetime: u16,
 | 
			
		||||
    upload_password: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -290,8 +291,8 @@ async fn handle_upload(
 | 
			
		|||
    req: HttpRequest,
 | 
			
		||||
    stream: web::Payload,
 | 
			
		||||
    data: web::Data<AppData>,
 | 
			
		||||
) -> impl Responder {
 | 
			
		||||
    if data.state.read().await.full(data.config.max_storage_size) {
 | 
			
		||||
) -> actix_web::Result<impl Responder> {
 | 
			
		||||
    if data.full().await? {
 | 
			
		||||
        return Ok(HttpResponse::BadRequest().finish());
 | 
			
		||||
    }
 | 
			
		||||
    let ip_addr = get_ip_addr(&req, data.config.reverse_proxy);
 | 
			
		||||
| 
						 | 
				
			
			@ -326,16 +327,15 @@ struct UploadLimits {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#[get("/upload/limits.json")]
 | 
			
		||||
async fn upload_limits(data: web::Data<AppData>) -> impl Responder {
 | 
			
		||||
    let file_store = data.state.read().await;
 | 
			
		||||
    let open = !file_store.full(data.config.max_storage_size);
 | 
			
		||||
    let available_size = file_store.available_size(data.config.max_storage_size);
 | 
			
		||||
async fn upload_limits(data: web::Data<AppData>) -> actix_web::Result<impl Responder> {
 | 
			
		||||
    let open = !data.full().await?;
 | 
			
		||||
    let available_size = data.available_size().await?;
 | 
			
		||||
    let max_size = std::cmp::min(available_size, data.config.max_upload_size);
 | 
			
		||||
    web::Json(UploadLimits {
 | 
			
		||||
    Ok(web::Json(UploadLimits {
 | 
			
		||||
        open,
 | 
			
		||||
        max_size,
 | 
			
		||||
        max_lifetime: data.config.max_lifetime,
 | 
			
		||||
    })
 | 
			
		||||
    }))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn env_or<T: FromStr>(var: &str, default: T) -> T
 | 
			
		||||
| 
						 | 
				
			
			@ -388,6 +388,8 @@ async fn main() -> std::io::Result<()> {
 | 
			
		|||
        env_or::<ByteSize>("TRANSBEAM_MAX_UPLOAD_SIZE", ByteSize(16 * bytesize::GB)).as_u64();
 | 
			
		||||
    let max_storage_size: u64 =
 | 
			
		||||
        env_or::<ByteSize>("TRANSBEAM_MAX_STORAGE_SIZE", ByteSize(64 * bytesize::GB)).as_u64();
 | 
			
		||||
    let min_disk_free: u64 =
 | 
			
		||||
        env_or::<ByteSize>("TRANSBEAM_MIN_DISK_FREE", ByteSize(8 * bytesize::GB)).as_u64();
 | 
			
		||||
    let upload_password: String = env_or_panic("TRANSBEAM_UPLOAD_PASSWORD");
 | 
			
		||||
    let cachebuster: String = env_or_else("TRANSBEAM_CACHEBUSTER", String::new);
 | 
			
		||||
    let admin_password_hash: PasswordHashString = env_or_panic("TRANSBEAM_ADMIN_PASSWORD_HASH");
 | 
			
		||||
| 
						 | 
				
			
			@ -423,6 +425,7 @@ async fn main() -> std::io::Result<()> {
 | 
			
		|||
            base_url,
 | 
			
		||||
            max_upload_size,
 | 
			
		||||
            max_storage_size,
 | 
			
		||||
            min_disk_free,
 | 
			
		||||
            max_lifetime,
 | 
			
		||||
            upload_password,
 | 
			
		||||
            storage_dir,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue