add pre-commit config
This commit is contained in:
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: v3.2.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: master
|
||||||
|
hooks:
|
||||||
|
- id: fmt
|
||||||
|
- id: cargo-check
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
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>;
|
||||||
|
|
||||||
|
|||||||
@@ -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(
|
||||||
|
time.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs()
|
.as_secs()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap())
|
.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::*;
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user