mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-10 06:25:00 +00:00
Further clean tracing logs
This commit is contained in:
parent
5a0b598ff7
commit
24f09408fb
6 changed files with 48 additions and 23 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -40,7 +40,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-form-data"
|
name = "actix-form-data"
|
||||||
version = "0.5.0-alpha.0"
|
version = "0.5.0-alpha.0"
|
||||||
source = "git+https://git.asonix.dog/Aardwolf/actix-form-data#2a69e0a4a3767ba177688adb247560c2e9f9c06c"
|
source = "git+https://git.asonix.dog/Aardwolf/actix-form-data#eefb669e0d16f89114da9acdf4ff9c5d8cc76b00"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-multipart",
|
"actix-multipart",
|
||||||
|
@ -48,10 +48,11 @@ dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures",
|
"futures",
|
||||||
"log",
|
|
||||||
"mime",
|
"mime",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"tracing-futures",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1386,6 +1387,7 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1697,18 +1699,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.111"
|
version = "1.0.112"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d"
|
checksum = "736aac72d1eafe8e5962d1d1c3d99b0df526015ba40915cb3c49d042e92ec243"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.111"
|
version = "1.0.112"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
|
checksum = "bf0343ce212ac0d3d6afd9391ac8e9c9efe06b533c8d33f660f6390cc4093f57"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -2314,6 +2316,15 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
||||||
|
dependencies = [
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|
|
@ -33,3 +33,4 @@ thiserror = "1.0"
|
||||||
tracing = "0.1.15"
|
tracing = "0.1.15"
|
||||||
tracing-futures = "0.2.4"
|
tracing-futures = "0.2.4"
|
||||||
tracing-subscriber = { version = "0.2.5", features = ["fmt", "tracing-log"] }
|
tracing-subscriber = { version = "0.2.5", features = ["fmt", "tracing-log"] }
|
||||||
|
uuid = { version = "0.8", features = ["v4"] }
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -87,7 +87,7 @@ fn from_ext(ext: std::ffi::OsString) -> mime::Mime {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle responding to succesful uploads
|
/// Handle responding to succesful uploads
|
||||||
#[instrument(skip(manager))]
|
#[instrument(skip(value, manager))]
|
||||||
async fn upload(
|
async fn upload(
|
||||||
value: Value,
|
value: Value,
|
||||||
manager: web::Data<UploadManager>,
|
manager: web::Data<UploadManager>,
|
||||||
|
@ -163,7 +163,7 @@ async fn delete(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serve files
|
/// Serve files
|
||||||
#[instrument(skip(manager))]
|
#[instrument(skip(manager, whitelist))]
|
||||||
async fn serve(
|
async fn serve(
|
||||||
segments: web::Path<String>,
|
segments: web::Path<String>,
|
||||||
manager: web::Data<UploadManager>,
|
manager: web::Data<UploadManager>,
|
||||||
|
@ -300,15 +300,20 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
.transform_error(|e| UploadError::from(e).into())
|
.transform_error(|e| UploadError::from(e).into())
|
||||||
.field(
|
.field(
|
||||||
"images",
|
"images",
|
||||||
Field::array(Field::file(move |_, _, stream| {
|
Field::array(Field::file(move |filename, _, stream| {
|
||||||
let manager = manager2.clone();
|
let manager = manager2.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
manager.upload(stream).await.map(|alias| {
|
let span = tracing::info_span!("file-upload", ?filename);
|
||||||
|
let entered = span.enter();
|
||||||
|
|
||||||
|
let res = manager.upload(stream).await.map(|alias| {
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
path.push(alias);
|
path.push(alias);
|
||||||
Some(path)
|
Some(path)
|
||||||
})
|
});
|
||||||
|
drop(entered);
|
||||||
|
res
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
@ -328,14 +333,19 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
let manager = manager2.clone();
|
let manager = manager2.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
manager
|
let span = tracing::info_span!("file-import", ?filename);
|
||||||
|
let entered = span.enter();
|
||||||
|
|
||||||
|
let res = manager
|
||||||
.import(filename, content_type, validate_imports, stream)
|
.import(filename, content_type, validate_imports, stream)
|
||||||
.await
|
.await
|
||||||
.map(|alias| {
|
.map(|alias| {
|
||||||
let mut path = PathBuf::new();
|
let mut path = PathBuf::new();
|
||||||
path.push(alias);
|
path.push(alias);
|
||||||
Some(path)
|
Some(path)
|
||||||
})
|
});
|
||||||
|
drop(entered);
|
||||||
|
res
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::dev::{Service, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures::future::{ok, Ready};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tracing_futures::{Instrument, Instrumented};
|
use tracing_futures::{Instrument, Instrumented};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub(crate) struct Tracing;
|
pub(crate) struct Tracing;
|
||||||
|
|
||||||
|
@ -41,8 +42,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: S::Request) -> Self::Future {
|
fn call(&mut self, req: S::Request) -> Self::Future {
|
||||||
|
let uuid = Uuid::new_v4();
|
||||||
|
|
||||||
self.inner
|
self.inner
|
||||||
.call(req)
|
.call(req)
|
||||||
.instrument(tracing::info_span!("request"))
|
.instrument(tracing::info_span!("request", ?uuid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete the alias, and the file & variants if no more aliases exist
|
/// Delete the alias, and the file & variants if no more aliases exist
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, alias, token))]
|
||||||
pub(crate) async fn delete(&self, alias: String, token: String) -> Result<(), UploadError> {
|
pub(crate) async fn delete(&self, alias: String, token: String) -> Result<(), UploadError> {
|
||||||
use sled::Transactional;
|
use sled::Transactional;
|
||||||
let db = self.inner.db.clone();
|
let db = self.inner.db.clone();
|
||||||
|
@ -439,7 +439,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for an already-uploaded image with this hash, returning the path to the target file
|
// check for an already-uploaded image with this hash, returning the path to the target file
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash, content_type))]
|
||||||
async fn check_duplicate(
|
async fn check_duplicate(
|
||||||
&self,
|
&self,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
|
@ -479,7 +479,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a short filename that isn't already in-use
|
// generate a short filename that isn't already in-use
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, content_type))]
|
||||||
async fn next_file(&self, content_type: mime::Mime) -> Result<String, UploadError> {
|
async fn next_file(&self, content_type: mime::Mime) -> Result<String, UploadError> {
|
||||||
let image_dir = self.image_dir();
|
let image_dir = self.image_dir();
|
||||||
use rand::distributions::{Alphanumeric, Distribution};
|
use rand::distributions::{Alphanumeric, Distribution};
|
||||||
|
@ -508,7 +508,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash, alias))]
|
||||||
async fn add_existing_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
async fn add_existing_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
||||||
self.save_alias(hash, alias).await??;
|
self.save_alias(hash, alias).await??;
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ impl UploadManager {
|
||||||
// Add an alias to an existing file
|
// Add an alias to an existing file
|
||||||
//
|
//
|
||||||
// This will help if multiple 'users' upload the same file, and one of them wants to delete it
|
// This will help if multiple 'users' upload the same file, and one of them wants to delete it
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash, content_type))]
|
||||||
async fn add_alias(
|
async fn add_alias(
|
||||||
&self,
|
&self,
|
||||||
hash: &Hash,
|
hash: &Hash,
|
||||||
|
@ -536,7 +536,7 @@ impl UploadManager {
|
||||||
// Add a pre-defined alias to an existin file
|
// Add a pre-defined alias to an existin file
|
||||||
//
|
//
|
||||||
// DANGER: this can cause BAD BAD BAD conflicts if the same alias is used for multiple files
|
// DANGER: this can cause BAD BAD BAD conflicts if the same alias is used for multiple files
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash))]
|
||||||
async fn store_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
async fn store_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
||||||
let alias = alias.to_string();
|
let alias = alias.to_string();
|
||||||
loop {
|
loop {
|
||||||
|
@ -569,7 +569,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate an alias to the file
|
// Generate an alias to the file
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash, content_type))]
|
||||||
async fn next_alias(
|
async fn next_alias(
|
||||||
&self,
|
&self,
|
||||||
hash: &Hash,
|
hash: &Hash,
|
||||||
|
@ -595,7 +595,7 @@ impl UploadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save an alias to the database
|
// Save an alias to the database
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self, hash))]
|
||||||
async fn save_alias(
|
async fn save_alias(
|
||||||
&self,
|
&self,
|
||||||
hash: &Hash,
|
hash: &Hash,
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub(crate) enum GifError {
|
||||||
}
|
}
|
||||||
|
|
||||||
// import & export image using the image crate
|
// import & export image using the image crate
|
||||||
#[instrument(skip(bytes))]
|
#[instrument(skip(bytes, prescribed_format))]
|
||||||
pub(crate) async fn validate_image(
|
pub(crate) async fn validate_image(
|
||||||
bytes: Bytes,
|
bytes: Bytes,
|
||||||
prescribed_format: Option<Format>,
|
prescribed_format: Option<Format>,
|
||||||
|
|
Loading…
Reference in a new issue