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

Add uri parser and object importer #15

Merged
merged 9 commits into from
Feb 3, 2025
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
3 changes: 2 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub static VERSION: &str = "0.3.0";
pub static APP_PATH: &str = "/pub/pubky.app/";
pub static PUBLIC_PATH: &str = "/pub/";
pub static APP_PATH: &str = "pubky.app/";
pub static PROTOCOL: &str = "pubky://";

#[cfg(target_arch = "wasm32")]
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ mod common;
mod models;
pub mod traits;
mod types;
mod uri_parser;
mod utils;

// Re-export domain types
pub use common::{APP_PATH, PROTOCOL, VERSION};
pub use common::{APP_PATH, PROTOCOL, PUBLIC_PATH, VERSION};
pub use models::blob::PubkyAppBlob;
pub use models::bookmark::PubkyAppBookmark;
pub use models::feed::{PubkyAppFeed, PubkyAppFeedLayout, PubkyAppFeedReach, PubkyAppFeedSort};
pub use models::file::PubkyAppFile;
pub use models::file_blob::PubkyAppBlob;
pub use models::follow::PubkyAppFollow;
pub use models::last_read::PubkyAppLastRead;
pub use models::mute::PubkyAppMute;
pub use models::post::{PubkyAppPost, PubkyAppPostEmbed, PubkyAppPostKind};
pub use models::tag::PubkyAppTag;
pub use models::user::{PubkyAppUser, PubkyAppUserLink};
pub use models::PubkyAppObject;
pub use types::PubkyId;
pub use uri_parser::{ParsedUri, Resource};
pub use utils::*;

// Our WASM module
Expand Down
6 changes: 4 additions & 2 deletions src/models/file_blob.rs → src/models/blob.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
traits::{HasPath, HashId, Validatable},
APP_PATH,
APP_PATH, PUBLIC_PATH,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -67,8 +67,10 @@ impl HashId for PubkyAppBlob {
}

impl HasPath for PubkyAppBlob {
const PATH_SEGMENT: &'static str = "blobs/";

fn create_path(&self) -> String {
format!("{}blobs/{}", APP_PATH, self.create_id())
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT, &self.create_id()].concat()
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/models/bookmark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::timestamp,
traits::{HasPath, HashId, Validatable},
APP_PATH,
APP_PATH, PUBLIC_PATH,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -65,8 +65,10 @@ impl HashId for PubkyAppBookmark {
}

impl HasPath for PubkyAppBookmark {
const PATH_SEGMENT: &'static str = "bookmarks/";

fn create_path(&self) -> String {
format!("{}bookmarks/{}", APP_PATH, self.create_id())
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT, &self.create_id()].concat()
}
}

Expand Down Expand Up @@ -101,7 +103,7 @@ mod tests {
created_at: 1627849723,
};
let expected_id = bookmark.create_id();
let expected_path = format!("{}bookmarks/{}", APP_PATH, expected_id);
let expected_path = format!("{}{}bookmarks/{}", PUBLIC_PATH, APP_PATH, expected_id);
let path = bookmark.create_path();
assert_eq!(path, expected_path);
}
Expand Down
6 changes: 4 additions & 2 deletions src/models/feed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::timestamp,
traits::{HasPath, HashId, Validatable},
PubkyAppPostKind, APP_PATH,
PubkyAppPostKind, APP_PATH, PUBLIC_PATH,
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
Expand Down Expand Up @@ -179,8 +179,10 @@ impl HashId for PubkyAppFeed {
}

impl HasPath for PubkyAppFeed {
const PATH_SEGMENT: &'static str = "feeds/";

fn create_path(&self) -> String {
format!("{}feeds/{}", APP_PATH, self.create_id())
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT, &self.create_id()].concat()
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/models/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::timestamp,
traits::{HasPath, TimestampId, Validatable},
APP_PATH,
APP_PATH, PUBLIC_PATH,
};
use mime::Mime;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -104,8 +104,10 @@ impl PubkyAppFile {
impl TimestampId for PubkyAppFile {}

impl HasPath for PubkyAppFile {
const PATH_SEGMENT: &'static str = "files/";

fn create_path(&self) -> String {
format!("{}files/{}", APP_PATH, self.create_id())
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT, &self.create_id()].concat()
}
}

Expand Down Expand Up @@ -208,7 +210,7 @@ mod tests {
let path = file.create_path();

// Check if the path starts with the expected prefix
let prefix = format!("{}files/", APP_PATH);
let prefix = format!("{}{}files/", PUBLIC_PATH, APP_PATH);
assert!(path.starts_with(&prefix));

let expected_path_len = prefix.len() + file_id.len();
Expand Down
6 changes: 4 additions & 2 deletions src/models/follow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::timestamp,
traits::{HasPubkyIdPath, Validatable},
APP_PATH,
APP_PATH, PUBLIC_PATH,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -61,8 +61,10 @@ impl Validatable for PubkyAppFollow {
}

impl HasPubkyIdPath for PubkyAppFollow {
const PATH_SEGMENT: &'static str = "follows/";

fn create_path(&self, pubky_id: &str) -> String {
format!("{}follows/{}", APP_PATH, pubky_id)
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT, pubky_id].concat()
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/models/last_read.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
common::timestamp,
traits::{HasPath, Validatable},
APP_PATH,
APP_PATH, PUBLIC_PATH,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -54,8 +54,10 @@ impl Validatable for PubkyAppLastRead {
}

impl HasPath for PubkyAppLastRead {
const PATH_SEGMENT: &'static str = "last_read";

fn create_path(&self) -> String {
format!("{}last_read", APP_PATH)
[PUBLIC_PATH, APP_PATH, Self::PATH_SEGMENT].concat()
}
}

Expand All @@ -76,7 +78,7 @@ mod tests {
fn test_create_path() {
let last_read = PubkyAppLastRead::new();
let path = last_read.create_path();
assert_eq!(path, format!("{}last_read", APP_PATH));
assert_eq!(path, format!("{}{}last_read", PUBLIC_PATH, APP_PATH));
}

#[test]
Expand Down
Loading