clippy fixes, no default feature compile fix
parent
0058a9fcdd
commit
0f3dd88193
|
@ -269,8 +269,8 @@ pub fn resolve_path_cached(
|
||||||
|
|
||||||
pub fn initialize_hier(connection: &UpEndConnection) -> Result<()> {
|
pub fn initialize_hier(connection: &UpEndConnection) -> Result<()> {
|
||||||
connection.insert_entry(Entry::try_from(&*HIER_INVARIANT)?)?;
|
connection.insert_entry(Entry::try_from(&*HIER_INVARIANT)?)?;
|
||||||
upend_insert_addr!(&connection, HIER_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
upend_insert_addr!(connection, HIER_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
||||||
upend_insert_val!(&connection, HIER_ADDR, TYPE_HAS_ATTR, HIER_HAS_ATTR);
|
upend_insert_val!(connection, HIER_ADDR, TYPE_HAS_ATTR, HIER_HAS_ATTR);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,15 +137,15 @@ impl UpEndDatabase {
|
||||||
|
|
||||||
trace!("Initializing types...");
|
trace!("Initializing types...");
|
||||||
connection.insert_entry(Entry::try_from(&*TYPE_INVARIANT)?)?;
|
connection.insert_entry(Entry::try_from(&*TYPE_INVARIANT)?)?;
|
||||||
upend_insert_addr!(&connection, TYPE_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
upend_insert_addr!(connection, TYPE_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
||||||
upend_insert_val!(&connection, TYPE_ADDR, TYPE_HAS_ATTR, TYPE_HAS_ATTR);
|
upend_insert_val!(connection, TYPE_ADDR, TYPE_HAS_ATTR, TYPE_HAS_ATTR);
|
||||||
|
|
||||||
initialize_hier(&connection)?;
|
initialize_hier(&connection)?;
|
||||||
|
|
||||||
Ok(OpenResult { db, new })
|
Ok(OpenResult { db, new })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connection(self: &Self) -> Result<UpEndConnection> {
|
pub fn connection(&self) -> Result<UpEndConnection> {
|
||||||
Ok(UpEndConnection(self.pool.get()?))
|
Ok(UpEndConnection(self.pool.get()?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ impl UpEndDatabase {
|
||||||
pub struct UpEndConnection(PooledConnection<ConnectionManager<SqliteConnection>>);
|
pub struct UpEndConnection(PooledConnection<ConnectionManager<SqliteConnection>>);
|
||||||
|
|
||||||
impl UpEndConnection {
|
impl UpEndConnection {
|
||||||
pub fn execute<S: AsRef<str>>(self: &Self, query: S) -> Result<usize, diesel::result::Error> {
|
pub fn execute<S: AsRef<str>>(&self, query: S) -> Result<usize, diesel::result::Error> {
|
||||||
self.0.execute(query.as_ref())
|
self.0.execute(query.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ impl UpEndConnection {
|
||||||
self.0.transaction(f)
|
self.0.transaction(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_file(self: &Self, file: models::NewFile) -> Result<usize> {
|
pub fn insert_file(&self, file: models::NewFile) -> Result<usize> {
|
||||||
use crate::database::inner::schema::files;
|
use crate::database::inner::schema::files;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -179,7 +179,7 @@ impl UpEndConnection {
|
||||||
.execute(&self.0)?)
|
.execute(&self.0)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_file(self: &Self, obj_hash: Hash) -> Result<Vec<models::File>> {
|
pub fn retrieve_file(&self, obj_hash: Hash) -> Result<Vec<models::File>> {
|
||||||
use crate::database::inner::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
let matches = files
|
let matches = files
|
||||||
|
@ -190,13 +190,13 @@ impl UpEndConnection {
|
||||||
Ok(matches)
|
Ok(matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_all_files(self: &Self) -> Result<Vec<models::File>> {
|
pub fn retrieve_all_files(&self) -> Result<Vec<models::File>> {
|
||||||
use crate::database::inner::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
let matches = files.load::<models::File>(&self.0)?;
|
let matches = files.load::<models::File>(&self.0)?;
|
||||||
Ok(matches)
|
Ok(matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_latest_files(self: &Self, count: i64) -> Result<Vec<models::File>> {
|
pub fn get_latest_files(&self, count: i64) -> Result<Vec<models::File>> {
|
||||||
use crate::database::inner::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
let matches = files
|
let matches = files
|
||||||
|
@ -208,7 +208,7 @@ impl UpEndConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_update_mtime(
|
pub fn file_update_mtime(
|
||||||
self: &Self,
|
&self,
|
||||||
file_id: i32,
|
file_id: i32,
|
||||||
m_time: Option<NaiveDateTime>,
|
m_time: Option<NaiveDateTime>,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
|
@ -221,7 +221,7 @@ impl UpEndConnection {
|
||||||
.execute(&self.0)?)
|
.execute(&self.0)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_set_valid(self: &Self, file_id: i32, is_valid: bool) -> Result<usize> {
|
pub fn file_set_valid(&self, file_id: i32, is_valid: bool) -> Result<usize> {
|
||||||
use crate::database::inner::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
debug!("Setting file ID {} to valid = {}", file_id, is_valid);
|
debug!("Setting file ID {} to valid = {}", file_id, is_valid);
|
||||||
|
@ -231,7 +231,7 @@ impl UpEndConnection {
|
||||||
.execute(&self.0)?)
|
.execute(&self.0)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve_object(self: &Self, object_address: Address) -> Result<Vec<Entry>> {
|
pub fn retrieve_object(&self, object_address: Address) -> Result<Vec<Entry>> {
|
||||||
use crate::database::inner::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
let primary = data
|
let primary = data
|
||||||
|
@ -265,7 +265,7 @@ impl UpEndConnection {
|
||||||
Ok([entries, secondary_entries].concat())
|
Ok([entries, secondary_entries].concat())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_object(self: &Self, object_address: Address) -> Result<usize> {
|
pub fn remove_object(&self, object_address: Address) -> Result<usize> {
|
||||||
use crate::database::inner::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
debug!("Deleting {}!", object_address);
|
debug!("Deleting {}!", object_address);
|
||||||
|
@ -278,7 +278,7 @@ impl UpEndConnection {
|
||||||
Ok(diesel::delete(matches).execute(&self.0)?)
|
Ok(diesel::delete(matches).execute(&self.0)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query(self: &Self, query: Query) -> Result<Vec<Entry>> {
|
pub fn query(&self, query: Query) -> Result<Vec<Entry>> {
|
||||||
use crate::database::inner::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
trace!("Querying: {:?}", query);
|
trace!("Querying: {:?}", query);
|
||||||
|
@ -298,7 +298,7 @@ impl UpEndConnection {
|
||||||
Ok(entries)
|
Ok(entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_entry(self: &Self, entry: Entry) -> Result<Address> {
|
pub fn insert_entry(&self, entry: Entry) -> Result<Address> {
|
||||||
debug!("Inserting: {}", entry);
|
debug!("Inserting: {}", entry);
|
||||||
|
|
||||||
let insert_entry = models::Entry::try_from(&entry)?;
|
let insert_entry = models::Entry::try_from(&entry)?;
|
||||||
|
|
|
@ -40,10 +40,10 @@ lazy_static! {
|
||||||
fn initialize_types(connection: &UpEndConnection) -> Result<()> {
|
fn initialize_types(connection: &UpEndConnection) -> Result<()> {
|
||||||
// BLOB_TYPE
|
// BLOB_TYPE
|
||||||
connection.insert_entry(Entry::try_from(&*BLOB_TYPE_INVARIANT)?)?;
|
connection.insert_entry(Entry::try_from(&*BLOB_TYPE_INVARIANT)?)?;
|
||||||
upend_insert_addr!(&connection, BLOB_TYPE_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
upend_insert_addr!(connection, BLOB_TYPE_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
|
||||||
upend_insert_val!(&connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_MTIME_KEY);
|
upend_insert_val!(connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_MTIME_KEY);
|
||||||
upend_insert_val!(&connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_SIZE_KEY);
|
upend_insert_val!(connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_SIZE_KEY);
|
||||||
upend_insert_val!(&connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_MIME_KEY);
|
upend_insert_val!(connection, BLOB_TYPE_ADDR, TYPE_HAS_ATTR, FILE_MIME_KEY);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::util::hash::{decode, encode};
|
||||||
use crate::util::jobs::JobContainer;
|
use crate::util::jobs::JobContainer;
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
||||||
use actix_web::http::{self};
|
use actix_web::http;
|
||||||
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
@ -51,43 +51,41 @@ pub async fn get_raw(
|
||||||
if let Some(file) = files.get(0) {
|
if let Some(file) = files.get(0) {
|
||||||
let file_path = state.upend.vault_path.join(&file.path);
|
let file_path = state.upend.vault_path.join(&file.path);
|
||||||
|
|
||||||
if !query.native.is_some() {
|
if query.native.is_none() {
|
||||||
Ok(Either::A(NamedFile::open(file_path)?))
|
Ok(Either::A(NamedFile::open(file_path)?))
|
||||||
} else {
|
} else if cfg!(feature = "desktop") {
|
||||||
if cfg!(feature = "desktop") {
|
#[cfg(feature = "desktop")]
|
||||||
#[cfg(feature = "desktop")]
|
{
|
||||||
{
|
info!("Opening {:?}...", file_path);
|
||||||
info!("Opening {:?}...", file_path);
|
let mut response = HttpResponse::NoContent();
|
||||||
let mut response = HttpResponse::NoContent();
|
let path = if !file_path.is_executable() {
|
||||||
let path = if !file_path.is_executable() {
|
file_path
|
||||||
file_path
|
} else {
|
||||||
} else {
|
response
|
||||||
response
|
.header(
|
||||||
.header(
|
http::header::WARNING,
|
||||||
http::header::WARNING,
|
"199 - Opening parent directory due to file being executable.",
|
||||||
"199 - Opening parent directory due to file being executable.",
|
)
|
||||||
)
|
.header(
|
||||||
.header(
|
http::header::ACCESS_CONTROL_EXPOSE_HEADERS,
|
||||||
http::header::ACCESS_CONTROL_EXPOSE_HEADERS,
|
http::header::WARNING.to_string(),
|
||||||
http::header::WARNING.to_string(),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
file_path
|
file_path
|
||||||
.parent()
|
.parent()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ErrorInternalServerError("No parent to open as fallback.")
|
ErrorInternalServerError("No parent to open as fallback.")
|
||||||
})?
|
})?
|
||||||
.to_path_buf()
|
.to_path_buf()
|
||||||
};
|
};
|
||||||
opener::open(path).map_err(error::ErrorServiceUnavailable)?;
|
opener::open(path).map_err(error::ErrorServiceUnavailable)?;
|
||||||
return Ok(Either::B(response.finish()));
|
Ok(Either::B(response.finish()))
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "desktop"))]
|
|
||||||
!unreachable()
|
|
||||||
} else {
|
|
||||||
Err(error::ErrorBadRequest("Desktop features not enabled."))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "desktop"))]
|
||||||
|
unreachable!()
|
||||||
|
} else {
|
||||||
|
Err(error::ErrorBadRequest("Desktop features not enabled."))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(error::ErrorNotFound("NOT FOUND"))
|
Err(error::ErrorNotFound("NOT FOUND"))
|
||||||
|
|
Loading…
Reference in New Issue