add readme, extract init-db script

This commit is contained in:
neri 2020-07-09 22:01:25 +02:00
parent 827baf8eec
commit 82b2bd4075
4 changed files with 43 additions and 16 deletions

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# datatrash
A file and text uploading service with configurable time limit
![Application screenshot](./screenshot.png)
## compiling
Compiling is a little strange.
The SQL-statements are checked for correctness at compile-time, unfortunately this means that the
database needs to be running at compile-time too.
To get set up:
- Start a postgresql somewhere
- Set its connection url in the `.env` file
- Run the `init-db.sql` script in the database (`cat init-db.sql | psql`)
- Build the project `cargo build --release`
## running & config
At runtime the environment variable `DATABASE_URL` must be set (e.g. `postgres://localhost`).
A folder named `files` needs to be created next to the application.
Other things are not configurable yet.
- The application listens on port 8000
- The server url is `http://localhost:8000/`
- The upload limit is 8MiB
- The maximum filename length is 255
- The uploaded files are stored in the `files` directory

8
init-db.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS files (
id serial,
file_id varchar(255) not null,
file_name varchar(255) not null,
valid_till timestamp not null,
kind varchar(255) not null,
primary key (id)
);

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -114,18 +114,7 @@ async fn setup_db() -> PgPool {
.await .await
.expect("could not create db pool"); .expect("could not create db pool");
sqlx::query!( sqlx::query_file!("./init-db.sql")
"
CREATE TABLE IF NOT EXISTS files (
id serial,
file_id varchar(255) not null,
file_name varchar(255) not null,
valid_till timestamp not null,
kind varchar(255) not null,
primary key (id)
)
"
)
.execute(&pool) .execute(&pool)
.await .await
.expect("could not create table Files"); .expect("could not create table Files");
@ -136,7 +125,6 @@ async fn setup_db() -> PgPool {
#[actix_rt::main] #[actix_rt::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "warn,datatrash=info,actix_web=info"); std::env::set_var("RUST_LOG", "warn,datatrash=info,actix_web=info");
std::env::set_var("DATABASE_URL", "postgresql://localhost");
env_logger::init(); env_logger::init();
let pool: PgPool = setup_db().await; let pool: PgPool = setup_db().await;