mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-23 03:04:19 +01:00
split notedeck into crates
This splits notedeck into crates, separating the browser chrome and individual apps: * notedeck: binary file, browser chrome * notedeck_columns: our columns app * enostr: same as before We still need to do more work to cleanly separate the chrome apis from the app apis. Soon I will create notedeck-notebook to see what makes sense to be shared between the apps. Some obvious ones that come to mind: 1. ImageCache We will likely want to move this to the notedeck crate, as most apps will want some kind of image cache. In web browsers, web pages do not need to worry about this, so we will likely have to do something similar 2. Ndb Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely copied to each app. This will simplify things. In the future we might want to create an abstraction over this? Maybe each app shouldn't have access to the same database... we assume the data in DBs are all public anyways, but if we have unwrapped giftwraps that could be a problem. 3. RelayPool / Subscription Manager The browser should probably maintain these. Then apps can use ken's high level subscription manager api and not have to worry about connection pool details 4. Accounts Accounts and key management should be handled by the chrome. Apps should only have a simple signer interface. That's all for now, just something to think about! Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
148
crates/notedeck_columns/src/support.rs
Normal file
148
crates/notedeck_columns/src/support.rs
Normal file
@@ -0,0 +1,148 @@
|
||||
use tracing::error;
|
||||
|
||||
use crate::storage::{DataPath, DataPathType, Directory};
|
||||
|
||||
pub struct Support {
|
||||
directory: Directory,
|
||||
mailto_url: String,
|
||||
most_recent_log: Option<String>,
|
||||
}
|
||||
|
||||
fn new_log_dir(paths: &DataPath) -> Directory {
|
||||
Directory::new(paths.path(DataPathType::Log))
|
||||
}
|
||||
|
||||
impl Support {
|
||||
pub fn new(path: &DataPath) -> Self {
|
||||
let directory = new_log_dir(path);
|
||||
|
||||
Self {
|
||||
mailto_url: MailtoBuilder::new(SUPPORT_EMAIL.to_string())
|
||||
.with_subject("Help Needed".to_owned())
|
||||
.with_content(EMAIL_TEMPLATE.to_owned())
|
||||
.build(),
|
||||
directory,
|
||||
most_recent_log: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static MAX_LOG_LINES: usize = 500;
|
||||
static SUPPORT_EMAIL: &str = "support@damus.io";
|
||||
static EMAIL_TEMPLATE: &str = concat!("version ", env!("CARGO_PKG_VERSION"), "\nCommit hash: ", env!("GIT_COMMIT_HASH"), "\n\nDescribe the bug you have encountered:\n<-- your statement here -->\n\n===== Paste your log below =====\n\n");
|
||||
|
||||
impl Support {
|
||||
pub fn refresh(&mut self) {
|
||||
self.most_recent_log = get_log_str(&self.directory);
|
||||
}
|
||||
|
||||
pub fn get_mailto_url(&self) -> &str {
|
||||
&self.mailto_url
|
||||
}
|
||||
|
||||
pub fn get_log_dir(&self) -> Option<&str> {
|
||||
self.directory.file_path.to_str()
|
||||
}
|
||||
|
||||
pub fn get_most_recent_log(&self) -> Option<&String> {
|
||||
self.most_recent_log.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_log_str(interactor: &Directory) -> Option<String> {
|
||||
match interactor.get_most_recent() {
|
||||
Ok(Some(most_recent_name)) => {
|
||||
match interactor.get_file_last_n_lines(most_recent_name.clone(), MAX_LOG_LINES) {
|
||||
Ok(file_output) => {
|
||||
return Some(
|
||||
get_prefix(
|
||||
&most_recent_name,
|
||||
file_output.output_num_lines,
|
||||
file_output.total_lines_in_file,
|
||||
) + &file_output.output,
|
||||
)
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
"Error retrieving the last lines from file {}: {:?}",
|
||||
most_recent_name, e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
error!("No files were found.");
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error fetching the most recent file: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn get_prefix(file_name: &str, lines_displayed: usize, num_total_lines: usize) -> String {
|
||||
format!(
|
||||
"===\nDisplaying the last {} of {} lines in file {}\n===\n\n",
|
||||
lines_displayed, num_total_lines, file_name,
|
||||
)
|
||||
}
|
||||
|
||||
struct MailtoBuilder {
|
||||
content: Option<String>,
|
||||
address: String,
|
||||
subject: Option<String>,
|
||||
}
|
||||
|
||||
impl MailtoBuilder {
|
||||
fn new(address: String) -> Self {
|
||||
Self {
|
||||
content: None,
|
||||
address,
|
||||
subject: None,
|
||||
}
|
||||
}
|
||||
|
||||
// will be truncated so the whole URL is at most 2000 characters
|
||||
pub fn with_content(mut self, content: String) -> Self {
|
||||
self.content = Some(content);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_subject(mut self, subject: String) -> Self {
|
||||
self.subject = Some(subject);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> String {
|
||||
let mut url = String::new();
|
||||
|
||||
url.push_str("mailto:");
|
||||
url.push_str(&self.address);
|
||||
|
||||
let has_subject = self.subject.is_some();
|
||||
|
||||
if has_subject || self.content.is_some() {
|
||||
url.push('?');
|
||||
}
|
||||
|
||||
if let Some(subject) = self.subject {
|
||||
url.push_str("subject=");
|
||||
url.push_str(&urlencoding::encode(&subject));
|
||||
}
|
||||
|
||||
if let Some(content) = self.content {
|
||||
if has_subject {
|
||||
url.push('&');
|
||||
}
|
||||
|
||||
url.push_str("body=");
|
||||
|
||||
let body = urlencoding::encode(&content);
|
||||
|
||||
url.push_str(&body);
|
||||
}
|
||||
|
||||
url
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user