Skip to content

Commit 1d734ba

Browse files
committed
update dependecies and settings file
1 parent 976e05c commit 1d734ba

File tree

9 files changed

+35
-32
lines changed

9 files changed

+35
-32
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ opt-level = "z"
2222
strip = true
2323

2424
[workspace.dependencies]
25-
anyhow = "1.0.80"
25+
anyhow = "1.0.81"
2626
argon2 = "0.5.3"
2727
assert_cmd = "2.0.14"
2828
async-stream = "0.3.5"
2929
axum = { version = "0.7.4", features = ["multipart"] }
3030
axum-extra = { version = "0.9.2", features = ["async-read-body"] }
3131
hyper = { version = "1.2.0", features = ["full"] }
3232
hyper-util = { version = "0.1.3" }
33-
rustls-pemfile = "2.1.0"
33+
rustls-pemfile = "2.1.1"
3434
tokio = { version = "1.36.0", features = [
3535
"macros",
3636
"time",
@@ -47,21 +47,21 @@ tower-service = "0.3.2"
4747
base64 = "0.22.0"
4848
bincode = "1.3.3"
4949
build_html = "2.4.0"
50-
chrono = { version = "0.4.34", features = ["serde"] }
51-
clap = { version = "4.5.1", features = ["derive"] }
50+
chrono = { version = "0.4.35", features = ["serde"] }
51+
clap = { version = "4.5.2", features = ["derive"] }
5252
config = { version = "0.14.0", default-features = false, features = ["toml"] }
5353
chacha20poly1305 = { version = "0.10.1", features = ["stream"] }
5454
cuid2 = "0.1.2"
5555
fake = { version = "2.9.2", features = ['derive', 'uuid', 'chrono'] }
5656
futures-util = "0.3.30"
5757
indicatif = "0.17.8"
58-
log = "0.4.20"
58+
log = "0.4.21"
5959
mime_guess = "2.0.4"
6060
once_cell = { version = "1.19.0" }
6161
qrcode = "0.13"
6262
image = "0.24.9"
6363
rand = "0.8.5"
64-
reqwest = { version = "0.11.24", default-features = false, features = [
64+
reqwest = { version = "0.11.25", default-features = false, features = [
6565
"json",
6666
"multipart",
6767
"stream",
@@ -70,9 +70,9 @@ reqwest = { version = "0.11.24", default-features = false, features = [
7070
serde = { version = "1.0.197", features = ["derive"] }
7171
serde_json = "1.0.114"
7272
sled = "0.34.7"
73-
strum = { version = "0.26.1", features = ["derive"] }
73+
strum = { version = "0.26.2", features = ["derive"] }
7474
test-context = "0.3.0"
75-
thiserror = "1.0.57"
75+
thiserror = "1.0.58"
7676
tracing = "0.1.40"
7777
tracing-subscriber = "0.3.18"
7878
url = "2.5.0"

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PasteFile 📁 📥
2-
The service provides a convenient means of sharing files with easy setup. The code includes the server API and CLI client tool, encompassing everything you need to create your own instance.
2+
The service provides a convenient and efficient way to share files. The code includes the server API and CLI client tool, encompassing everything you need to create your own instance.
33

44
![License](https://img.shields.io/github/license/robatipoor/pf)
55
[![Lines Of Code](https://tokei.rs/b1/github/robatipoor/pf?category=code)](https://github.com/robatipoor/pf)
@@ -22,7 +22,7 @@ The service provides a convenient means of sharing files with easy setup. The co
2222
* Built-in TLS Server
2323

2424

25-
**Run Backend Service Locally**
25+
**Run API Service Locally**
2626

2727
```sh
2828
# Clone the project
@@ -37,7 +37,7 @@ $ ./target/release/api --settings api/settings/base.toml
3737
# Alternatively, Run backend with cargo
3838
$ cargo run --bin api
3939
```
40-
**Run Backend Service via Docker**
40+
**Run API Service via Docker**
4141

4242
```sh
4343
# Build docker image
@@ -96,7 +96,7 @@ $ curl -X GET http://127.0.0.1:8080/info/{code}/{file_name}
9696
$ curl -X DELETE http://127.0.0.1:8080/{code}/{file_name}
9797
```
9898

99-
**Backend settings**
99+
**API settings**
100100

101101
```toml
102102
# api/settings/base.toml
@@ -123,8 +123,8 @@ host = "127.0.0.1"
123123
# Port number for the server
124124
port = 8080
125125

126-
# Domain URL
127-
domain = "http://localhost:8080"
126+
# Domain name URL
127+
domain_name = "http://localhost:8080"
128128

129129
# TLS key file path
130130
file_tls_key_path = "key.pem"
@@ -163,20 +163,17 @@ $ mv ~/.cargo/bin/cli ~/.cargo/bin/pf
163163
$ alias pf="pf --server-addr http://localhost:8080"
164164

165165
# Encrypt and upload a file and retrieve the corresponding download URL.
166-
$ pf upload --source-file ~/example-file.txt --key-nonce "{key}:{nonce}" --progress-bar
166+
$ pf upload --source-file ~/example-file.txt --key-nonce "{key}:{nonce}" --progress-bar
167167

168-
# Upload a file with basic authentication and progress bar option.
169-
$ pf --auth "username:password" upload --source-file ~/example-file.txt
168+
# Download and decrypt a file.
169+
$ pf download --destination ~/example-dir/ --url-path "{code}/{file_name}" --key-nonce "{key}:{nonce}"
170170

171171
# Upload a text with an expiration time of 10 minutes.
172172
$ echo 'Hello World!' | pf copy --expire "10 minute"
173173

174174
# Upload a file and then display the QR code.
175175
$ pf upload --source-file ~/example-file.txt --output qr-code
176176

177-
# Download a file with progress bar option.
178-
$ pf download --destination ~/example-dir/ --url-path "{code}/{file_name}" --progress-bar
179-
180177
# Paste a file.
181178
$ pf paste --url-path "{code}/{file_name}" > my_file.txt
182179

api/settings/base.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ schema = "http"
1414
host = "127.0.0.1"
1515
# Port number for the server
1616
port = 8080
17-
# Domain URL
18-
domain = "http://localhost:8080"
17+
# Domain name URL
18+
domain_name = "http://localhost:8080"
19+
# Public IP address
20+
public_addr = "http://127.0.0.1:8080"
1921
# TLS key file path
2022
file_tls_key_path = "key.pem"
2123
# TLS certificate file path

api/src/configure/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ApiConfig {
2929

3030
#[derive(Debug, Deserialize, Clone)]
3131
pub struct ServerConfig {
32-
pub domain: String,
32+
pub domain_name: String,
3333
pub schema: UrlSchema,
3434
pub host: String,
3535
pub port: u16,

api/src/handler/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub async fn upload(
2929
let (file_path, expire_date_time) =
3030
service::file::store(&state, &param, secret, multipart).await?;
3131
let url = create_url(
32-
&state.config.server.domain,
32+
&state.config.server.domain_name,
3333
&file_path.code,
3434
&file_path.file_name,
3535
)?

api/src/handler/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct IndexPage<'a> {
1010

1111
pub async fn page(State(state): State<ApiState>) -> ApiResult<Html<String>> {
1212
let page = IndexPage {
13-
domain: &state.config.server.domain,
13+
domain: &state.config.server.domain_name,
1414
};
1515
Ok(Html(page.render()?))
1616
}

api/src/router/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ pub fn get_router(state: ApiState) -> ApiResult<Router> {
1717
.route("/:code/:file_name", get(handler::file::download))
1818
.route("/:code/:file_name", delete(handler::file::delete))
1919
.route("/", get(handler::index::page))
20-
.layer(cors_layer(&state.config.server.domain)?)
20+
.layer(cors_layer(&state.config.server.domain_name)?)
2121
.with_state(state),
2222
)
2323
}
2424

25-
fn cors_layer(domain: &str) -> ApiResult<tower_http::cors::CorsLayer> {
25+
fn cors_layer(domain_name: &str) -> ApiResult<tower_http::cors::CorsLayer> {
2626
Ok(
2727
tower_http::cors::CorsLayer::new()
2828
.allow_methods([
@@ -31,7 +31,8 @@ fn cors_layer(domain: &str) -> ApiResult<tower_http::cors::CorsLayer> {
3131
hyper::Method::DELETE,
3232
])
3333
.allow_origin(tower_http::cors::AllowOrigin::exact(
34-
HeaderValue::from_str(domain).map_err(|e| anyhow!("Invalid domain url, Error: {e}"))?,
34+
HeaderValue::from_str(domain_name)
35+
.map_err(|e| anyhow!("Invalid domain url, Error: {e}"))?,
3536
))
3637
.allow_headers([hyper::header::CONTENT_TYPE]),
3738
)

api/src/service/file.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::configure::ApiConfig;
22
use crate::database::file_path::FilePath;
33
use crate::database::meta_data_file::MetaDataFile;
4+
use crate::error::invalid_input_error;
45
use crate::error::{
56
result::{ApiResult, ToApiResult},
67
ApiError,
@@ -37,7 +38,7 @@ pub async fn store(
3738
.expire_secs
3839
.unwrap_or(state.config.default_expire_secs) as i64;
3940
let now = Utc::now();
40-
let expire_date_time = calc_expiration_date(now, expire_secs);
41+
let expire_date_time = calc_expiration_date(now, expire_secs)?;
4142
let mut code_length = param
4243
.code_length
4344
.unwrap_or(state.config.default_code_length);
@@ -237,8 +238,10 @@ pub fn authorize_user(secret: Option<Secret>, secret_hash: &Option<SecretHash>)
237238
Ok(())
238239
}
239240

240-
pub fn calc_expiration_date(now: DateTime<Utc>, secs: i64) -> DateTime<Utc> {
241-
now + chrono::Duration::seconds(secs)
241+
pub fn calc_expiration_date(now: DateTime<Utc>, expire_secs: i64) -> ApiResult<DateTime<Utc>> {
242+
chrono::Duration::try_seconds(expire_secs)
243+
.map(|s| now + s)
244+
.ok_or_else(|| invalid_input_error("expire_secs", "Invalid expire seconds"))
242245
}
243246

244247
#[cfg(test)]

api/tests/api/index_page_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ use test_context::test_context;
55
#[tokio::test]
66
pub async fn test_index_page(ctx: &mut ApiTestContext) {
77
let (status, html) = ctx.index_page().await.unwrap();
8-
assert!(html.contains(&ctx.state.config.server.domain));
8+
assert!(html.contains(&ctx.state.config.server.domain_name));
99
assert!(status.is_success(), "status: {status}");
1010
}

0 commit comments

Comments
 (0)