Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add head endpoint #46

Merged
merged 3 commits into from
Oct 17, 2024
Merged
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
152 changes: 79 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
resolver = "2"

[workspace.dependencies]
pkarr = { git = "https://github.com/Pubky/pkarr", branch = "serde", package = "pkarr", features = ["async"] }
pkarr = { git = "https://github.com/Pubky/pkarr", branch = "serde", package = "pkarr", features = ["async", "serde"] }
serde = { version = "^1.0.209", features = ["derive"] }

[profile.release]
Expand Down
12 changes: 3 additions & 9 deletions pubky-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
base32 = "0.5.0"
blake3 = "1.5.1"
ed25519-dalek = "2.1.1"
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
once_cell = "1.19.0"
pkarr = { workspace = true }
rand = "0.8.5"
Expand All @@ -17,17 +17,11 @@ postcard = { version = "1.0.8", features = ["alloc"] }
crypto_secretbox = { version = "0.1.1", features = ["std"] }
argon2 = { version = "0.5.3", features = ["std"] }

serde = { workspace = true, optional = true }
serde = { workspace = true }
pubky-timestamp = { version = "0.2.0", features = ["full"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.69"

[dev-dependencies]
postcard = "1.0.8"

[features]

serde = ["dep:serde", "ed25519-dalek/serde", "pkarr/serde"]
full = ['serde']

default = ['full']
6 changes: 3 additions & 3 deletions pubky-common/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl AuthToken {
let now = Timestamp::now();

// Chcek timestamp;
let diff = token.timestamp.difference(&now);
let diff = token.timestamp.as_u64() as i64 - now.as_u64() as i64;
if diff > TIMESTAMP_WINDOW {
return Err(Error::TooFarInTheFuture);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl AuthVerifier {

/// Remove all tokens older than two time intervals in the past.
fn gc(&self) {
let threshold = ((Timestamp::now().into_inner() / TIME_INTERVAL) - 2).to_be_bytes();
let threshold = ((Timestamp::now().as_u64() / TIME_INTERVAL) - 2).to_be_bytes();

let mut inner = self.seen.lock().unwrap();

Expand Down Expand Up @@ -235,7 +235,7 @@ mod tests {

let verifier = AuthVerifier::default();

let timestamp = (&Timestamp::now()) - (TIMESTAMP_WINDOW as u64);
let timestamp = (Timestamp::now()) - (TIMESTAMP_WINDOW as u64);

let mut signable = vec![];
signable.extend_from_slice(signer.public_key().as_bytes());
Expand Down
5 changes: 4 additions & 1 deletion pubky-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ pub mod crypto;
pub mod namespaces;
pub mod recovery_file;
pub mod session;
pub mod timestamp;

pub mod timestamp {
pub use pubky_timestamp::*;
}
2 changes: 1 addition & 1 deletion pubky-common/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Session {
Self {
version: 0,
pubky: token.pubky().to_owned(),
created_at: Timestamp::now().into_inner(),
created_at: Timestamp::now().as_u64(),
capabilities: token.capabilities().to_vec(),
user_agent: user_agent.as_deref().unwrap_or("").to_string(),
name: user_agent.as_deref().unwrap_or("").to_string(),
Expand Down
280 changes: 0 additions & 280 deletions pubky-common/src/timestamp.rs

This file was deleted.

3 changes: 2 additions & 1 deletion pubky-homeserver/src/routes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{
extract::DefaultBodyLimit,
routing::{delete, get, post, put},
routing::{delete, get, head, post, put},
Router,
};
use tower_cookies::CookieManagerLayer;
Expand All @@ -25,6 +25,7 @@ fn base(state: AppState) -> Router {
.route("/:pubky/session", delete(auth::signout))
.route("/:pubky/*path", put(public::put))
.route("/:pubky/*path", get(public::get))
.route("/:pubky/*path", head(public::head))
.route("/:pubky/*path", delete(public::delete))
.route("/events/", get(feed::feed))
.layer(CookieManagerLayer::new())
Expand Down
2 changes: 1 addition & 1 deletion pubky-homeserver/src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub async fn signin(
&mut wtxn,
public_key,
&User {
created_at: Timestamp::now().into_inner(),
created_at: Timestamp::now().as_u64(),
},
)?;
}
Expand Down
Loading
Loading