Skip to content

Commit

Permalink
Change prefix to be two-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
reasv committed Mar 30, 2021
1 parent 9621fab commit 7ac274c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ async fn get_boards_status(db: web::Data<DBClient>) -> Result<HttpResponse, Http
}

async fn get_image(db: web::Data<DBClient>, board: String, tim: i64, ext: String, is_thumb: bool)-> Result<NamedFile, HttpResponse> {
let sha256_base32 = db.image_tim_to_sha256(&board, tim, is_thumb).await
let sha256 = db.image_tim_to_sha256(&board, tim, is_thumb).await
.map_err(|e| {
error!("Error getting image from DB: {}", e);
HttpResponse::InternalServerError().finish()
})?
.ok_or(HttpResponse::NotFound().finish())?;

let filename = match is_thumb {
true => format!("{}.jpg", sha256_base32),
false => format!("{}.{}", sha256_base32, ext)
true => format!("{}.jpg", sha256),
false => format!("{}.{}", sha256, ext)
};
let path = get_file_folder(&sha256_base32, is_thumb).join(filename);
let path = get_file_folder(&sha256, is_thumb).join(filename);
NamedFile::open(path).map_err(|e| {
error!("Error getting image from filesystem: {}", e);
HttpResponse::NotFound().finish()
Expand Down
9 changes: 4 additions & 5 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,17 @@ pub fn get_file_folder(sha256: &String, is_thumb: bool) -> PathBuf {
true => image_folder.join("thumb"),
false => image_folder.join("full")
};
folder.join(&sha256[0..2])
folder.join(&sha256[0..2]).join(&sha256[2..3])
}

pub fn get_file_url(sha256: &String, ext: &String, is_thumb: bool) -> String {
let folder = match is_thumb {
true => "thumb",
false => "full"
};
if sha256.len() < 2 {
if sha256.len() < 3 {
return "/static/image/favicon-ws.ico".to_string();
}

format!("/img/{}/{}/{}{}", folder, &sha256[0..2], sha256, ext)
}

format!("/img/{}/{}/{}/{}{}", folder, &sha256[0..2], &sha256[2..3], sha256, ext)
}

0 comments on commit 7ac274c

Please sign in to comment.