Merge branch 'main' of gitea:jheuel/photos
This commit is contained in:
@@ -6,4 +6,6 @@ steps:
|
|||||||
- name: pre-commit
|
- name: pre-commit
|
||||||
image: iamthefij/drone-pre-commit:latest
|
image: iamthefij/drone-pre-commit:latest
|
||||||
commands:
|
commands:
|
||||||
|
- curl https://sh.rustup.rs -sSf | bash -s -- -y
|
||||||
|
- export PATH="/root/.cargo/bin:$${PATH}"
|
||||||
- pre-commit run --all-files
|
- pre-commit run --all-files
|
||||||
|
|||||||
2
.env
2
.env
@@ -1 +1 @@
|
|||||||
DATABASE_URL=postgres://user:password@localhost/diesel_demo
|
DATABASE_URL=postgres://user:password@localhost/diesel_demo
|
||||||
|
|||||||
33
.github/workflows/rust.yml
vendored
Normal file
33
.github/workflows/rust.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: pre-commit
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-commit:
|
||||||
|
name: pre-commit
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-python@v3
|
||||||
|
- uses: pre-commit/action@v3.0.0
|
||||||
|
test:
|
||||||
|
name: tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install stable toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Run cargo test
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
13
.pre-commit-config.yaml
Normal file
13
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.3.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
|
- repo: https://github.com/doublify/pre-commit-rust
|
||||||
|
rev: v1.0
|
||||||
|
hooks:
|
||||||
|
- id: fmt
|
||||||
|
- id: cargo-check
|
||||||
@@ -19,4 +19,4 @@ dotenv = "0.15.0"
|
|||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
DROP TABLE pictures
|
DROP TABLE pictures
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ CREATE TABLE pictures (
|
|||||||
exposure_program VARCHAR,
|
exposure_program VARCHAR,
|
||||||
exposure_compensation VARCHAR,
|
exposure_compensation VARCHAR,
|
||||||
thumbnail VARCHAR
|
thumbnail VARCHAR
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
use backend::models::*;
|
use backend::models::*;
|
||||||
use diesel::prelude::*;
|
|
||||||
use backend::*;
|
use backend::*;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
type DbError = Box<dyn std::error::Error + Send + Sync>;
|
type DbError = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
pub fn list_pictures(conn: &PgConnection) -> Result<Vec<Picture>, DbError> {
|
pub fn list_pictures(conn: &PgConnection) -> Result<Vec<Picture>, DbError> {
|
||||||
use self::schema::pictures::dsl::*;
|
use self::schema::pictures::dsl::*;
|
||||||
|
|
||||||
Ok(pictures
|
Ok(pictures
|
||||||
.limit(50)
|
.limit(50)
|
||||||
.order_by(created_at.desc())
|
.order_by(created_at.desc())
|
||||||
.load::<Picture>(conn)?)
|
.load::<Picture>(conn)?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
use backend::create_picture;
|
use backend::create_picture;
|
||||||
use backend::models::NewPicture;
|
|
||||||
use backend::establish_connection;
|
use backend::establish_connection;
|
||||||
|
use backend::models::NewPicture;
|
||||||
|
|
||||||
// use backend::*;
|
// use backend::*;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -123,17 +123,18 @@ fn main() {
|
|||||||
|
|
||||||
println!("pe = {}", serde_json::to_string_pretty(pe).unwrap());
|
println!("pe = {}", serde_json::to_string_pretty(pe).unwrap());
|
||||||
|
|
||||||
|
|
||||||
let created_at: Option<i32> = if let Some(c) = pe.created_at {
|
let created_at: Option<i32> = if let Some(c) = pe.created_at {
|
||||||
Some(c)
|
Some(c)
|
||||||
} else {
|
} else {
|
||||||
let metadata = fs::metadata(&path.path()).unwrap();
|
let metadata = fs::metadata(&path.path()).unwrap();
|
||||||
if let Ok(time) = metadata.created() {
|
if let Ok(time) = metadata.created() {
|
||||||
Some(time.duration_since(UNIX_EPOCH)
|
Some(
|
||||||
.unwrap()
|
time.duration_since(UNIX_EPOCH)
|
||||||
.as_secs()
|
.unwrap()
|
||||||
.try_into()
|
.as_secs()
|
||||||
.unwrap())
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
println!("Not supported on this platform or filesystem");
|
println!("Not supported on this platform or filesystem");
|
||||||
None
|
None
|
||||||
@@ -161,10 +162,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let pic = create_picture(&connection, new_picture);
|
let pic = create_picture(&connection, new_picture);
|
||||||
println!(
|
println!("Created picture with filepath={} and id={}", filepath, pic);
|
||||||
"Created picture with filepath={} and id={}",
|
|
||||||
filepath, pic
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
use self::models::*;
|
use self::models::*;
|
||||||
use diesel::prelude::*;
|
|
||||||
use backend::*;
|
use backend::*;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use self::schema::pictures::dsl::*;
|
use self::schema::pictures::dsl::*;
|
||||||
@@ -18,4 +18,4 @@ fn main() {
|
|||||||
println!("filepath: {}", picture.filepath);
|
println!("filepath: {}", picture.filepath);
|
||||||
println!("\tid: {}", picture.id);
|
println!("\tid: {}", picture.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ extern crate dotenv;
|
|||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
|
|
||||||
use self::models::{NewPicture};
|
use self::models::NewPicture;
|
||||||
use diesel::prelude::*;
|
|
||||||
use diesel::pg::PgConnection;
|
use diesel::pg::PgConnection;
|
||||||
|
use diesel::prelude::*;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub fn establish_connection() -> PgConnection {
|
pub fn establish_connection() -> PgConnection {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
let database_url = env::var("DATABASE_URL")
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||||
.expect("DATABASE_URL must be set");
|
|
||||||
PgConnection::establish(&database_url)
|
PgConnection::establish(&database_url)
|
||||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||||
}
|
}
|
||||||
@@ -24,7 +23,7 @@ pub fn create_picture<'a>(conn: &PgConnection, new_picture: NewPicture) -> usize
|
|||||||
use schema::pictures;
|
use schema::pictures;
|
||||||
|
|
||||||
diesel::insert_into(pictures::table)
|
diesel::insert_into(pictures::table)
|
||||||
.values(&new_picture)
|
.values(&new_picture)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.expect("Error saving new picture")
|
.expect("Error saving new picture")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,30 +114,3 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use actix_web::test;
|
|
||||||
|
|
||||||
#[actix_web::test]
|
|
||||||
async fn user_routes() {
|
|
||||||
std::env::set_var("RUST_LOG", "actix_web=debug");
|
|
||||||
env_logger::init();
|
|
||||||
dotenv::dotenv().ok();
|
|
||||||
|
|
||||||
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
|
|
||||||
let manager = ConnectionManager::<PgConnection>::new(connspec);
|
|
||||||
let pool = r2d2::Pool::builder()
|
|
||||||
.build(manager)
|
|
||||||
.expect("Failed to create pool.");
|
|
||||||
|
|
||||||
let _app = test::init_service(
|
|
||||||
App::new()
|
|
||||||
.app_data(web::Data::new(pool.clone()))
|
|
||||||
.wrap(middleware::Logger::default()), // .service(get_user)
|
|
||||||
// .service(add_user),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ license = "MIT"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
pub struct OutputPicture {
|
pub struct OutputPicture {
|
||||||
pub thumbnail: Option<String>,
|
pub thumbnail: Option<String>,
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use common::OutputPicture;
|
|||||||
use pathfinding::prelude::dijkstra;
|
use pathfinding::prelude::dijkstra;
|
||||||
use weblog::console_log;
|
use weblog::console_log;
|
||||||
|
|
||||||
|
|
||||||
pub fn get_common_height(row: &[OutputPicture], container_width: u32, margin: u32) -> f32 {
|
pub fn get_common_height(row: &[OutputPicture], container_width: u32, margin: u32) -> f32 {
|
||||||
let row_width: u32 = container_width - row.len() as u32 * (margin * 2);
|
let row_width: u32 = container_width - row.len() as u32 * (margin * 2);
|
||||||
let total_aspect_ratio: f32 = row
|
let total_aspect_ratio: f32 = row
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ pub mod grid;
|
|||||||
pub use grid::Grid;
|
pub use grid::Grid;
|
||||||
|
|
||||||
pub mod picture;
|
pub mod picture;
|
||||||
pub use picture::Picture;
|
pub use picture::Picture;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello world!")
|
println!("Hello world!")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user