Large is full.

The "large" version of an image is the full original file.  Only
logged-in users may access the large version.
This commit is contained in:
Rasmus Kaj 2017-02-12 15:24:39 +01:00
parent b5f6c53448
commit abf5dcf384
14 changed files with 35 additions and 21 deletions

View File

@ -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::<Photo>(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")

View File

@ -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<S: AsRef<OsStr> + ?Sized>(&self, path: &S) -> bool {
self.basedir.join(Path::new(path)).is_file()

View File

@ -3,12 +3,11 @@
@use templates::page_base;
@(lpath: &[Link], user: Option<String>, people: &[Person], places: &[Place], tags: &[Tag], position: Option<Coord>, attribution: Option<String>, camera: Option<Camera>, time: String, photo: Photo)
@:page_base("Photo details", lpath, user, {
@:page_base("Photo details", lpath, &user, {
<div class="details">
<div class="item"><img src="/img/@photo.id-m.jpg"></div>
<div class="meta">
<p><a href="/img/@photo.id-l.jpg">@photo.path</a></p>
@if user.is_some() {<p><a href="/img/@photo.id-l.jpg">@photo.path</a></p>}
@if let Some(g) = photo.grade {<p>Betyg: @g</p>}
<p>Tid: @time</p>
@if !people.is_empty() {

View File

@ -3,7 +3,7 @@
@(title: &str, lpath: &[Link], user: Option<String>, groups: &[Group])
@:page_base(title, lpath, user, {
@:page_base(title, lpath, &user, {
<div class="group">
@if groups.is_empty() {
<p>Inga bilder.</p>

View File

@ -1,6 +1,6 @@
@use ::Link;
@(lpath: &[Link], user: Option<String>)
@(lpath: &[Link], user: &Option<String>)
<header>
<span><a href="/">Bilder</a>
@ -10,6 +10,6 @@
<span>· <a href="/person/">Personer</a></span>
<span>· <a href="/place/">Platser</a></span>
<span>· <a href="/thisday">Denna dag</a></span>
@if let Some(u) = user {<span class="user">@u (<a href="/logout">log out</a>)</span>}
@if let &Some(ref u) = user {<span class="user">@u (<a href="/logout">log out</a>)</span>}
else {<span class="user">(<a href="/login">log in</a>)</span>}
</header>

View File

@ -4,7 +4,7 @@
@(title: &str, lpath: &[Link], user: Option<String>, photos: &[Photo])
@:page_base(title, lpath, user, {
@:page_base(title, lpath, &user, {
<div class="group">
@for p in photos {@:img_link(p)}
</div>

View File

@ -2,7 +2,7 @@
@()
@:page_base("login", &[], None, {
@:page_base("login", &[], &None, {
<form action="/login" method="post">
<p><label for="user">User:</label>
<input id="user" name="user"></p>

View File

@ -2,7 +2,7 @@
@use templates::head;
@use templates::statics::style_css;
@(title: &str, lpath: &[Link], user: Option<String>, content: Content)
@(title: &str, lpath: &[Link], user: &Option<String>, content: Content)
<!doctype html>
<html>

View File

@ -2,7 +2,7 @@
@use templates::page_base;
@(user: Option<String>, people: &[Person])
@:page_base("Photo people", &[], user, {
@:page_base("Photo people", &[], &user, {
<ul class="allpeople">
@for p in people {
<li><a href="/person/@p.slug">@p.person_name</a>

View File

@ -2,7 +2,7 @@
@use templates::{page_base, img_link};
@(user: Option<String>, photos: &[Photo], person: Person)
@:page_base(&format!("Photos with {}", person.person_name), &[], user, {
@:page_base(&format!("Photos with {}", person.person_name), &[], &user, {
<div class="group">
@for p in photos {@:img_link(p)}
</div>

View File

@ -2,7 +2,7 @@
@use templates::{page_base, img_link};
@(user: Option<String>, photos: &[Photo], place: Place)
@:page_base(&format!("Photos from {}", place.place_name), &[], user, {
@:page_base(&format!("Photos from {}", place.place_name), &[], &user, {
<div class="group">
@for p in photos {@:img_link(p)}
</div>

View File

@ -3,7 +3,7 @@
@(user: Option<String>, places: &[Place])
@:page_base("Photo places", &[], user, {
@:page_base("Photo places", &[], &user, {
<ul class="allplaces">
@for p in places {
<li><a href="/place/@p.slug">@p.place_name</a>

View File

@ -3,7 +3,7 @@
@(user: Option<String>, photos: &[Photo], tag: Tag)
@:page_base(&format!("Photos tagged {}", tag.tag_name), &[], user, {
@:page_base(&format!("Photos tagged {}", tag.tag_name), &[], &user, {
<div class="group">
@for p in photos {@:img_link(p)}
</div>

View File

@ -2,7 +2,7 @@
@use templates::page_base;
@(user: Option<String>, tags: &[Tag])
@:page_base("Photo tags", &[], user, {
@:page_base("Photo tags", &[], &user, {
<ul class="alltags">
@for tag in tags {
<li><a href="/tag/@tag.slug">@tag.tag_name</a>