add themes, add public and private msg publishing
This commit is contained in:
41
peach-web/src/routes/scuttlebutt/publish.rs
Normal file
41
peach-web/src/routes/scuttlebutt/publish.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use peach_lib::sbot::SbotStatus;
|
||||
use rouille::{post_input, try_or_400, Request, Response};
|
||||
|
||||
use crate::utils::{flash::FlashResponse, sbot};
|
||||
|
||||
// ROUTE: /scuttlebutt/publish
|
||||
|
||||
/// Publish a public Scuttlebutt post.
|
||||
///
|
||||
/// Parse the post text from the submitted form and publish the message.
|
||||
/// Redirect to the profile page of the PeachCloud local identity with a flash
|
||||
/// message describing the outcome of the action (may be successful or
|
||||
/// unsuccessful).
|
||||
pub fn handle_form(request: &Request) -> Response {
|
||||
// query the request body for form data
|
||||
// return a 400 error if the admin_id field is missing
|
||||
let data = try_or_400!(post_input!(request, {
|
||||
text: String,
|
||||
}));
|
||||
|
||||
let (flash_name, flash_msg) = match SbotStatus::read() {
|
||||
Ok(status) if status.state == Some("active".to_string()) => {
|
||||
match sbot::publish_public_post(data.text) {
|
||||
Ok(success_msg) => (
|
||||
"flash_name=success".to_string(),
|
||||
format!("flash_msg={}", success_msg),
|
||||
),
|
||||
Err(error_msg) => (
|
||||
"flash_name=error".to_string(),
|
||||
format!("flash_msg={}", error_msg),
|
||||
),
|
||||
}
|
||||
}
|
||||
_ => (
|
||||
"flash_name=warning".to_string(),
|
||||
"Public posting is unavailable.".to_string(),
|
||||
),
|
||||
};
|
||||
|
||||
Response::redirect_303("/scuttlebutt/profile").add_flash(flash_name, flash_msg)
|
||||
}
|
Reference in New Issue
Block a user