Skip to content

Commit

Permalink
Convert .html files into String to execute as binary
Browse files Browse the repository at this point in the history
Update docstrings and README.md
  • Loading branch information
dormant-user committed Feb 18, 2024
1 parent ea466bd commit 10f67a8
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 50 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Update Rust
# print it with style
run: |
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
[![made-with-rust][rust-logo]][rust-src-page]

[![build][gh-logo]][build]
[![crates.io][crates-logo]][crates]
[![docs.rs][docs-logo]][docs]

[![crates.io][crates-logo]][crate]

**Platform Supported**

[![platform][platform]][cross-platform]

#### Summary
[`RuStream`][repo] is an application written in Rust to stream videos using Actix API via authenticated sessions.
[`RuStream`][repo] is a self-hosted streaming engine, that can render videos via authenticated sessions.

## Usage

Expand Down Expand Up @@ -75,14 +79,14 @@ async fn main() {
"authorization": {"rustic": "S0m3rAn0mP@ssW0rD"},
"video_source": "/Users/hannibal/Downloads/stream",
"video_port": 5883,
"file_formats": [".mov", ".mp4", ".mkv"],
"file_formats": ["mov", "mp4", "mkv"],
"workers": 10
}
```
</details>

## Crate
https://crates.io/crates/RuStream
[https://crates.io/crates/RuStream][crate]

## Linting
### Requirement
Expand All @@ -106,8 +110,8 @@ Licensed under the [MIT License][license]
[rust-src-page]: https://www.rust-lang.org/
[rust-logo]: https://img.shields.io/badge/Made%20with-Rust-black?style=for-the-badge&logo=Rust
[gh-logo]: https://github.com/thevickypedia/RuStream/actions/workflows/rust.yml/badge.svg
[docs-logo]: https://docs.rs/RuStream/badge.svg
[docs]: https://docs.rs/RuStream
[crates]: https://crates.io/crates/RuStream
[crate]: https://crates.io/crates/RuStream
[gh-checks]: https://github.com/thevickypedia/RuStream/actions/workflows/rust.yml
[crates-logo]: https://img.shields.io/crates/v/RuStream.svg
[platform]: https://img.shields.io/badge/Platform-Linux_|_macOS_|_Windows-blue?style=for-the-badge&logo=ubuntu
[cross-platform]: https://www.computerlanguage.com/results.php?definition=cross+platform
40 changes: 8 additions & 32 deletions src/jinja.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
use std::path::Path;
use std::sync::{Arc, Mutex};

/// Read the content of each file and return it as a String.
///
/// # Arguments
///
/// * `filename` - Filename that has to be read.
///
/// # Returns
///
/// String representation of the file content.
fn get_content(filename: &str) -> String {
let filepath = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src")
.join("templates")
.join(format!("{}.html", filename))
.to_string_lossy()
.to_string();
std::fs::read_to_string(filepath).unwrap_or_else(|_| String::new())
}
use crate::templates;

/// Reads all the HTML files in templates directory and loads the content into a Jinja Environment
///
/// # Rendered files
/// - Index page template that is served as HTML response for the root endpoint.
/// - Landing page template that is served as HTML response while streaming videos.
/// - Listing page template that is served as HTML response after successful authentication.
/// - Logout page template that is served as HTML response when the user decides to end the session.
/// - Session page template that is served as HTML response when invalid/expired session tokens are received.
/// - Unauthorized page template that is served as HTML response after failed authentication.
/// Loads all the HTML content into a Jinja Environment
pub fn environment() -> Arc<Mutex<minijinja::Environment<'static>>> {
let mut env = minijinja::Environment::new();
for html in ["index", "landing", "listing", "logout", "session", "unauthorized"] {
let content = get_content(html);
env.add_template_owned(html, content).unwrap();
}
env.add_template_owned("index", templates::index::get_content()).unwrap();
env.add_template_owned("landing", templates::landing::get_content()).unwrap();
env.add_template_owned("listing", templates::listing::get_content()).unwrap();
env.add_template_owned("logout", templates::logout::get_content()).unwrap();
env.add_template_owned("session", templates::session::get_content()).unwrap();
env.add_template_owned("unauthorized", templates::unauthorized::get_content()).unwrap();
let mutex = Mutex::new(env.to_owned());
Arc::new(mutex)
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mod jinja;
mod routes;
/// Module to store all the helper functions.
mod squire;
/// Module to load all the templates for the UI.
mod templates;

/// Contains entrypoint and initializer settings to trigger the asynchronous HTTPServer
///
Expand Down
14 changes: 13 additions & 1 deletion src/templates/index.html → src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<!DOCTYPE html>
/// Get the HTML content to render the index/root page.
///
/// # See Also
///
/// - This page is served as a response for the `/` entry point.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<!--suppress JSUnresolvedLibraryURL -->
<html lang="en">
<head>
Expand Down Expand Up @@ -196,3 +206,5 @@ <h2 style="margin-top:5%">This page requires JavaScript
</script>
</html>
"###.to_string()
}
14 changes: 13 additions & 1 deletion src/templates/landing.html → src/templates/landing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<!DOCTYPE html>
/// Get the HTML content to render the streaming/landing page.
///
/// # See Also
///
/// - This page is served as a response for the `/stream` entry point.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<!--suppress JSUnresolvedLibraryURL -->
<html lang="en">
<head>
Expand Down Expand Up @@ -192,3 +202,5 @@ <h1>{{ video_title }}</h1>
</script>
</body>
</html>
"###.to_string()
}
14 changes: 13 additions & 1 deletion src/templates/listing.html → src/templates/listing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<!DOCTYPE html>
/// Get the HTML content to render the home/listing page.
///
/// # See Also
///
/// - This page is served as a response for the `/home` entry point.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<!--suppress JSUnresolvedLibraryURL -->
<html lang="en">
<head>
Expand Down Expand Up @@ -143,3 +153,5 @@ <h3 style="text-align: center">No content was rendered by the server</h3>
</script>
</body>
</html>
"###.to_string()
}
14 changes: 13 additions & 1 deletion src/templates/logout.html → src/templates/logout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<!DOCTYPE html>
/// Get the HTML content to render the logout page.
///
/// # See Also
///
/// - This page is served as a response for the `/logout` entry point.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<html lang="en">
<head>
<title>Rustic video streaming</title>
Expand Down Expand Up @@ -67,3 +77,5 @@ <h4>Click <a href="https://vigneshrao.com/contact">ME</a> to reach out.</h4>
});
</script>
</html>
"###.to_string()
}
12 changes: 12 additions & 0 deletions src/templates/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Index page template that is served as HTML response for the root endpoint.
pub mod index;
/// Landing page template that is served as HTML response while streaming videos.
pub mod landing;
/// Listing page template that is served as HTML response after successful authentication.
pub mod listing;
/// Logout page template that is served as HTML response when the user decides to end the session.
pub mod logout;
/// Session page template that is served as HTML response when invalid/expired session tokens are received.
pub mod session;
/// Unauthorized page template that is served as HTML response after failed authentication.
pub mod unauthorized;
15 changes: 14 additions & 1 deletion src/templates/session.html → src/templates/session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<!DOCTYPE html>
/// Get the HTML content to render the session expired/invalid page.
///
/// # See Also
///
/// - This page is served as a response for all the content delivery entry points,
/// when the user session-token is invalid or expired.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<html lang="en">
<head>
<title>Rustic video streaming</title>
Expand Down Expand Up @@ -66,3 +77,5 @@ <h4>Click <a href="https://vigneshrao.com/contact">HERE</a> to reach out.</h4>
});
</script>
</html>
"###.to_string()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<!DOCTYPE html>
/// Get the HTML content to render the session unauthorized page.
///
/// # See Also
///
/// - This page is served as a response for all the entry points,
/// when the user tries to access a page without valid authentication.
///
/// # Returns
///
/// A `String` version of the HTML, CSS and JS content.
pub fn get_content() -> String {
r###"<!DOCTYPE html>
<html lang="en">
<head>
<title>Rustic video streaming</title>
Expand Down Expand Up @@ -64,3 +75,5 @@ <h4>Click <a href="https://vigneshrao.com/contact">HERE</a> to reach out.</h4>
});
</script>
</html>
"###.to_string()
}

0 comments on commit 10f67a8

Please sign in to comment.