Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added uppy #898

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/uppy.min.css

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions data/uppy.min.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ pub struct MiniserveConfig {
/// Randomly generated css route
pub css_route: String,

/// Randomly generated uppy css route
pub uppy_css_route: String,

/// Randomly generated uppy js route
pub uppy_js_route: String,

/// Default color scheme
pub default_color_scheme: String,

Expand Down Expand Up @@ -157,15 +163,19 @@ impl MiniserveConfig {
// If --random-route is enabled , in order to not leak the random generated route, we must not use it
// as static files prefix.
// Otherwise, we should apply route_prefix to static files.
let (favicon_route, css_route) = if args.random_route {
let (favicon_route, css_route, uppy_css_route, uppy_js_route) = if args.random_route {
(
format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
)
} else {
(
format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
)
};

Expand Down Expand Up @@ -240,6 +250,8 @@ impl MiniserveConfig {
route_prefix,
favicon_route,
css_route,
uppy_css_route,
uppy_js_route,
default_color_scheme,
default_color_scheme_dark,
index: args.index,
Expand Down
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.wrap(middleware::Logger::default())
.route(&inside_config.favicon_route, web::get().to(favicon))
.route(&inside_config.css_route, web::get().to(css))
.route(&inside_config.uppy_css_route, web::get().to(uppy_css))
.route(&inside_config.uppy_js_route, web::get().to(uppy_js))
.service(
web::scope(&inside_config.route_prefix)
.wrap(middleware::Condition::new(
Expand Down Expand Up @@ -351,6 +353,18 @@ async fn css() -> impl Responder {
.insert_header(ContentType(mime::TEXT_CSS))
.body(css)
}
async fn uppy_css() -> impl Responder {
let uppy_css = include_str!("../data/uppy.min.css");
HttpResponse::Ok()
.insert_header(ContentType(mime::TEXT_CSS))
.body(uppy_css)
}
async fn uppy_js() -> impl Responder {
let uppy_js = include_str!("../data/uppy.min.js");
HttpResponse::Ok()
.insert_header(ContentType(mime::APPLICATION_JAVASCRIPT))
.body(uppy_js)
}

// Prints to the console two inverted QrCodes side by side.
fn print_qr(qr: &QrCode) {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ pub fn page(
button type="submit" { "Upload file" }
}
}
link rel="stylesheet" href={ (conf.uppy_css_route) };
script src={ (conf.uppy_js_route) } {};
(PreEscaped(format!(r#"
<button id="uppyT">Uppy</button>
<script>
var uppy = new Uppy.Uppy({{logger:Uppy.debugLogger}});
uppy.use(Uppy.Dashboard, {{trigger: '#uppyT', proudlyDisplayPoweredByUppy: false, theme: 'auto', showProgressDetails: true, doneButtonHandler: ()=>{{location.reload()}}}});
uppy.use(Uppy.XHRUpload, {{endpoint: '{}', fieldName: 'file_to_upload', allowedMetaFields: []}});
</script>
"#, upload_action)))
}
}
@if conf.mkdir_enabled {
Expand Down