Skip to content

Commit

Permalink
rename modules
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Mar 20, 2024
1 parent e31b4cb commit 8894703
Show file tree
Hide file tree
Showing 30 changed files with 63 additions and 66 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ The service provides a convenient and efficient way to share files. The code inc
$ git clone https://github.com/robatipoor/pf

# Build the project
$ cargo build --bin api --release
$ cargo build --bin pf-api --release

# Run the backend on address 127.0.0.1:8080
$ ./target/release/api --settings api/settings/base.toml
$ ./target/release/pf-api --settings api/settings/base.toml

# Alternatively, Run backend with cargo
$ cargo run --bin api
$ cargo run --bin pf-api
```
**Run API Service via Docker**

Expand Down Expand Up @@ -157,11 +157,8 @@ export PF__SERVER__HOST=127.0.0.1
# Install CLI tool
$ cargo install --path cli

# Rename CLI tool from 'cli' to 'pf'
$ mv ~/.cargo/bin/cli ~/.cargo/bin/pf

# Define an alias in the shell profile for 'pf' with server address
$ alias pf="pf --server-addr http://localhost:8080"
$ alias pf="pf-cli --server-addr http://localhost:8080"

# Copy text content to the server with an expiration time of 10 minutes.
$ echo 'Hello World!' | pf copy --expire "10 minute"
Expand Down
6 changes: 3 additions & 3 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "api"
name = "pf-api"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "api"
name = "pf-api"
path = "src/bin/main.rs"

[dependencies]
sdk = { path = "../sdk" }
pf-sdk = { path = "../sdk" }
anyhow = { workspace = true }
argon2 = { workspace = true }
clap = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion api/settings/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ port = 8080
# Domain name URL
domain_name = "localhost:8080"
# Public IP address
public_addr = "192.168.1.1:8080"
public_addr = "127.0.0.1:8080"
# TLS key file path
file_tls_key_path = "key.pem"
# TLS certificate file path
Expand Down
12 changes: 6 additions & 6 deletions api/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use api::{
use clap::Parser;
use futures_util::FutureExt;
use once_cell::sync::Lazy;
use pf_api::{
configure::env::get_env_source,
constant::ENV_PREFIX,
error::result::ApiResult,
server::{worker::GarbageCollectorTask, ApiServer},
util::{self, tracing::INIT_SUBSCRIBER},
};
use clap::Parser;
use futures_util::FutureExt;
use once_cell::sync::Lazy;

#[tokio::main]
async fn main() -> ApiResult {
// Parse command-line arguments
let args = api::configure::args::Args::parse();
let args = pf_api::configure::args::Args::parse();
// Read API configuration
let config = api::configure::ApiConfig::read(args.settings, get_env_source(ENV_PREFIX))?;
let config = pf_api::configure::ApiConfig::read(args.settings, get_env_source(ENV_PREFIX))?;
// Validate settings
config.validate()?;
// Force initialization of subscriber
Expand Down
2 changes: 1 addition & 1 deletion api/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use config::Environment;
use once_cell::sync::Lazy;
use sdk::util::dir::get_cargo_project_root;
use pf_sdk::util::dir::get_cargo_project_root;
use serde::Deserialize;
use std::{
net::{AddrParseError, SocketAddr},
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,5 +1,5 @@
use crate::error::{result::ApiResult, ApiError};
use sdk::dto::FileUrlPath;
use pf_sdk::dto::FileUrlPath;
use serde::{Deserialize, Serialize};
use sled::IVec;
use std::path::PathBuf;
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
Expand Up @@ -3,7 +3,7 @@ use crate::{
util::secret::SecretHash,
};
use chrono::{DateTime, Utc};
use sdk::dto::response::MetaDataFileResponse;
use pf_sdk::dto::response::MetaDataFileResponse;
use serde::{Deserialize, Serialize};
use sled::IVec;

Expand Down
2 changes: 1 addition & 1 deletion api/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::http::StatusCode;
use sdk::dto::response::BodyResponseError;
use pf_sdk::dto::response::BodyResponseError;

pub mod response;
pub mod result;
Expand Down
2 changes: 1 addition & 1 deletion api/src/handler/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
Json,
};
use garde::Validate;
use sdk::{
use pf_sdk::{
dto::{
request::UploadQueryParam,
response::{MessageResponse, MetaDataFileResponse, UploadResponse},
Expand Down
2 changes: 1 addition & 1 deletion api/src/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::Json;
use sdk::dto::response::MessageResponse;
use pf_sdk::dto::response::MessageResponse;

pub mod file;
pub mod index;
Expand Down
6 changes: 3 additions & 3 deletions api/src/service/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use axum::extract::multipart::Field;
use axum::extract::Multipart;
use chrono::{DateTime, Utc};
use futures_util::TryStreamExt;
use sdk::dto::request::UploadQueryParam;
use pf_sdk::dto::request::UploadQueryParam;
use std::path::PathBuf;
use tokio::fs::File;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufWriter};
Expand Down Expand Up @@ -61,7 +61,7 @@ pub async fn store(
None => continue,
};
let file_path = loop {
let code = sdk::util::random::generate_random_string(code_length);
let code = pf_sdk::util::random::generate_random_string(code_length);
let path = FilePath {
code,
file_name: file_name.to_string(),
Expand Down Expand Up @@ -250,7 +250,7 @@ mod tests {
use super::*;
use crate::util::{multipart::create_multipart_request, test::StateTestContext};
use fake::{Fake, Faker};
use sdk::assert_err;
use pf_sdk::assert_err;
use test_context::test_context;

#[test_context(StateTestContext)]
Expand Down
6 changes: 3 additions & 3 deletions api/src/util/qr_code.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use sdk::dto::request::QrCodeFormat;
use pf_sdk::dto::request::QrCodeFormat;

use crate::error::result::ApiResult;

pub fn generate_qr_code(qr_code_format: QrCodeFormat, input: &str) -> ApiResult<String> {
match qr_code_format {
QrCodeFormat::Text => Ok(sdk::util::qr_code::generate_base64_text_qr_code(input)?),
QrCodeFormat::Image => Ok(sdk::util::qr_code::generate_base64_png_qr_code(input)?),
QrCodeFormat::Text => Ok(pf_sdk::util::qr_code::generate_base64_text_qr_code(input)?),
QrCodeFormat::Image => Ok(pf_sdk::util::qr_code::generate_base64_png_qr_code(input)?),
}
}
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 sdk::dto::{response::BodyResponseError, FileUrlPath};
use pf_sdk::dto::{response::BodyResponseError, FileUrlPath};
use test_context::test_context;

#[test_context(ApiTestContext)]
Expand Down
2 changes: 1 addition & 1 deletion api/tests/api/download_api_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{assert_response_err, unwrap};
use fake::{Fake, Faker};
use sdk::dto::response::BodyResponseError;
use pf_sdk::dto::response::BodyResponseError;
use std::time::Duration;
use test_context::test_context;

Expand Down
8 changes: 4 additions & 4 deletions api/tests/api/helper/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
macro_rules! assert_response_ok {
($result:expr) => {
assert!(
matches!($result, sdk::dto::response::ApiResponseResult::Ok(_)),
matches!($result, pf_sdk::dto::response::ApiResponseResult::Ok(_)),
"match failed: {:?}",
$result,
)
Expand All @@ -13,7 +13,7 @@ macro_rules! assert_response_ok {
macro_rules! assert_response_err {
($result:expr $(, $closure:expr )?) => {
assert!(
matches!($result,sdk::dto::response::ApiResponseResult::Err(ref _e) $( if $closure(_e) )?),
matches!($result,pf_sdk::dto::response::ApiResponseResult::Err(ref _e) $( if $closure(_e) )?),
"match failed: {:?}",$result,
)
};
Expand All @@ -23,8 +23,8 @@ macro_rules! assert_response_err {
macro_rules! unwrap {
($result:expr) => {
match $result {
sdk::dto::response::ApiResponseResult::Ok(resp) => resp,
sdk::dto::response::ApiResponseResult::Err(e) => {
pf_sdk::dto::response::ApiResponseResult::Ok(resp) => resp,
pf_sdk::dto::response::ApiResponseResult::Err(e) => {
panic!("called `util::unwrap!()` on an `Err` value {e:?}")
}
}
Expand Down
16 changes: 8 additions & 8 deletions api/tests/api/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use std::ops::Deref;
use std::path::{Path, PathBuf};

use crate::unwrap;
use api::configure::CONFIG;
use api::error::result::ApiResult;
use api::server::worker::GarbageCollectorTask;
use api::server::{ApiServer, ApiState};
use api::util::tracing::INIT_SUBSCRIBER;
use fake::{Fake, Faker};
use once_cell::sync::Lazy;
use sdk::client::PasteFileClient;
use sdk::dto::request::{QrCodeFormat, UploadQueryParam};
use sdk::dto::FileUrlPath;
use pf_api::configure::CONFIG;
use pf_api::error::result::ApiResult;
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 test_context::AsyncTestContext;

pub mod assert;
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 sdk::dto::{response::BodyResponseError, FileUrlPath};
use pf_sdk::dto::{response::BodyResponseError, FileUrlPath};
use test_context::test_context;

#[test_context(ApiTestContext)]
Expand Down
2 changes: 1 addition & 1 deletion api/tests/api/upload_api_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{assert_response_err, assert_response_ok};
use sdk::dto::{request::UploadQueryParam, response::BodyResponseError};
use pf_sdk::dto::{request::UploadQueryParam, response::BodyResponseError};
use test_context::test_context;

use crate::helper::ApiTestContext;
Expand Down
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "cli"
name = "pf-cli"
version = "0.1.0"
edition = "2021"

[dependencies]
sdk = { path = "../sdk" }
pf-sdk = { path = "../sdk" }
reqwest = { workspace = true }
futures-util = { workspace = true }
anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Parser, Subcommand, ValueEnum};
use sdk::{dto::FileUrlPath, util::crypto::KeyNonce};
use pf_sdk::{dto::FileUrlPath, util::crypto::KeyNonce};

use std::path::PathBuf;

Expand Down
6 changes: 3 additions & 3 deletions cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use sdk::{
use pf_sdk::{
client::PasteFileClient,
dto::{
request::UploadQueryParam,
Expand Down Expand Up @@ -35,8 +35,8 @@ impl CommandLineClient {
param: &UploadQueryParam,
auth: Option<(String, String)>,
) -> anyhow::Result<(StatusCode, ApiResponseResult<UploadResponse>)> {
let file_name = sdk::util::file::get_file_name(source)?;
let content_type = sdk::util::file::get_content_type(source)?;
let file_name = pf_sdk::util::file::get_file_name(source)?;
let content_type = pf_sdk::util::file::get_content_type(source)?;
let file = tokio::fs::File::open(source).await?;
let total_size = file.metadata().await?.len();
let pb = progress_bar(total_size)?;
Expand Down
8 changes: 4 additions & 4 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::{
use pf_sdk::{
dto::{
request::UploadQueryParam,
response::{ApiResponseResult, BodyResponseError, UploadResponse},
Expand Down Expand Up @@ -138,7 +138,7 @@ fn show_upload_response(resp: ApiResponseResult<UploadResponse>, output: UploadO
println!("{}", serde_json::to_string(&resp).unwrap());
}
UploadOutput::QrCode => {
let qr_code = sdk::util::qr_code::generate_text_qr_code(&resp.url).unwrap();
let qr_code = pf_sdk::util::qr_code::generate_text_qr_code(&resp.url).unwrap();
println!("{qr_code}");
}
UploadOutput::Url => {
Expand Down Expand Up @@ -259,7 +259,7 @@ pub async fn encrypt_file(
.await
.unwrap();
} else {
sdk::util::crypto::encrypt_file(key_nonce, source_file, destination)
pf_sdk::util::crypto::encrypt_file(key_nonce, source_file, destination)
.await
.unwrap();
}
Expand All @@ -283,7 +283,7 @@ pub async fn decrypt_file(
.await
.unwrap();
} else {
sdk::util::crypto::decrypt_file(key_nonce, source_file, destination)
pf_sdk::util::crypto::decrypt_file(key_nonce, source_file, destination)
.await
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use args::{Args, SubCommand};
use clap::Parser;
use command::{CopyArguments, UploadArguments};
use sdk::util::{
use pf_sdk::util::{
file::{add_extension, get_content_type},
random::generate_random_string,
};
Expand Down
6 changes: 3 additions & 3 deletions cli/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{path::PathBuf, str::FromStr};

use anyhow::anyhow;
use sdk::dto::FileUrlPath;
use pf_sdk::dto::FileUrlPath;

use sdk::util::crypto::{KeyNonce, KeyType, NonceType};
use pf_sdk::util::crypto::{KeyNonce, KeyType, NonceType};

pub fn parse_key_nonce(input: &str) -> anyhow::Result<KeyNonce> {
let pos = input
Expand Down Expand Up @@ -89,7 +89,7 @@ mod tests {

use super::*;
use fake::{Fake, Faker};
use sdk::{assert_err, util::random::generate_random_string};
use pf_sdk::{assert_err, util::random::generate_random_string};

#[test]
fn test_parse_key_nonce() {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/util/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::progress::progress_bar;
use sdk::util::{
use pf_sdk::util::{
crypto::{decrypt, decrypt_file, encrypt, encrypt_file, KeyNonce},
file::{add_extension, add_parent_dir, rm_extra_extension},
random::generate_random_string_with_prefix,
Expand Down Expand Up @@ -110,7 +110,7 @@ mod tests {
use fake::{Fake, Faker};
use test_context::test_context;

use sdk::util::{
use pf_sdk::util::{
crypto::{KeyType, NonceType},
random::generate_random_string,
test::FileTestContext,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fake::{Fake, Faker};
use once_cell::sync::Lazy;
use sdk::{
use pf_sdk::{
dto::FileUrlPath,
retry,
util::{dir::get_cargo_project_root, random::generate_random_string},
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/cli/upload_and_download_cli_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use assert_cmd::Command;
use sdk::util::file::add_extension;
use pf_sdk::util::file::add_extension;

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

Expand Down
Loading

0 comments on commit 8894703

Please sign in to comment.