feat: ✨ dependency system
This commit is contained in:
parent
e5e3bf2de5
commit
cee3d10759
3 changed files with 53 additions and 70 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use axum::extract::Multipart;
|
||||
use tokio::{fs::File, io::AsyncWriteExt};
|
||||
use tokio_util::io::ReaderStream;
|
||||
|
@ -15,8 +17,11 @@ pub async fn read_package(package_name: String) -> Option<Package> {
|
|||
database::read_package(package_name).await
|
||||
}
|
||||
|
||||
pub async fn update_package(package_name: String, package: routing::Package) -> Option<Package> {
|
||||
let package = Package::new(package.name, package.publisher, package.version);
|
||||
pub async fn update_package(package_name: String, mut package: Package) -> Option<Package> {
|
||||
for dependency in package.get_dependencies() {
|
||||
database::read_package(dependency.to_string()).await?;
|
||||
}
|
||||
package.set_last_update_date_time();
|
||||
database::update_package(package_name, package).await
|
||||
}
|
||||
|
||||
|
@ -39,14 +44,24 @@ pub async fn upload_package(mut package_file: Multipart) -> Option<Package> {
|
|||
if let Some(package_file_name) = package_file_part.file_name() {
|
||||
let package_file_name = package_file_name.to_owned();
|
||||
let file_location = format!("./{}/{}", PACKAGE_PATH, package_file_name);
|
||||
if let Ok(package_file_data) = package_file_part.bytes().await {
|
||||
if let Some(mut package) =
|
||||
crate::package::utils::read_package(package_file_name.to_owned()).await
|
||||
{
|
||||
if let Ok(mut file_descriptor) = File::create_new(&file_location).await {
|
||||
if let Ok(_) = file_descriptor.write_all(&package_file_data).await {
|
||||
package.set_location(&file_location);
|
||||
return Some(package);
|
||||
if let Ok(file_location) = PathBuf::from(file_location).canonicalize() {
|
||||
if let Some(file_location) = file_location.to_str() {
|
||||
if let Ok(package_file_data) = package_file_part.bytes().await {
|
||||
if let Some(mut package) =
|
||||
crate::package::utils::read_package(package_file_name.to_owned())
|
||||
.await
|
||||
{
|
||||
if let Ok(mut file_descriptor) =
|
||||
File::create_new(&file_location).await
|
||||
{
|
||||
if let Ok(_) =
|
||||
file_descriptor.write_all(&package_file_data).await
|
||||
{
|
||||
package.set_location(&file_location.to_string());
|
||||
package.set_hash().await;
|
||||
return Some(package);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue