mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-08 09:12:26 +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 (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?;
|
let hashed_personal_id_number = hash_password(personal_id_number).await?;
|
||||||
|
|
||||||
// TODO: Specify root path in config?
|
// TODO: Specify root path in config?
|
||||||
tokio::fs::create_dir_all(Path::new(&application_id.to_string()).join("cache")).await?;
|
tokio::fs::create_dir_all(Path::new(&application_id.to_string()).join("cache")).await?;
|
||||||
|
|
||||||
|
|
||||||
let candidate = Mutation::create_candidate(
|
let candidate = Mutation::create_candidate(
|
||||||
db,
|
db,
|
||||||
application_id,
|
application_id,
|
||||||
|
|
@ -142,40 +142,29 @@ impl CandidateService {
|
||||||
|
|
||||||
let mut archive = tokio::fs::File::create(path.join("PORTFOLIO.zip")).await?;
|
let mut archive = tokio::fs::File::create(path.join("PORTFOLIO.zip")).await?;
|
||||||
|
|
||||||
|
|
||||||
let mut writer = async_zip::write::ZipFileWriter::new(&mut archive);
|
let mut writer = async_zip::write::ZipFileWriter::new(&mut archive);
|
||||||
|
|
||||||
for entry in vec!["MOTIVACNI_DOPIS.pdf", "PORTFOLIO.pdf", "PORTFOLIO.zip"] {
|
for entry in vec!["MOTIVACNI_DOPIS.pdf", "PORTFOLIO.pdf", "PORTFOLIO.zip"] {
|
||||||
let mut entry_file = tokio::fs::File::open(cache_path.join(entry))
|
let mut entry_file = tokio::fs::File::open(cache_path.join(entry)).await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut contents = vec![];
|
let mut contents_buffer = vec![];
|
||||||
|
|
||||||
entry_file
|
entry_file.read_to_end(&mut contents_buffer).await?;
|
||||||
.read_to_end(&mut contents)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let builder =
|
let builder =
|
||||||
async_zip::ZipEntryBuilder::new(entry.to_string(), async_zip::Compression::Deflate);
|
async_zip::ZipEntryBuilder::new(entry.to_string(), async_zip::Compression::Deflate);
|
||||||
|
|
||||||
let mut entry_writer = writer
|
writer.write_entry_whole(builder, &contents_buffer).await?;
|
||||||
.write_entry_stream(builder)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// TODO: write_all_buf?
|
|
||||||
entry_writer
|
|
||||||
.write_all(&mut contents)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ne unwrap
|
// TODO: Ne unwrap
|
||||||
writer.close().await.unwrap();
|
writer.close().await.unwrap();
|
||||||
archive.shutdown().await.unwrap();
|
archive.shutdown().await.unwrap();
|
||||||
|
|
||||||
let admin_public_keys = Query::get_all_admin_public_keys(db)
|
let admin_public_keys = Query::get_all_admin_public_keys(db).await?;
|
||||||
.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)?;
|
.ok_or(ServiceError::CandidateNotFound)?;
|
||||||
|
|
||||||
let candidate_public_key = candidate.public_key;
|
let candidate_public_key = candidate.public_key;
|
||||||
|
|
@ -187,27 +176,33 @@ impl CandidateService {
|
||||||
|
|
||||||
recipients.append(&mut admin_public_keys_refrence);
|
recipients.append(&mut admin_public_keys_refrence);
|
||||||
|
|
||||||
|
let final_path = path.join("PORTFOLIO.zip");
|
||||||
|
|
||||||
let Ok(_) = crypto::encrypt_file_with_recipients(
|
let Ok(_) = crypto::encrypt_file_with_recipients(
|
||||||
path.join("PORTFOLIO.zip"),
|
&final_path,
|
||||||
path.join("PORTFOLIO.zip"),
|
&final_path.with_extension("age"),
|
||||||
recipients,
|
recipients,
|
||||||
)
|
)
|
||||||
.await else {
|
.await else {
|
||||||
return Err(ServiceError::CryptoEncryptFailed);
|
return Err(ServiceError::CryptoEncryptFailed);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tokio::fs::remove_file(final_path).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_portfolio(candidate_id: i32, db: &DbConn) -> Result<Vec<u8>, ServiceError> {
|
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)?;
|
.ok_or(ServiceError::CandidateNotFound)?;
|
||||||
|
|
||||||
let candidate_public_key = candidate.public_key;
|
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)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue