Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Jan 24, 2022
2 parents 4d162d4 + 1f5cf77 commit 2135b16
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 127 deletions.
31 changes: 15 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustus"
version = "0.3.1"
version = "0.4.0"
edition = "2021"
description = "TUS protocol implementation written in Rust."

Expand All @@ -26,7 +26,7 @@ features = ["vendored"]
version = "0.6.0-beta.13"

[dependencies.actix-web]
version = "^4.0.0-beta.15"
version = "^4.0.0-beta.20"

[dependencies.async-std]
features = ["tokio1"]
Expand Down
13 changes: 10 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ pub struct NotificationsOptions {
/// [here](https://tus.io/).
pub struct RustusConf {
/// Rustus server host
#[structopt(short, long, default_value = "0.0.0.0", env = "RUSTUS_HOST")]
#[structopt(short, long, default_value = "0.0.0.0", env = "RUSTUS_SERVER_HOST")]
pub host: String,

/// Rustus server port
#[structopt(short, long, default_value = "1081", env = "RUSTUS_PORT")]
#[structopt(short, long, default_value = "1081", env = "RUSTUS_SERVER_PORT")]
pub port: u16,

/// Rustus base API url
Expand Down Expand Up @@ -177,12 +177,19 @@ pub struct RustusConf {
/// Enabled extensions for TUS protocol.
#[structopt(
long,
default_value = "getting,creation,termination,creation-with-upload,creation-defer-length",
default_value = "getting,creation,termination,creation-with-upload,creation-defer-length,concatenation",
env = "RUSTUS_TUS_EXTENSIONS",
use_delimiter = true
)]
pub tus_extensions: Vec<Extensions>,

/// Remove part files after concatenation is done.
/// By default rustus does nothing with part files after concatenation.
///
/// This parameter is only needed if concatenation extension is enabled.
#[structopt(long, parse(from_flag))]
pub remove_parts: bool,

#[structopt(flatten)]
pub storage_opts: StorageOptions,

Expand Down
6 changes: 6 additions & 0 deletions src/info_storages/models/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct FileInfo {
#[serde(with = "ts_seconds")]
pub created_at: DateTime<Utc>,
pub deferred_size: bool,
pub is_partial: bool,
pub is_final: bool,
pub parts: Option<Vec<String>>,
pub storage: String,
pub metadata: HashMap<String, String>,
}
Expand Down Expand Up @@ -55,6 +58,9 @@ impl FileInfo {
metadata,
deferred_size,
offset: 0,
is_final: false,
is_partial: false,
parts: None,
created_at: chrono::Utc::now(),
}
}
Expand Down
40 changes: 17 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use log::LevelFilter;
use crate::errors::RustusResult;
use crate::info_storages::InfoStorage;
use crate::notifiers::models::notification_manager::NotificationManager;
use crate::state::State;
use config::RustusConf;

use crate::storages::Storage;
Expand All @@ -23,6 +24,7 @@ mod info_storages;
mod notifiers;
mod protocol;
mod routes;
mod state;
mod storages;
mod utils;

Expand Down Expand Up @@ -64,35 +66,22 @@ fn greeting(app_conf: &RustusConf) {
/// This function may throw an error
/// if the server can't be bound to the
/// given address.
pub fn create_server(
storage: Box<dyn Storage + Send + Sync>,
info_storage: Box<dyn InfoStorage + Send + Sync>,
app_conf: RustusConf,
notification_manager: NotificationManager,
) -> Result<Server, std::io::Error> {
let host = app_conf.host.clone();
let port = app_conf.port;
let workers = app_conf.workers;
let app_conf_data = web::Data::new(app_conf.clone());
let info_storage_data: web::Data<Box<dyn InfoStorage + Send + Sync>> =
web::Data::from(Arc::new(info_storage));
let storage_data: web::Data<Box<dyn Storage + Send + Sync>> =
web::Data::from(Arc::new(storage));
let manager_data: web::Data<Box<NotificationManager>> =
web::Data::from(Arc::new(Box::new(notification_manager)));
pub fn create_server(state: State) -> Result<Server, std::io::Error> {
let host = state.config.host.clone();
let port = state.config.port;
let config = state.config.clone();
let workers = state.config.workers;
let state_data: web::Data<State> = web::Data::from(Arc::new(state));
let mut server = HttpServer::new(move || {
App::new()
.app_data(app_conf_data.clone())
.app_data(storage_data.clone())
.app_data(manager_data.clone())
.app_data(info_storage_data.clone())
.app_data(state_data.clone())
// Adds all routes.
.configure(protocol::setup(app_conf.clone()))
.configure(protocol::setup(config.clone()))
// Main middleware that appends TUS headers.
.wrap(
middleware::DefaultHeaders::new()
.add(("Tus-Resumable", "1.0.0"))
.add(("Tus-Max-Size", app_conf.max_body_size.to_string()))
.add(("Tus-Max-Size", config.max_body_size.to_string()))
.add(("Tus-Version", "1.0.0")),
)
.wrap(middleware::Logger::new("\"%r\" \"-\" \"%s\" \"%a\" \"%D\""))
Expand Down Expand Up @@ -176,6 +165,11 @@ async fn main() -> std::io::Result<()> {
let notification_manager = NotificationManager::new(&app_conf).await?;

// Creating actual server and running it.
let server = create_server(storage, info_storage, app_conf, notification_manager)?;
let server = create_server(State::new(
app_conf.clone(),
storage,
info_storage,
notification_manager,
))?;
server.await
}
6 changes: 3 additions & 3 deletions src/notifiers/models/message_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl From<FileInfo> for TusdFileInfo {
offset: file_info.offset,
size: file_info.length,
size_is_deferred: deferred_size,
is_final: true,
is_partial: false,
partial_uploads: None,
is_final: file_info.is_final,
is_partial: file_info.is_partial,
partial_uploads: file_info.parts,
metadata: file_info.metadata,
storage: TusdStorageInfo {
storage_type: file_info.storage,
Expand Down
1 change: 1 addition & 0 deletions src/notifiers/models/notification_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl NotificationManager {
notifiers: Vec::new(),
};
debug!("Initializing notification manager.");
#[cfg(feature = "file_notifiers")]
if tus_config.notification_opts.hooks_file.is_some() {
debug!("Found hooks file");
manager.notifiers.push(Box::new(FileNotifier::new(
Expand Down
Loading

0 comments on commit 2135b16

Please sign in to comment.