Skip to content

feat: allow fetching bookmark title from remote server - #21

Draft
dhth wants to merge 6 commits into
mainfrom
fetch-details-automatically
Draft

feat: allow fetching bookmark title from remote server#21
dhth wants to merge 6 commits into
mainfrom
fetch-details-automatically

Conversation

@dhth

@dhth dhth commented Mar 20, 2025

Copy link
Copy Markdown
Owner

Adds a flag to bmm save to allow fetching bookmark details from remote server.

  -F, --fetch                    Whether to fetch bookmark title automatically

@dhth dhth changed the title feat: allow fetching bk title from remote server feat: allow fetching bookmark title from remote server Mar 20, 2025
@github-actions

github-actions Bot commented Mar 20, 2025

Copy link
Copy Markdown

dstlled-diff

2b1afe4..0430529 -- **.rs

expand
diff --git a/2b1afe40/src/args.rs b/04305297/src/args.rs
index 2dcdec8..b948598 100644
--- a/2b1afe40/src/args.rs
+++ b/04305297/src/args.rs
@@ -97,0 +98,3 @@ pub enum BmmCommand {
+        /// Whether to fetch bookmark title automatically
+        #[arg(short = 'F', long = "fetch")]
+        fetch: bool,
diff --git a/2b1afe40/src/cli/save.rs b/04305297/src/cli/save.rs
index a5c9c93..113386b 100644
--- a/2b1afe40/src/cli/save.rs
+++ b/04305297/src/cli/save.rs
@@ -13,0 +14,4 @@ pub enum SaveBookmarkError {
+    #[error("couldn't fetch details: {0}")]
+    CouldntFetchDetails(#[from] FetchUriDetailsError),
+    #[error("no details fetched from remote server")]
+    NoDetailsFetched,
@@ -40,0 +45,7 @@ pub enum ParsingTempFileContentError {
+pub struct SaveConfig {
+    pub use_editor: bool,
+    pub fail_if_uri_already_saved: bool,
+    pub reset_missing: bool,
+    pub ignore_attribute_errors: bool,
+    pub fetch: bool,
+}
@@ -43,5 +54,4 @@ pub fn save_bookmark(
-    potential_bookmark: PotentialBookmark,
-    use_editor: bool,
-    fail_if_uri_saved: bool,
-    reset_missing: bool,
-    ignore_attribute_errors: bool,
+    uri: String,
+    title: Option<String>,
+    tags: &[String],
+    save_config: SaveConfig,
@@ -50 +60,3 @@ fn get_bookmark_update_details_from_temp_file(
-    bookmark: &SavedBookmark,
+    uri: &str,
+    title: Option<&str>,
+    tags: Option<&str>,
@@ -53,0 +66,2 @@ fn get_new_bookmark_details_from_temp_file(
+    title: Option<&str>,
+    tags: Option<&str>,
@@ -57,2 +71,10 @@ fn get_env_var(key: &str) -> Result<String, CouldntGetDetailsViaEditorError>
-fn get_update_bookmark_tmp_file_contents(bookmark: &SavedBookmark) -> String
-fn get_create_bookmark_tmp_file_contents(uri: &str) -> String
+fn get_update_bookmark_tmp_file_contents(
+    uri: &str,
+    title: Option<&str>,
+    tags: Option<&str>,
+) -> String
+fn get_create_bookmark_tmp_file_contents(
+    uri: &str,
+    title: Option<&str>,
+    tags: Option<&str>,
+) -> String
diff --git a/04305297/src/service/fetch.rs b/04305297/src/service/fetch.rs
new file mode 100644
index 0000000..68113f8
--- /dev/null
+++ b/04305297/src/service/fetch.rs
@@ -0,0 +1,13 @@
+pub enum FetchUriDetailsError {
+    #[error("uri is incorrect: {0}")]
+    IncorrectUri(#[from] ParseError),
+    #[error(transparent)]
+    RequestUri(#[from] ReqwestError),
+}
+pub fn fetch_uri_details(uri: &str) -> Result<Option<String>, FetchUriDetailsError>
+fn get_title_from_html(html: &str) -> Option<String>
+fn parsing_simple_html_works()
+fn parsing_html_with_og_tags_only_works()
+fn parsing_html_with_both_title_and_og_tags_works()
+fn parsing_empty_html_works()
+fn parsing_incorrect_html_works()
diff --git a/2b1afe40/tests/save_test.rs b/04305297/tests/save_test.rs
index 4fa43d0..c390063 100644
--- a/2b1afe40/tests/save_test.rs
+++ b/04305297/tests/save_test.rs
@@ -2,0 +3 @@ fn saving_a_new_bookmark_with_title_and_tags_works()
+fn updating_bookmarks_with_no_new_data_works()
@@ -4 +5,3 @@ fn extending_tags_for_a_saved_bookmark_works()
-fn resetting_properties_on_bookmark_update_works()
+fn resetting_all_data_for_a_bookmark_works()
+fn resetting_title_on_bookmark_update_works()
+fn resetting_tags_on_bookmark_update_works()
@@ -6,0 +10 @@ fn force_saving_a_new_bookmark_with_invalid_tags_works()
+fn fetching_title_from_remote_server_works()
@@ -8,0 +13 @@ fn saving_a_new_bookmark_with_an_invalid_tag_fails()
+fn updating_a_bookmarks_with_no_new_details_fails_if_requested()
@@ -10,0 +16 @@ fn saving_a_new_bookmark_with_incorrect_text_editor_configured_fails()
+fn fetching_details_for_non_existent_uri_should_fail()

@dhth dhth linked an issue Mar 20, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically fetch uri title

1 participant