Skip to content

Commit

Permalink
Add a fallback for failing custom file formats
Browse files Browse the repository at this point in the history
Update rust before build in GH actions
  • Loading branch information
dormant-user committed Feb 11, 2024
1 parent a0940b9 commit 94aba20
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Update Rust
# print it with style
run: |
printf '*%.0s' {1..60} && printf "\n"
echo "Existing rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n\n"
rustup update && printf "\n"
printf '*%.0s' {1..60} && printf "\n"
echo "Updated rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n"
- name: Install OpenSSL static for Windows
# https://github.com/sfackler/rust-openssl/issues/1086
Expand Down
12 changes: 10 additions & 2 deletions src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ pub async fn home(config: web::Data<Arc<squire::settings::Config>>,
}
squire::logger::log_connection(&request);
log::debug!("{}", auth_response.detail);
let default_values = squire::settings::default_file_formats();
let file_format;
// https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.collect_tuple
let file_format = config.file_formats.iter().collect_tuple().unwrap();
let args = (config.video_source.to_string_lossy().to_string(), file_format);
let _file_format = config.file_formats.iter().collect_tuple();
if _file_format.is_none() {
log::debug!("CRITICAL::Failed to extract tuple from {:?}", config.file_formats);
file_format = default_values.iter().collect_tuple();
} else {
file_format = _file_format
}
let args = (config.video_source.to_string_lossy().to_string(), file_format.unwrap());
let listing_page = squire::fileio::get_all_stream_content(args);
let template = constant::ENV.lock().unwrap();
let listing = template.get_template("listing").unwrap();
Expand Down
26 changes: 22 additions & 4 deletions src/routes/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ pub async fn stream(config: web::Data<Arc<squire::settings::Config>>,
let template = constant::ENV.lock().unwrap();
if target.is_file() {
let landing = template.get_template("landing").unwrap();
let file_format = config.file_formats.iter().collect_tuple().unwrap();
let args = (&target_str, file_format);
let default_values = squire::settings::default_file_formats();
let file_format;
// https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.collect_tuple
let _file_format = config.file_formats.iter().collect_tuple();
if _file_format.is_none() {
log::debug!("CRITICAL::Failed to extract tuple from {:?}", config.file_formats);
file_format = default_values.iter().collect_tuple();
} else {
file_format = _file_format
}
let args = (&target_str, file_format.unwrap());
let iter = squire::fileio::get_iter(args);
// https://rustjobs.dev/blog/how-to-url-encode-strings-in-rust/
let render_path = format!("/video?file={}",
Expand Down Expand Up @@ -127,8 +136,17 @@ pub async fn stream(config: web::Data<Arc<squire::settings::Config>>,
.content_type("text/html; charset=utf-8").body(response_body);
} else if target.is_dir() {
let child_dir = target.iter().last().unwrap().to_string_lossy().to_string();
let file_format = config.file_formats.iter().collect_tuple().unwrap();
let args = (target_str, child_dir, file_format);
let default_values = squire::settings::default_file_formats();
let file_format;
// https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.collect_tuple
let _file_format = config.file_formats.iter().collect_tuple();
if _file_format.is_none() {
log::debug!("CRITICAL::Failed to extract tuple from {:?}", config.file_formats);
file_format = default_values.iter().collect_tuple();
} else {
file_format = _file_format
}
let args = (target_str, child_dir, file_format.unwrap());
let listing_page = squire::fileio::get_dir_stream_content(args);
let listing = template.get_template("listing").unwrap();
return HttpResponse::build(StatusCode::OK)
Expand Down

0 comments on commit 94aba20

Please sign in to comment.