Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = ["sdk", "api", "cli"]
authors = ["Mahdi <Mahdi.robatipoor@gmail.com>"]
description = "A file upload/download service"
documentation = ""
edition = "2021"
edition = "2024"
homepage = "https://github.com/robatipoor/pf"
keywords = ["paste", "file", "transfer"]
license = "MIT"
Expand All @@ -22,59 +22,59 @@ opt-level = "z"
strip = true

[workspace.dependencies]
anyhow = "1.0.81"
anyhow = "1.0.97"
argon2 = "0.5.3"
assert_cmd = "2.0.14"
async-stream = "0.3.5"
axum = { version = "0.7.5", features = ["multipart"] }
axum-extra = { version = "0.9.3", features = ["async-read-body"] }
assert_cmd = "2.0.16"
async-stream = "0.3.6"
axum = { version = "0.8.1", features = ["multipart"] }
axum-extra = { version = "0.10.0", features = ["async-read-body"] }
hyper = { version = "1.2.0", features = ["full"] }
hyper-util = { version = "0.1.3" }
rustls-pemfile = "2.1.1"
tokio = { version = "1.36.0", features = [
rustls-pemfile = "2.2.0"
tokio = { version = "1.43.0", features = [
"macros",
"time",
"process",
"net",
"rt-multi-thread",
"io-std",
] }
tokio-util = { version = "0.7.10", features = ["io"] }
tokio-rustls = "0.26.0"
tower = { version = "0.4.13", features = ["util", "make"] }
tower-http = { version = "0.5.2", features = ["fs", "cors"] }
tokio-util = { version = "0.7.13", features = ["io"] }
tokio-rustls = "0.26.2"
tower = { version = "0.5.2", features = ["util", "make"] }
tower-http = { version = "0.6.2", features = ["fs", "cors"] }
tower-service = "0.3.2"
base64 = "0.22.0"
base64 = "0.22.1"
bincode = "1.3.3"
build_html = "2.4.0"
chrono = { version = "0.4.37", features = ["serde"] }
clap = { version = "4.5.4", features = ["derive"] }
config = { version = "0.14.0", default-features = false, features = ["toml"] }
chrono = { version = "0.4.40", features = ["serde"] }
clap = { version = "4.5.31", features = ["derive"] }
config = { version = "0.15.9", default-features = false, features = ["toml"] }
chacha20poly1305 = { version = "0.10.1", features = ["stream"] }
cuid2 = "0.1.2"
fake = { version = "2.9.2", features = ['derive', 'uuid', 'chrono'] }
futures-util = "0.3.30"
indicatif = { version = "0.17.8", features = ["tokio"] }
log = "0.4.21"
mime_guess = "2.0.4"
once_cell = { version = "1.19.0" }
qrcode = "0.14.0"
image = "0.25.0"
rand = "0.8.5"
reqwest = { version = "0.12.2", default-features = false, features = [
cuid2 = "0.1.4"
fake = { version = "4.0.0", features = ["derive", "chrono"] }
futures-util = "0.3.31"
indicatif = { version = "0.17.11", features = ["tokio"] }
log = "0.4.26"
mime_guess = "2.0.5"
once_cell = { version = "1.20.3" }
qrcode = "0.14.1"
image = "0.25.5"
rand = "0.9.0"
reqwest = { version = "0.12.12", default-features = false, features = [
"json",
"multipart",
"stream",
"rustls-tls",
] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
serde = { version = "1.0.218", features = ["derive"] }
serde_json = "1.0.140"
sled = "0.34.7"
strum = { version = "0.26.2", features = ["derive"] }
test-context = "0.3.0"
thiserror = "1.0.58"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
url = "2.5.0"
garde = { version = "0.18.0", features = ["full"] }
strum = { version = "0.27.1", features = ["derive"] }
test-context = "0.4.1"
thiserror = "2.0.12"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
url = "2.5.4"
garde = { version = "0.22.0", features = ["full"] }
askama = "0.12.1"
2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pf-api"
version = "0.1.0"
edition = "2021"
edition = "2024"

[[bin]]
name = "pf-api"
Expand Down
2 changes: 1 addition & 1 deletion api/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pf_api::{
configure::env::get_env_source,
constant::ENV_PREFIX,
error::result::ApiResult,
server::{worker::GarbageCollectorTask, ApiServer},
server::{ApiServer, worker::GarbageCollectorTask},
util::{self, tracing::INIT_SUBSCRIBER},
};

Expand Down
2 changes: 1 addition & 1 deletion api/src/configure/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
constant::ENV_PREFIX,
error::{result::ApiResult, ApiError},
error::{ApiError, result::ApiResult},
};
use config::Environment;
use once_cell::sync::Lazy;
Expand Down
2 changes: 1 addition & 1 deletion api/src/database/file_path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::{result::ApiResult, ApiError};
use crate::error::{ApiError, result::ApiResult};
use pf_sdk::dto::FileUrlPath;
use serde::{Deserialize, Serialize};
use sled::IVec;
Expand Down
2 changes: 1 addition & 1 deletion api/src/database/meta_data_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
error::{result::ApiResult, ApiError},
error::{ApiError, result::ApiResult},
util::secret::SecretHash,
};
use chrono::{DateTime, Utc};
Expand Down
4 changes: 2 additions & 2 deletions api/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
configure::DatabaseConfig,
error::{result::ApiResult, ApiError},
error::{ApiError, result::ApiResult},
util::path::get_fs_path,
};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Database {
let is_gc_notify = guard
.iter()
.next()
.map_or(true, |(first_expire, _)| *first_expire > expire_date_time);
.is_none_or(|(first_expire, _)| *first_expire > expire_date_time);
guard.insert(expire.clone());
drop(guard);
if is_gc_notify {
Expand Down
2 changes: 1 addition & 1 deletion api/src/error/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{
response::{IntoResponse, Response},
Json,
response::{IntoResponse, Response},
};

use super::ApiError;
Expand Down
6 changes: 3 additions & 3 deletions api/src/handler/file.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::anyhow;
use axum::{
Json,
body::Body,
extract::{Multipart, Path, Query, State},
http::{header::HeaderMap, Request},
http::{Request, header::HeaderMap},
response::Response,
Json,
};
use garde::Validate;
use pf_sdk::{
Expand All @@ -25,7 +25,7 @@ pub async fn upload(
headers: HeaderMap,
multipart: Multipart,
) -> ApiResult<Json<UploadResponse>> {
param.validate(&())?;
param.validate()?;
let secret = crate::util::http::parse_basic_auth(&headers)?;
let (file_path, expire_date_time) =
service::file::store(&state, &param, secret, multipart).await?;
Expand Down
8 changes: 4 additions & 4 deletions api/src/router/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{configure::cors::cors_layer, error::result::ApiResult, handler, server::ApiState};
use axum::{
Router,
extract::DefaultBodyLimit,
routing::{delete, get, post},
Router,
};

pub fn get_router(state: ApiState) -> ApiResult<Router> {
Expand All @@ -11,9 +11,9 @@ pub fn get_router(state: ApiState) -> ApiResult<Router> {
.route("/upload", post(handler::file::upload))
.layer(DefaultBodyLimit::disable())
.route("/healthz", get(handler::health_check))
.route("/info/:code/:file_name", get(handler::file::info))
.route("/:code/:file_name", get(handler::file::download))
.route("/:code/:file_name", delete(handler::file::delete))
.route("/info/{code}/{file_name}", get(handler::file::info))
.route("/{code}/{file_name}", get(handler::file::download))
.route("/{code}/{file_name}", delete(handler::file::delete))
.route("/", get(handler::index::page))
.layer(cors_layer(&state.config.server)?)
.with_state(state),
Expand Down
4 changes: 2 additions & 2 deletions api/src/server/axum_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::sync::Arc;

use axum::Router;
use futures_util::pin_mut;
use hyper::body::Incoming;
use hyper::Request;
use hyper::body::Incoming;
use hyper_util::rt::{TokioExecutor, TokioIo};
use tokio::net::TcpListener;
use tokio_rustls::rustls::ServerConfig;
use tokio_rustls::TlsAcceptor;
use tokio_rustls::rustls::ServerConfig;
use tower_service::Service;

// Async function to serve incoming connections over TLS
Expand Down
4 changes: 2 additions & 2 deletions api/src/service/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::database::file_path::FilePath;
use crate::database::meta_data_file::MetaDataFile;
use crate::error::invalid_input_error;
use crate::error::{
result::{ApiResult, ToApiResult},
ApiError,
result::{ApiResult, ToApiResult},
};
use crate::util::path::get_fs_path;
use crate::util::secret::{Secret, SecretHash};
use anyhow::anyhow;
use axum::extract::multipart::Field;
use axum::extract::Multipart;
use axum::extract::multipart::Field;
use chrono::{DateTime, Utc};
use futures_util::TryStreamExt;
use pf_sdk::dto::request::UploadQueryParam;
Expand Down
2 changes: 1 addition & 1 deletion api/src/util/hash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use argon2::{
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Argon2,
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString, rand_core::OsRng},
};

pub fn argon_hash(content: impl AsRef<str>) -> Result<String, argon2::password_hash::Error> {
Expand Down
4 changes: 3 additions & 1 deletion api/src/util/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use axum::{
use hyper::header::CONTENT_TYPE;

pub async fn create_multipart_request(file_name: &str, data: &str) -> anyhow::Result<Multipart> {
let data = format!("--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"file\"; filename=\"{file_name}\"\r\n\r\n{data}\r\n--X-BOUNDARY--\r\n");
let data = format!(
"--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"file\"; filename=\"{file_name}\"\r\n\r\n{data}\r\n--X-BOUNDARY--\r\n"
);
let body = Body::from(Bytes::from(data));
let request = Request::builder()
.header(CONTENT_TYPE, "multipart/form-data; boundary=X-BOUNDARY")
Expand Down
2 changes: 1 addition & 1 deletion api/src/util/secret.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::{result::ApiResult, ApiError};
use crate::error::{ApiError, result::ApiResult};

#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)]
pub struct Secret(String);
Expand Down
2 changes: 1 addition & 1 deletion api/src/util/task.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tracing::error;

use crate::error::{result::ApiResult, ApiError};
use crate::error::{ApiError, result::ApiResult};

/// If a task is fail fast after encounter an error node goes down.
pub type IsFailFast = bool;
Expand Down
2 changes: 1 addition & 1 deletion api/src/util/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::path::PathBuf;
use std::{collections::HashMap, hash::Hash};

use crate::error::result::ApiResult;
use crate::server::worker::GarbageCollectorTask;
use crate::server::ApiState;
use crate::server::worker::GarbageCollectorTask;
use crate::{configure::CONFIG, util::tracing::INIT_SUBSCRIBER};
use once_cell::sync::Lazy;
use test_context::AsyncTestContext;
Expand Down
2 changes: 1 addition & 1 deletion api/tests/api/delete_api_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helper::ApiTestContext;
use crate::{assert_response_err, assert_response_ok};
use fake::{Fake, Faker};
use pf_sdk::dto::{response::BodyResponseError, FileUrlPath};
use pf_sdk::dto::{FileUrlPath, response::BodyResponseError};
use test_context::test_context;

#[test_context(ApiTestContext)]
Expand Down
3 changes: 2 additions & 1 deletion api/tests/api/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use pf_api::server::worker::GarbageCollectorTask;
use pf_api::server::{ApiServer, ApiState};
use pf_api::util::tracing::INIT_SUBSCRIBER;
use pf_sdk::client::PasteFileClient;
use pf_sdk::dto::request::{QrCodeFormat, UploadQueryParam};
use pf_sdk::dto::FileUrlPath;
use pf_sdk::dto::request::{QrCodeFormat, UploadQueryParam};
use test_context::AsyncTestContext;

pub mod assert;
Expand Down Expand Up @@ -104,6 +104,7 @@ impl ApiTestContext {
}
}

#[allow(dead_code)]
#[derive(Clone)]
pub struct DummyFile {
pub content: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion api/tests/api/info_api_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helper::ApiTestContext;
use crate::{assert_response_err, unwrap};
use fake::{Fake, Faker};
use pf_sdk::dto::{response::BodyResponseError, FileUrlPath};
use pf_sdk::dto::{FileUrlPath, response::BodyResponseError};
use test_context::test_context;

#[test_context(ApiTestContext)]
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pf-cli"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
pf-sdk = { path = "../sdk" }
Expand Down
4 changes: 2 additions & 2 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::parse::{
parse_key_nonce, parse_source_file,
};

const HELP_ENCRYPT :&str = "The encrypt format should be `key:nonce`, with the key being 32 characters in length and the nonce being 19 characters.";
const HELP_DECRYPT :&str = "The decrypt format should be `key:nonce`, with the key being 32 characters in length and the nonce being 19 characters.";
const HELP_ENCRYPT: &str = "The encrypt format should be `key:nonce`, with the key being 32 characters in length and the nonce being 19 characters.";
const HELP_DECRYPT: &str = "The decrypt format should be `key:nonce`, with the key being 32 characters in length and the nonce being 19 characters.";

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::{
use pf_sdk::{
client::PasteFileClient,
dto::{
FileUrlPath,
request::UploadQueryParam,
response::{ApiResponseResult, BodyResponseError, UploadResponse},
FileUrlPath,
},
};

Expand Down
2 changes: 1 addition & 1 deletion cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pf_sdk::{
dto::{
FileUrlPath,
request::UploadQueryParam,
response::{ApiResponseResult, BodyResponseError, UploadResponse},
FileUrlPath,
},
util::{
crypto::KeyNonce,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::progress::progress_bar;
use pf_sdk::util::{
crypto::{decrypt, decrypt_file, encrypt, encrypt_file, KeyNonce},
crypto::{KeyNonce, decrypt, decrypt_file, encrypt, encrypt_file},
file::{add_extension, add_parent_dir, rm_extra_extension},
random::generate_random_string_with_prefix,
};
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/copy_and_paste_cli_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use assert_cmd::Command;

use crate::helper::{generate_random_key_nonce, CliTestContext};
use crate::helper::{CliTestContext, generate_random_key_nonce};

#[test_context::test_context(CliTestContext)]
#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/encrypt_and_decrypt_cli_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::helper::{generate_random_key_nonce, CliTestContext};
use crate::helper::{CliTestContext, generate_random_key_nonce};
use assert_cmd::Command;

#[test_context::test_context(CliTestContext)]
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static SETUP: Lazy<()> = Lazy::new(|| {
std::process::Command::new("cargo")
.arg("build")
.arg("-q")
.current_dir(&get_cargo_project_root().unwrap().unwrap())
.current_dir(get_cargo_project_root().unwrap().unwrap())
.stdout(Stdio::piped())
.spawn()
.unwrap()
Expand Down
Loading
Loading