also remove post from list if unlist is set
This commit is contained in:
parent
c68263a7bd
commit
7de1212993
10
src/blog.rs
10
src/blog.rs
|
@ -42,10 +42,18 @@ impl PostsList {
|
||||||
if self.has_post(uuid) {
|
if self.has_post(uuid) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.0.insert(0, uuid.into());
|
self.0.insert(0, uuid.into());
|
||||||
store::put_obj_pretty("posts_list", self.0).await
|
store::put_obj_pretty("posts_list", self.0).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove a post from published list
|
||||||
|
// may be used when deleting / unpublishing a post
|
||||||
|
// Does nothing if uuid not found in list
|
||||||
|
pub async fn remove_post(mut self, uuid: &str) -> MyResult<()> {
|
||||||
|
self.0.remove_item(&uuid);
|
||||||
|
store::put_obj_pretty("posts_list", self.0).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![feature(vec_remove_item)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
|
|
14
src/sn.rs
14
src/sn.rs
|
@ -75,11 +75,10 @@ async fn get_actions(_req: Request, url: Url) -> MyResult<Response> {
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct CustomMetadata {
|
struct CustomMetadata {
|
||||||
// If unlist is set to TRUE upon first publication,
|
// If unlist is set to TRUE,
|
||||||
// the post won't be listed publicly on the blog.
|
// the post won't be listed publicly on the blog,
|
||||||
// However, this has no effect if set to TRUE after first publication.
|
// and if the post were published, it will
|
||||||
// (setting to FALSE after first publication MAY work)
|
// be removed from the public list
|
||||||
// You will have to first delete the blog before changing this value.
|
|
||||||
unlist: Option<bool>,
|
unlist: Option<bool>,
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
timestamp: Option<String> // Should be something `js_sys::Date::parse` could handle
|
timestamp: Option<String> // Should be something `js_sys::Date::parse` could handle
|
||||||
|
@ -203,8 +202,11 @@ async fn create_or_update_post(req: Request, url: Url) -> MyResult<Response> {
|
||||||
// As you may have seen by now, the process is far from atomic
|
// As you may have seen by now, the process is far from atomic
|
||||||
// This is fine because we don't expect users to update posts from
|
// This is fine because we don't expect users to update posts from
|
||||||
// multiple endpoints simultaneously all the time
|
// multiple endpoints simultaneously all the time
|
||||||
|
let list = blog::PostsList::load().await;
|
||||||
if !metadata.unlist {
|
if !metadata.unlist {
|
||||||
blog::PostsList::load().await.add_post(&post.uuid).await?;
|
list.add_post(&post.uuid).await?;
|
||||||
|
} else {
|
||||||
|
list.remove_post(&post.uuid).await?;
|
||||||
}
|
}
|
||||||
post.write_to_kv().await?;
|
post.write_to_kv().await?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue