Better avoiding of raw images.
And get rid of some 'use ...::*'.
This commit is contained in:
parent
b8f671c7bf
commit
961e04d257
47
src/main.rs
47
src/main.rs
@ -218,7 +218,7 @@ fn show_image<'mw>(req: &Request,
|
|||||||
the_id: i32,
|
the_id: i32,
|
||||||
size: SizeTag)
|
size: SizeTag)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::photos;
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
if let Ok(tphoto) = photos.find(the_id).first::<Photo>(c) {
|
if let Ok(tphoto) = photos.find(the_id).first::<Photo>(c) {
|
||||||
if req.authorized_user().is_some() || tphoto.is_public() {
|
if req.authorized_user().is_some() || tphoto.is_public() {
|
||||||
@ -255,10 +255,10 @@ fn tag_one<'mw>(req: &mut Request,
|
|||||||
res: Response<'mw>,
|
res: Response<'mw>,
|
||||||
tslug: String)
|
tslug: String)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::tags::dsl::*;
|
use rphotos::schema::tags::dsl::{slug, tags};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
if let Ok(tag) = tags.filter(slug.eq(tslug)).first::<Tag>(c) {
|
if let Ok(tag) = tags.filter(slug.eq(tslug)).first::<Tag>(c) {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::id;
|
||||||
use rphotos::schema::photo_tags::dsl::{photo_id, photo_tags, tag_id};
|
use rphotos::schema::photo_tags::dsl::{photo_id, photo_tags, tag_id};
|
||||||
return render!(res, "templates/tag.tpl", {
|
return render!(res, "templates/tag.tpl", {
|
||||||
user: Option<String> = req.authorized_user(),
|
user: Option<String> = req.authorized_user(),
|
||||||
@ -291,10 +291,10 @@ fn place_one<'mw>(req: &mut Request,
|
|||||||
res: Response<'mw>,
|
res: Response<'mw>,
|
||||||
tslug: String)
|
tslug: String)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::places::dsl::*;
|
use rphotos::schema::places::dsl::{places, slug};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
if let Ok(place) = places.filter(slug.eq(tslug)).first::<Place>(c) {
|
if let Ok(place) = places.filter(slug.eq(tslug)).first::<Place>(c) {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::id;
|
||||||
use rphotos::schema::photo_places::dsl::{photo_id, photo_places,
|
use rphotos::schema::photo_places::dsl::{photo_id, photo_places,
|
||||||
place_id};
|
place_id};
|
||||||
return render!(res, "templates/place.tpl", {
|
return render!(res, "templates/place.tpl", {
|
||||||
@ -328,10 +328,10 @@ fn person_one<'mw>(req: &mut Request,
|
|||||||
res: Response<'mw>,
|
res: Response<'mw>,
|
||||||
tslug: String)
|
tslug: String)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::people::dsl::*;
|
use rphotos::schema::people::dsl::{people, slug};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
if let Ok(person) = people.filter(slug.eq(tslug)).first::<Person>(c) {
|
if let Ok(person) = people.filter(slug.eq(tslug)).first::<Person>(c) {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::id;
|
||||||
use rphotos::schema::photo_people::dsl::{person_id, photo_id,
|
use rphotos::schema::photo_people::dsl::{person_id, photo_id,
|
||||||
photo_people};
|
photo_people};
|
||||||
return render!(res, "templates/person.tpl", {
|
return render!(res, "templates/person.tpl", {
|
||||||
@ -420,7 +420,7 @@ fn all_years<'mw>(req: &mut Request,
|
|||||||
res: Response<'mw>)
|
res: Response<'mw>)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
|
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::{date, grade};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
|
|
||||||
return render!(res, "templates/groups.tpl", {
|
return render!(res, "templates/groups.tpl", {
|
||||||
@ -438,7 +438,6 @@ fn all_years<'mw>(req: &mut Request,
|
|||||||
.load::<(Option<f64>, i64)>(c).unwrap()
|
.load::<(Option<f64>, i64)>(c).unwrap()
|
||||||
.iter().map(|&(year, count)| {
|
.iter().map(|&(year, count)| {
|
||||||
let q = Photo::query(req.authorized_user().is_some())
|
let q = Photo::query(req.authorized_user().is_some())
|
||||||
// .filter(path.like("%.JPG"))
|
|
||||||
.order((grade.desc(), date.asc()))
|
.order((grade.desc(), date.asc()))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
let photo =
|
let photo =
|
||||||
@ -468,7 +467,7 @@ fn months_in_year<'mw>(req: &mut Request,
|
|||||||
res: Response<'mw>,
|
res: Response<'mw>,
|
||||||
year: i32)
|
year: i32)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::{date, grade};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
|
|
||||||
render!(res, "templates/groups.tpl", {
|
render!(res, "templates/groups.tpl", {
|
||||||
@ -496,7 +495,6 @@ fn months_in_year<'mw>(req: &mut Request,
|
|||||||
let photo = Photo::query(req.authorized_user().is_some())
|
let photo = Photo::query(req.authorized_user().is_some())
|
||||||
.filter(date.ge(fromdate))
|
.filter(date.ge(fromdate))
|
||||||
.filter(date.lt(todate))
|
.filter(date.lt(todate))
|
||||||
// .filter(path.like("%.JPG"))
|
|
||||||
.order((grade.desc(), date.asc()))
|
.order((grade.desc(), date.asc()))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first::<Photo>(c).unwrap();
|
.first::<Photo>(c).unwrap();
|
||||||
@ -516,7 +514,7 @@ fn days_in_month<'mw>(req: &mut Request,
|
|||||||
year: i32,
|
year: i32,
|
||||||
month: u32)
|
month: u32)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::{date, grade};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
|
|
||||||
render!(res, "templates/groups.tpl", {
|
render!(res, "templates/groups.tpl", {
|
||||||
@ -542,7 +540,6 @@ fn days_in_month<'mw>(req: &mut Request,
|
|||||||
let photo = Photo::query(req.authorized_user().is_some())
|
let photo = Photo::query(req.authorized_user().is_some())
|
||||||
.filter(date.ge(fromdate))
|
.filter(date.ge(fromdate))
|
||||||
.filter(date.lt(fromdate + ChDuration::days(1)))
|
.filter(date.lt(fromdate + ChDuration::days(1)))
|
||||||
// .filter(path.like("%.JPG"))
|
|
||||||
.order((grade.desc(), date.asc()))
|
.order((grade.desc(), date.asc()))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first::<Photo>(c).unwrap();
|
.first::<Photo>(c).unwrap();
|
||||||
@ -564,13 +561,7 @@ fn all_for_day<'mw>(req: &mut Request,
|
|||||||
day: u32)
|
day: u32)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0);
|
let thedate = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0);
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::{date, grade};
|
||||||
let pq = photos
|
|
||||||
.filter(date.ge(thedate))
|
|
||||||
.filter(date.lt(thedate + ChDuration::days(1)))
|
|
||||||
// .filter(path.like("%.JPG"))
|
|
||||||
.order((grade.desc(), date.asc()))
|
|
||||||
.limit(500);
|
|
||||||
|
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
render!(res, "templates/index.tpl", {
|
render!(res, "templates/index.tpl", {
|
||||||
@ -579,20 +570,19 @@ fn all_for_day<'mw>(req: &mut Request,
|
|||||||
Link::month(year, month)],
|
Link::month(year, month)],
|
||||||
title: String = format!("Photos from {} {} {}",
|
title: String = format!("Photos from {} {} {}",
|
||||||
day, monthname(month), year),
|
day, monthname(month), year),
|
||||||
photos: Vec<Photo> =
|
photos: Vec<Photo> = Photo::query(req.authorized_user().is_some())
|
||||||
if req.authorized_user().is_none() {
|
.filter(date.ge(thedate))
|
||||||
pq.filter(grade.ge(&rphotos::models::MIN_PUBLIC_GRADE))
|
.filter(date.lt(thedate + ChDuration::days(1)))
|
||||||
.load(c).unwrap()
|
.order((grade.desc(), date.asc()))
|
||||||
} else {
|
.limit(500)
|
||||||
pq.load(c).unwrap()
|
.load(c).unwrap()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_this_day<'mw>(req: &mut Request,
|
fn on_this_day<'mw>(req: &mut Request,
|
||||||
res: Response<'mw>)
|
res: Response<'mw>)
|
||||||
-> MiddlewareResult<'mw> {
|
-> MiddlewareResult<'mw> {
|
||||||
use rphotos::schema::photos::dsl::*;
|
use rphotos::schema::photos::dsl::{date, grade};
|
||||||
let c: &PgConnection = &req.db_conn();
|
let c: &PgConnection = &req.db_conn();
|
||||||
|
|
||||||
let (month, day) = {
|
let (month, day) = {
|
||||||
@ -621,7 +611,6 @@ fn on_this_day<'mw>(req: &mut Request,
|
|||||||
let photo = Photo::query(req.authorized_user().is_some())
|
let photo = Photo::query(req.authorized_user().is_some())
|
||||||
.filter(date.ge(fromdate))
|
.filter(date.ge(fromdate))
|
||||||
.filter(date.lt(fromdate + ChDuration::days(1)))
|
.filter(date.lt(fromdate + ChDuration::days(1)))
|
||||||
// .filter(path.like("%.JPG"))
|
|
||||||
.order((grade.desc(), date.asc()))
|
.order((grade.desc(), date.asc()))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first::<Photo>(c).unwrap();
|
.first::<Photo>(c).unwrap();
|
||||||
|
@ -63,9 +63,11 @@ impl Photo {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn query<'a>(auth: bool) -> photos::BoxedQuery<'a, Pg> {
|
pub fn query<'a>(auth: bool) -> photos::BoxedQuery<'a, Pg> {
|
||||||
use super::schema::photos::dsl::{grade, photos};
|
use super::schema::photos::dsl::{grade, photos, path};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
let result = photos.into_boxed();
|
let result = photos
|
||||||
|
.filter(path.not_like("%.CR2"))
|
||||||
|
.into_boxed();
|
||||||
if !auth {
|
if !auth {
|
||||||
result.filter(grade.ge(MIN_PUBLIC_GRADE))
|
result.filter(grade.ge(MIN_PUBLIC_GRADE))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user