mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 20:42:15 +00:00
fix: portfolio submit fix
This commit is contained in:
parent
39aa1f0ad6
commit
5bac182f83
1 changed files with 20 additions and 25 deletions
|
|
@ -47,14 +47,14 @@ impl CandidateService {
|
|||
|
||||
let (pubkey, priv_key_plain_text) = crypto::create_identity();
|
||||
|
||||
let encrypted_priv_key = crypto::encrypt_password(priv_key_plain_text, plain_text_password.to_string()).await?;
|
||||
let encrypted_priv_key =
|
||||
crypto::encrypt_password(priv_key_plain_text, plain_text_password.to_string()).await?;
|
||||
|
||||
let hashed_personal_id_number = hash_password(personal_id_number).await?;
|
||||
|
||||
// TODO: Specify root path in config?
|
||||
tokio::fs::create_dir_all(Path::new(&application_id.to_string()).join("cache")).await?;
|
||||
|
||||
|
||||
let candidate = Mutation::create_candidate(
|
||||
db,
|
||||
application_id,
|
||||
|
|
@ -142,40 +142,29 @@ impl CandidateService {
|
|||
|
||||
let mut archive = tokio::fs::File::create(path.join("PORTFOLIO.zip")).await?;
|
||||
|
||||
|
||||
let mut writer = async_zip::write::ZipFileWriter::new(&mut archive);
|
||||
|
||||
for entry in vec!["MOTIVACNI_DOPIS.pdf", "PORTFOLIO.pdf", "PORTFOLIO.zip"] {
|
||||
let mut entry_file = tokio::fs::File::open(cache_path.join(entry))
|
||||
.await?;
|
||||
let mut entry_file = tokio::fs::File::open(cache_path.join(entry)).await?;
|
||||
|
||||
let mut contents = vec![];
|
||||
let mut contents_buffer = vec![];
|
||||
|
||||
entry_file
|
||||
.read_to_end(&mut contents)
|
||||
.await?;
|
||||
entry_file.read_to_end(&mut contents_buffer).await?;
|
||||
|
||||
let builder =
|
||||
async_zip::ZipEntryBuilder::new(entry.to_string(), async_zip::Compression::Deflate);
|
||||
|
||||
let mut entry_writer = writer
|
||||
.write_entry_stream(builder)
|
||||
.await?;
|
||||
|
||||
// TODO: write_all_buf?
|
||||
entry_writer
|
||||
.write_all(&mut contents)
|
||||
.await?;
|
||||
writer.write_entry_whole(builder, &contents_buffer).await?;
|
||||
}
|
||||
|
||||
// TODO: Ne unwrap
|
||||
writer.close().await.unwrap();
|
||||
archive.shutdown().await.unwrap();
|
||||
|
||||
let admin_public_keys = Query::get_all_admin_public_keys(db)
|
||||
.await?;
|
||||
let admin_public_keys = Query::get_all_admin_public_keys(db).await?;
|
||||
|
||||
let candidate = Query::find_candidate_by_id(db, candidate_id).await?
|
||||
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
||||
.await?
|
||||
.ok_or(ServiceError::CandidateNotFound)?;
|
||||
|
||||
let candidate_public_key = candidate.public_key;
|
||||
|
|
@ -187,27 +176,33 @@ impl CandidateService {
|
|||
|
||||
recipients.append(&mut admin_public_keys_refrence);
|
||||
|
||||
let final_path = path.join("PORTFOLIO.zip");
|
||||
|
||||
let Ok(_) = crypto::encrypt_file_with_recipients(
|
||||
path.join("PORTFOLIO.zip"),
|
||||
path.join("PORTFOLIO.zip"),
|
||||
&final_path,
|
||||
&final_path.with_extension("age"),
|
||||
recipients,
|
||||
)
|
||||
.await else {
|
||||
return Err(ServiceError::CryptoEncryptFailed);
|
||||
};
|
||||
|
||||
tokio::fs::remove_file(final_path).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_portfolio(candidate_id: i32, db: &DbConn) -> Result<Vec<u8>, ServiceError> {
|
||||
let candidate = Query::find_candidate_by_id(db, candidate_id).await?
|
||||
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
||||
.await?
|
||||
.ok_or(ServiceError::CandidateNotFound)?;
|
||||
|
||||
let candidate_public_key = candidate.public_key;
|
||||
|
||||
let path = Path::new(&candidate_id.to_string()).join("PORTFOLIO.zip");
|
||||
let path = Path::new(&candidate_id.to_string()).join("PORTFOLIO.age");
|
||||
|
||||
let buffer = crypto::decrypt_file_with_private_key_as_buffer(path, &candidate_public_key).await?;
|
||||
let buffer =
|
||||
crypto::decrypt_file_with_private_key_as_buffer(path, &candidate_public_key).await?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue