-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
182 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "files" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rwf = { version = "0.1.7", path = "../../rwf" } | ||
tokio = { version = "1", features = ["full"] } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use rwf::prelude::*; | ||
|
||
#[derive(Default, macros::PageController)] | ||
pub struct Upload; | ||
|
||
#[async_trait] | ||
impl PageController for Upload { | ||
async fn get(&self, _req: &Request) -> Result<Response, Error> { | ||
render!("templates/upload.html") | ||
} | ||
|
||
async fn post(&self, req: &Request) -> Result<Response, Error> { | ||
let form_data = req.form_data()?; | ||
if let Some(file) = form_data.file("file") { | ||
let redirect = format!("/ok?name={}&size={}", file.name, file.body.len()); | ||
Ok(Response::new().redirect(redirect)) | ||
} else { | ||
Ok(Response::bad_request()) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct UploadOk; | ||
|
||
#[async_trait] | ||
impl Controller for UploadOk { | ||
async fn handle(&self, req: &Request) -> Result<Response, Error> { | ||
let name = req.query().get_required::<String>("name")?; | ||
let size = req.query().get_required::<i64>("size")?; | ||
|
||
render!("templates/ok.html", | ||
"name" => rwf::http::urlencode(&name), | ||
"size" => size | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mod controllers; | ||
mod models; | ||
|
||
use rwf::http::{self, Server}; | ||
use rwf::prelude::*; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), http::Error> { | ||
Logger::init(); | ||
|
||
Server::new(vec![ | ||
route!("/" => controllers::Upload), | ||
route!("/ok" => controllers::UploadOk), | ||
]) | ||
.launch("0.0.0.0:8000") | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<head> | ||
<%= rwf_head() %> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> | ||
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<%% "templates/head.html" %> | ||
<body> | ||
<div class="container my-5"> | ||
<h3 class="mb-4">Upload successful</h3> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>File name</th> | ||
<th>File size</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="pe-5"><%= name %></td> | ||
<td class=""><%= size %> bytes</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div class="d-flex justify-content-end"> | ||
<a href="/" class="btn btn-primary btn-lg">Back</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<%% "templates/head.html" %> | ||
<body> | ||
<div class="container my-5"> | ||
<h3 class="mb-4">Upload file</h3> | ||
<form method="post" action="/" enctype="multipart/form-data"> | ||
<%= csrf_token() %> | ||
<div class="mb-3"> | ||
<label class="form-label">Comment</label> | ||
<input type="text" name="comment" class="form-control"> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="form-label">Upload file</label> | ||
<input type="file" name="file" class="form-control"> | ||
</div> | ||
|
||
<div class="d-flex justify-content-end"> | ||
<button class="btn btn-primary" type="submit"> | ||
Upload | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters