Save medias in static/media

Fixes #272
This commit is contained in:
Bat 2018-10-12 20:22:57 +01:00
parent f7c37ca6ca
commit 14969d489c
4 changed files with 3 additions and 13 deletions

3
.gitignore vendored
View File

@ -7,7 +7,8 @@ translations
po/*.po~ po/*.po~
.env .env
Rocket.toml Rocket.toml
media !.gitkeep
static/media
docker-compose.yml docker-compose.yml
*.db *.db
*.sqlite *.sqlite

View File

@ -193,12 +193,6 @@ plm users new --admin
For more information about these commands, and the arguments you can give them, check out [their documentaion](CLI.md). For more information about these commands, and the arguments you can give them, check out [their documentaion](CLI.md).
After that, you are almost done, the last thing to do is to create the media directory, where uploads will be stored:
```bash
mkdir media
```
Finally, you can start Plume with: Finally, you can start Plume with:
```bash ```bash

View File

@ -39,7 +39,7 @@ fn upload(user: User, data: Data, ct: &ContentType, conn: DbConn) -> Redirect {
let ext = filename.rsplitn(2, ".") let ext = filename.rsplitn(2, ".")
.next() .next()
.unwrap(); .unwrap();
let dest = format!("media/{}.{}", GUID::rand().to_string(), ext); let dest = format!("static/media/{}.{}", GUID::rand().to_string(), ext);
if let SavedData::Bytes(ref bytes) = fields[&"file".to_string()][0].data { if let SavedData::Bytes(ref bytes) = fields[&"file".to_string()][0].data {
fs::write(&dest, bytes).expect("Couldn't save upload"); fs::write(&dest, bytes).expect("Couldn't save upload");
@ -110,8 +110,3 @@ fn set_avatar(id: i32, user: User, conn: DbConn) -> Redirect {
user.set_avatar(&*conn, media.id); user.set_avatar(&*conn, media.id);
Redirect::to(uri!(details: id = id)) Redirect::to(uri!(details: id = id))
} }
#[get("/static/media/<file..>", rank = 1)]
fn static_files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("media/").join(file)).ok()
}

0
static/media/.gitkeep Normal file
View File