diff --git a/src/main.rs b/src/main.rs index 5626231..931677c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,7 +149,7 @@ fn logout<'mw>(_req: &mut Request, res.redirect("/") } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] enum SizeTag { Small, Medium, @@ -185,11 +185,21 @@ fn show_image<'mw>(req: &Request, let c: &PgConnection = &req.db_conn(); if let Ok(tphoto) = photos.find(the_id).first::(c) { if req.authorized_user().is_some() || tphoto.is_public() { - let data = get_image_data(req, tphoto, size) - .expect("Get image data"); - res.set(MediaType::Jpeg); - res.set(Expires(HttpDate(time::now() + Duration::days(14)))); - return res.send(data); + if size == SizeTag::Large { + if req.authorized_user().is_some() { + let path = req.photos().get_raw_path(tphoto); + res.set(MediaType::Jpeg); + res.set(Expires(HttpDate(time::now() + + Duration::days(14)))); + return res.send_file(path); + } + } else { + let data = get_image_data(req, tphoto, size) + .expect("Get image data"); + res.set(MediaType::Jpeg); + res.set(Expires(HttpDate(time::now() + Duration::days(14)))); + return res.send(data); + } } } res.not_found("No such image") diff --git a/src/photosdir.rs b/src/photosdir.rs index a834155..f476c2e 100644 --- a/src/photosdir.rs +++ b/src/photosdir.rs @@ -45,6 +45,11 @@ impl PhotosDir { Ok(buf) } + #[allow(dead_code)] + pub fn get_raw_path(&self, photo: Photo) -> PathBuf { + self.basedir.join(photo.path) + } + #[allow(dead_code)] pub fn has_file + ?Sized>(&self, path: &S) -> bool { self.basedir.join(Path::new(path)).is_file() diff --git a/templates/details.rs.html b/templates/details.rs.html index 0ffa348..ebde9b2 100644 --- a/templates/details.rs.html +++ b/templates/details.rs.html @@ -3,12 +3,11 @@ @use templates::page_base; @(lpath: &[Link], user: Option, people: &[Person], places: &[Place], tags: &[Tag], position: Option, attribution: Option, camera: Option, time: String, photo: Photo) -@:page_base("Photo details", lpath, user, { +@:page_base("Photo details", lpath, &user, {
-

@photo.path

- + @if user.is_some() {

@photo.path

} @if let Some(g) = photo.grade {

Betyg: @g

}

Tid: @time

@if !people.is_empty() { diff --git a/templates/groups.rs.html b/templates/groups.rs.html index f56200c..548a0fa 100644 --- a/templates/groups.rs.html +++ b/templates/groups.rs.html @@ -3,7 +3,7 @@ @(title: &str, lpath: &[Link], user: Option, groups: &[Group]) -@:page_base(title, lpath, user, { +@:page_base(title, lpath, &user, {
@if groups.is_empty() {

Inga bilder.

diff --git a/templates/head.rs.html b/templates/head.rs.html index 824d33b..e368e39 100644 --- a/templates/head.rs.html +++ b/templates/head.rs.html @@ -1,6 +1,6 @@ @use ::Link; -@(lpath: &[Link], user: Option) +@(lpath: &[Link], user: &Option)
Bilder @@ -10,6 +10,6 @@ · Personer · Platser · Denna dag -@if let Some(u) = user {@u (log out)} +@if let &Some(ref u) = user {@u (log out)} else {(log in)}
diff --git a/templates/index.rs.html b/templates/index.rs.html index 7a6f8f2..8f79d7b 100644 --- a/templates/index.rs.html +++ b/templates/index.rs.html @@ -4,7 +4,7 @@ @(title: &str, lpath: &[Link], user: Option, photos: &[Photo]) -@:page_base(title, lpath, user, { +@:page_base(title, lpath, &user, {
@for p in photos {@:img_link(p)}
diff --git a/templates/login.rs.html b/templates/login.rs.html index 35adcf2..4c286f8 100644 --- a/templates/login.rs.html +++ b/templates/login.rs.html @@ -2,7 +2,7 @@ @() -@:page_base("login", &[], None, { +@:page_base("login", &[], &None, {

diff --git a/templates/page_base.rs.html b/templates/page_base.rs.html index 418be86..20f67a4 100644 --- a/templates/page_base.rs.html +++ b/templates/page_base.rs.html @@ -2,7 +2,7 @@ @use templates::head; @use templates::statics::style_css; -@(title: &str, lpath: &[Link], user: Option, content: Content) +@(title: &str, lpath: &[Link], user: &Option, content: Content) diff --git a/templates/people.rs.html b/templates/people.rs.html index 2856781..2020aa5 100644 --- a/templates/people.rs.html +++ b/templates/people.rs.html @@ -2,7 +2,7 @@ @use templates::page_base; @(user: Option, people: &[Person]) -@:page_base("Photo people", &[], user, { +@:page_base("Photo people", &[], &user, {
    @for p in people {
  • @p.person_name diff --git a/templates/person.rs.html b/templates/person.rs.html index 8d83a2d..37b240f 100644 --- a/templates/person.rs.html +++ b/templates/person.rs.html @@ -2,7 +2,7 @@ @use templates::{page_base, img_link}; @(user: Option, photos: &[Photo], person: Person) -@:page_base(&format!("Photos with {}", person.person_name), &[], user, { +@:page_base(&format!("Photos with {}", person.person_name), &[], &user, {
    @for p in photos {@:img_link(p)}
    diff --git a/templates/place.rs.html b/templates/place.rs.html index 052d885..2012594 100644 --- a/templates/place.rs.html +++ b/templates/place.rs.html @@ -2,7 +2,7 @@ @use templates::{page_base, img_link}; @(user: Option, photos: &[Photo], place: Place) -@:page_base(&format!("Photos from {}", place.place_name), &[], user, { +@:page_base(&format!("Photos from {}", place.place_name), &[], &user, {
    @for p in photos {@:img_link(p)}
    diff --git a/templates/places.rs.html b/templates/places.rs.html index dc8b957..008804d 100644 --- a/templates/places.rs.html +++ b/templates/places.rs.html @@ -3,7 +3,7 @@ @(user: Option, places: &[Place]) -@:page_base("Photo places", &[], user, { +@:page_base("Photo places", &[], &user, {
      @for p in places {
    • @p.place_name diff --git a/templates/tag.rs.html b/templates/tag.rs.html index dc97fe2..23cffdd 100644 --- a/templates/tag.rs.html +++ b/templates/tag.rs.html @@ -3,7 +3,7 @@ @(user: Option, photos: &[Photo], tag: Tag) -@:page_base(&format!("Photos tagged {}", tag.tag_name), &[], user, { +@:page_base(&format!("Photos tagged {}", tag.tag_name), &[], &user, {
      @for p in photos {@:img_link(p)}
      diff --git a/templates/tags.rs.html b/templates/tags.rs.html index 8c77496..83cf38d 100644 --- a/templates/tags.rs.html +++ b/templates/tags.rs.html @@ -2,7 +2,7 @@ @use templates::page_base; @(user: Option, tags: &[Tag]) -@:page_base("Photo tags", &[], user, { +@:page_base("Photo tags", &[], &user, {