forked from neri/datatrash
use rand distribution for file id generation
This commit is contained in:
parent
756d4b67a0
commit
44843ab222
|
@ -7,7 +7,7 @@ use actix_files::NamedFile;
|
|||
use actix_multipart::Multipart;
|
||||
use actix_web::http::header::LOCATION;
|
||||
use actix_web::{error, web, Error, HttpRequest, HttpResponse};
|
||||
use rand::prelude::SliceRandom;
|
||||
use rand::{distributions::Slice, Rng};
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::path::PathBuf;
|
||||
use tokio::fs::{self, OpenOptions};
|
||||
|
@ -139,12 +139,11 @@ async fn create_unique_file(
|
|||
}
|
||||
|
||||
fn gen_file_id() -> String {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut id = String::with_capacity(5);
|
||||
for _ in 0..5 {
|
||||
id.push(*ID_CHARS.choose(&mut rng).expect("ID_CHARS is not empty"));
|
||||
}
|
||||
id
|
||||
let distribution = Slice::new(ID_CHARS).expect("ID_CHARS is not empty");
|
||||
rand::thread_rng()
|
||||
.sample_iter(distribution)
|
||||
.take(5)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_file_url(req: &HttpRequest, id: &str, name: Option<&str>) -> String {
|
||||
|
|
Loading…
Reference in New Issue