forked from neri/datatrash
add readme, extract init-db script
This commit is contained in:
parent
827baf8eec
commit
82b2bd4075
|
@ -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
|
|
@ -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)
|
||||
);
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
14
src/main.rs
14
src/main.rs
|
@ -114,18 +114,7 @@ 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)
|
||||
)
|
||||
"
|
||||
)
|
||||
sqlx::query_file!("./init-db.sql")
|
||||
.execute(&pool)
|
||||
.await
|
||||
.expect("could not create table Files");
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue