From 074245733e993b6c633e00c323964cce3d902292 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sun, 18 May 2025 08:59:05 +0000
Subject: [PATCH] chore(nostr): A util to get the content from a string or
editor
Signed-off-by: Awiteb
---
src/nostr_utils/utils.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/nostr_utils/utils.rs b/src/nostr_utils/utils.rs
index 4a77c72..6158fe1 100644
--- a/src/nostr_utils/utils.rs
+++ b/src/nostr_utils/utils.rs
@@ -184,3 +184,14 @@ pub fn read_editor(file_suffix: &str) -> N34Result {
}
Ok(content)
}
+
+/// Returns the given content if it's `Option::Some` or call [`read_editor`]
+pub fn get_content(content: Option, file_suffix: &str) -> N34Result
+where
+ S: AsRef,
+{
+ if let Some(content) = content {
+ return Ok(content.as_ref().trim().to_owned());
+ }
+ read_editor(file_suffix)
+}