Add multipart

This commit is contained in:
Adrian Wozniak 2020-05-01 22:21:28 +02:00
parent 704cddc6e7
commit a069b318bc
4 changed files with 69 additions and 7 deletions

View File

@ -2,20 +2,28 @@ image: archlinux
packages:
- nodejs
- rustup
- yarn
sources:
- https://git.sr.ht/~tsumanu/jirs
environment:
deploy: adrian.wozniak@ita-prog.pl
NODE_ENV: production
DEBUG: false
JIRS_CLIENT_PORT: 80
JIRS_CLIENT_BIND: jirs.ita-prog.pl
JIRS_SERVER_PORT: 80
JIRS_SERVER_BIND: jirs.ita-prog.pl
secrets:
- 7ebab768-e5e4-4c9d-ba57-ec41a72c5665
tasks:
- setup: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sudo sh
- test: |
cd jirs/jirs-client
cd ~/jirs/jirs-client
wasm-pack test --node
- build: |
cd jirs/jirs-client
wasm-pack build --release
cd ~/jirs/jirs-client
yarn
yarn webpack-cli -p --config ./webpack.config.js
- deploy: |
cd jirs
cd ~/jirs

View File

@ -1,6 +1,7 @@
image: shepmaster/rust-nightly
image: archlinux
packages:
- postgresql
- rustup
sources:
- https://git.sr.ht/~tsumanu/jirs
environment:
@ -8,8 +9,14 @@ environment:
secrets:
- 7ebab768-e5e4-4c9d-ba57-ec41a72c5665
tasks:
- build_config: |
cd jirs/jirs-server
echo 'concurrency = 2' >> db.test.toml
echo 'database_url = "postgres://postgres@localhost:5432/jirs_test"' >> db.test.toml
- setup: |
sudo systemctl start postgresql
rustup toolchain install nightly
rustup default nightly
cargo install diesel_cli --no-default-features --features postgres
cd jirs/jirs-server
diesel migration run

View File

@ -1,5 +1,9 @@
# A simplified Jira clone built with seed.rs and actix
[![builds.sr.ht status](https://builds.sr.ht/~tsumanu/jirs.sr.ht.svg)](https://builds.sr.ht/~tsumanu/jirs.sr.ht?)
https://git.sr.ht/~tsumanu/jirs
## Features
* Actor based asynchronous backend
@ -7,6 +11,31 @@
## How to run it
### Config files
```toml
# web.toml
concurrency = 2
port = "5000"
bind = "0.0.0.0"
ssl = false
```
```toml
# db.toml
concurrency = 2
database_url = "postgres://postgres@localhost:5432/jirs"
```
```toml
# mail.toml
concurrency = 2
user = "apikey"
pass = "YOUR-TOKEN"
host = "smtp.sendgrid.net"
from = "contact@jirs.pl"
```
### Local variables
Within `jirs` directory place `.env` file with following content

View File

@ -1,7 +1,25 @@
use actix_multipart::Multipart;
use actix_web::{get, post, web, HttpResponse, Responder};
use futures::{StreamExt, TryStreamExt};
use std::io::Write;
#[post("/")]
async fn upload() -> impl Responder {
async fn upload(mut payload: Multipart) -> impl Responder {
while let Ok(Some(mut field)) = payload.try_next().await {
let content_type = field.content_disposition().unwrap();
let filename = content_type.get_filename().unwrap();
let filepath = format!("./tmp/{}", filename);
// File::create is blocking operation, use threadpool
let mut f = web::block(|| std::fs::File::create(filepath))
.await
.unwrap();
// Field in turn is stream of *Bytes* object
while let Some(chunk) = field.next().await {
let data = chunk.unwrap();
// filesystem operations are blocking, we have to use threadpool
f = web::block(move || f.write_all(&data).map(|_| f)).await?;
}
}
HttpResponse::Ok().json("")
}