also remove post from list if unlist is set
This commit is contained in:
parent
c68263a7bd
commit
7de1212993
3 changed files with 19 additions and 7 deletions
10
src/blog.rs
10
src/blog.rs
|
@ -42,10 +42,18 @@ impl PostsList {
|
|||
if self.has_post(uuid) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
self.0.insert(0, uuid.into());
|
||||
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)]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![feature(vec_remove_item)]
|
||||
|
||||
#[macro_use]
|
||||
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)]
|
||||
struct CustomMetadata {
|
||||
// If unlist is set to TRUE upon first publication,
|
||||
// the post won't be listed publicly on the blog.
|
||||
// However, this has no effect if set to TRUE after first publication.
|
||||
// (setting to FALSE after first publication MAY work)
|
||||
// You will have to first delete the blog before changing this value.
|
||||
// If unlist is set to TRUE,
|
||||
// the post won't be listed publicly on the blog,
|
||||
// and if the post were published, it will
|
||||
// be removed from the public list
|
||||
unlist: Option<bool>,
|
||||
url: Option<String>,
|
||||
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
|
||||
// This is fine because we don't expect users to update posts from
|
||||
// multiple endpoints simultaneously all the time
|
||||
let list = blog::PostsList::load().await;
|
||||
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?;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue