From 6c0644ca98e6bb73ecae39e9b7e743d5921ba03e Mon Sep 17 00:00:00 2001 From: Nick Gerakines <12125+ngerakines@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:07:27 -0500 Subject: [PATCH] feature: optionally display deny post Signed-off-by: Nick Gerakines <12125+ngerakines@users.noreply.github.com> --- README.md | 12 +++--------- src/bin/supercell.rs | 2 +- src/config.rs | 7 ++++++- src/http/context.rs | 4 ++-- src/http/handle_get_feed_skeleton.rs | 24 ++++++++++++++++++------ 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f6cdc5b..395cfd3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,9 @@ The following environment variables are used: * `DATABASE_URL` - The URL of the database to use. * `JETSTREAM_HOSTNAME` - The hostname of the JetStream server to consume events from. * `ZSTD_DICTIONARY` - The path to the ZSTD dictionary to use. -* `CONSUMER_TASK_ENABLE` - Whether or not to enable the consumer tasks. +* `CONSUMER_TASK_ENABLE` - Whether or not to enable the consumer tasks. Default `true`. +* `VMC_TASK_ENABLE` - Whether or not to enable the VMC (verification method cache) tasks. Default `true`. +* `PLC_HOSTNAME` - The hostname of the PLC server to use for VMC tasks. Default `plc.directory`. * `FEEDS` - The path to the feeds configuration file. * `RUST_LOG` - Logging configuration. Defaults to `supercell=debug,info` @@ -69,14 +71,6 @@ The site [https://jsonpath.com/](https://jsonpath.com/) is a great resource for See the `config.example.yml` file for additional examples. -# TODO - -* use i64, it's fine -* possible scoring function for queries -* add likes -* support deletes -* document how to register a feed - # License This project is open source under the MIT license. diff --git a/src/bin/supercell.rs b/src/bin/supercell.rs index 6ce16fa..f5b48dd 100644 --- a/src/bin/supercell.rs +++ b/src/bin/supercell.rs @@ -48,7 +48,7 @@ async fn main() -> Result<()> { let pool = SqlitePool::connect(&config.database_url).await?; sqlx::migrate!().run(&pool).await?; - let feeds: HashMap)> = config + let feeds: HashMap, HashSet)> = config .feeds .feeds .iter() diff --git a/src/config.rs b/src/config.rs index c54e99b..c937888 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,8 +13,13 @@ pub struct Feed { pub uri: String, pub name: String, pub description: String, + + #[serde(default)] pub allow: HashSet, - pub deny: String, + + #[serde(default)] + pub deny: Option, + pub matchers: Vec, } diff --git a/src/http/context.rs b/src/http/context.rs index 581c0c6..3c65d82 100644 --- a/src/http/context.rs +++ b/src/http/context.rs @@ -9,7 +9,7 @@ use crate::storage::StoragePool; #[derive(Clone, Debug)] pub(crate) struct FeedControl { - pub(crate) deny: String, + pub(crate) deny: Option, pub(crate) allowed: HashSet, } @@ -34,7 +34,7 @@ impl WebContext { pub fn new( pool: StoragePool, external_base: &str, - feeds: HashMap)>, + feeds: HashMap, HashSet)>, ) -> Self { let feeds = feeds .into_iter() diff --git a/src/http/handle_get_feed_skeleton.rs b/src/http/handle_get_feed_skeleton.rs index f57da13..f22b5bb 100644 --- a/src/http/handle_get_feed_skeleton.rs +++ b/src/http/handle_get_feed_skeleton.rs @@ -72,9 +72,15 @@ pub async fn handle_get_feed_skeleton( tracing::error!(error = ?err, "failed to validate JWT"); return Ok(Json(FeedItemsView { cursor: None, - feed: vec![FeedItemView { - post: feed_control.deny.clone(), - }], + feed: feed_control + .deny + .as_ref() + .map(|value| { + vec![FeedItemView { + post: value.clone(), + }] + }) + .unwrap_or(vec![]), }) .into_response()); } @@ -84,9 +90,15 @@ pub async fn handle_get_feed_skeleton( if !feed_control.allowed.contains(&did) { return Ok(Json(FeedItemsView { cursor: None, - feed: vec![FeedItemView { - post: feed_control.deny.clone(), - }], + feed: feed_control + .deny + .as_ref() + .map(|value| { + vec![FeedItemView { + post: value.clone(), + }] + }) + .unwrap_or(vec![]), }) .into_response()); } -- 2.51.2