Skip to content

Commit

Permalink
fix: try fix deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Panakotta00 committed Jul 20, 2024
1 parent 4c7393a commit b747b57
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Website/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use url::Url;
use crate::repository::Repository;

pub async fn app() -> Result<Router, anyhow::Error> {
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);
Expand Down
2 changes: 1 addition & 1 deletion Website/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn unzip_index<R: Read + Seek>(reader: R) -> zip::result::ZipResult<TempDir> {

async fn get_and_unzip_index(url: &str) -> zip::result::ZipResult<TempDir> {
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),
}
}
Expand Down
4 changes: 2 additions & 2 deletions Website/src/routes/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn get_package(
Path((package_id)): Path<(String)>,
) -> Result<Response> {
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(),
Expand All @@ -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());

Expand Down
5 changes: 3 additions & 2 deletions Website/src/util.rs
Original file line number Diff line number Diff line change
@@ -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<URLOrFile> {
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();
Expand Down

0 comments on commit b747b57

Please sign in to comment.