diff --git a/README.md b/README.md new file mode 100644 index 0000000..9b66880 --- /dev/null +++ b/README.md @@ -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 diff --git a/init-db.sql b/init-db.sql new file mode 100644 index 0000000..ebbeb9b --- /dev/null +++ b/init-db.sql @@ -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) +); diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..f8fdb45 Binary files /dev/null and b/screenshot.png differ diff --git a/src/main.rs b/src/main.rs index e1c9f46..c608c8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,21 +114,10 @@ async fn setup_db() -> PgPool { .await .expect("could not create db pool"); - sqlx::query!( - " - 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) - .await - .expect("could not create table Files"); + sqlx::query_file!("./init-db.sql") + .execute(&pool) + .await + .expect("could not create table Files"); pool } @@ -136,7 +125,6 @@ async fn setup_db() -> PgPool { #[actix_rt::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "warn,datatrash=info,actix_web=info"); - std::env::set_var("DATABASE_URL", "postgresql://localhost"); env_logger::init(); let pool: PgPool = setup_db().await;