diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9bbe9af..9b60952 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: working-directory: ./Website run: | cp target/aarch64-unknown-linux-gnu/release/FicsIt-Networks-Repository-Website . - chmod 770 FicsIt-Networks-Repository-Website + chmod 770 ./FicsIt-Networks-Repository-Website - name: Upload Website uses: actions/upload-artifact@v4 with: @@ -87,5 +87,6 @@ jobs: username: ${{ secrets.DEPLOY_USERNAME }} key: ${{ secrets.DEPLOY_KEY }} script: | - cd $${{ secrets.DEPLOY_FOLDER }} + cd ${{ secrets.DEPLOY_FOLDER }} + chmod 770 ./Website/FicsIt-Networks-Repository-Website podman-compose up --build --force-recreate diff --git a/Website/src/main.rs b/Website/src/main.rs index 9d49d44..5f36781 100644 --- a/Website/src/main.rs +++ b/Website/src/main.rs @@ -15,7 +15,7 @@ use url::Url; use crate::repository::Repository; pub async fn app() -> Result { - let index_file = std::env::var("FIN_REPO_INDEX").unwrap_or(String::from("../index.zip")); + let index_file = std::env::var("FIN_REPO_INDEX").unwrap_or(String::from("https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/index/index.zip")); let url = std::env::var("FIN_REPO_RAW").unwrap_or(String::from("..")); println!("Repository Index File: '{}'", index_file); println!("Repository Raw Base URL: '{}'", url); diff --git a/Website/src/repository/mod.rs b/Website/src/repository/mod.rs index cfadb49..b6e6939 100644 --- a/Website/src/repository/mod.rs +++ b/Website/src/repository/mod.rs @@ -40,7 +40,7 @@ fn unzip_index(reader: R) -> zip::result::ZipResult { async fn get_and_unzip_index(url: &str) -> zip::result::ZipResult { match read_file_or_url(url).await.unwrap() { - URLOrFile::URL(content) => unzip_index(std::io::Cursor::new(content.as_bytes())), + URLOrFile::URL(content) => unzip_index(std::io::Cursor::new(content)), URLOrFile::File(file) => unzip_index(&file), } } diff --git a/Website/src/routes/package.rs b/Website/src/routes/package.rs index 126b1fc..3f55507 100644 --- a/Website/src/routes/package.rs +++ b/Website/src/routes/package.rs @@ -79,7 +79,7 @@ pub async fn get_package( Path((package_id)): Path<(String)>, ) -> Result { let mut package: Package = match read_file_or_url(&repository.path(&format!("/Packages/{package_id}/metadata.toml"))).await.ok_or(StatusCode::NOT_FOUND)? { - URLOrFile::URL(content) => toml::from_str(&content).ok(), + URLOrFile::URL(content) => std::str::from_utf8(&content).ok().map(|s| toml::from_str(s).unwrap()).flatten(), URLOrFile::File(file) => std::io::read_to_string(file).ok().map(|s| { toml::from_str(&s).unwrap() }).flatten(), @@ -99,7 +99,7 @@ pub async fn get_package( readme = read_file_or_url(&repository.path(&format!("/Packages/{package_id}/README.adoc"))).await; } package.readme = match readme.ok_or(StatusCode::NOT_FOUND)? { - URLOrFile::URL(content) => Some(content), + URLOrFile::URL(content) => std::str::from_utf8(&content).map(|s| s.to_string()).ok(), URLOrFile::File(file) => std::io::read_to_string(file).ok(), }.unwrap_or("".to_string()); diff --git a/Website/src/util.rs b/Website/src/util.rs index 6106287..69aef0c 100644 --- a/Website/src/util.rs +++ b/Website/src/util.rs @@ -1,16 +1,17 @@ use std::fs::File; use std::path::Path; +use axum::body::Bytes; use url::Url; pub enum URLOrFile { - URL(String), + URL(Bytes), File(File), } pub async fn read_file_or_url(url: &str) -> Option { Some(if let Ok(url) = Url::parse(url) { let response = reqwest::get(url).await.unwrap(); - let content = response.text().await.unwrap(); + let content = response.bytes().await.unwrap(); URLOrFile::URL(content) } else { let index = File::open(Path::new(url)).unwrap();