tangled
alpha
login
or
join now
aleeve.dev
/
ott
2
fork
atom
Scalable and distributed custom feed generator, ott - on that topic
2
fork
atom
overview
issues
pulls
pipelines
Filter posts to only create records
aleeve.dev
5 months ago
eb0b9e43
6057734f
+9
-7
1 changed file
expand all
collapse all
unified
split
smart-modules
contruct-post-uri
src
lib.rs
+9
-7
smart-modules/contruct-post-uri/src/lib.rs
···
1
1
use eyre::eyre;
2
2
use fluvio_smartmodule::{RecordData, Result, SmartModuleRecord, smartmodule};
3
3
use serde_json::{Map, Value};
4
4
-
use std::str::FromStr;
5
4
6
6
-
#[smartmodule(map)]
7
7
-
pub fn map(record: &SmartModuleRecord) -> Result<(Option<RecordData>, RecordData)> {
5
5
+
#[smartmodule(filter_map)]
6
6
+
pub fn filter_map(record: &SmartModuleRecord) -> Result<Option<(Option<RecordData>, RecordData)>> {
8
7
let key = record.key.clone();
9
8
10
9
let string = std::str::from_utf8(record.value.as_ref())?;
···
13
12
.as_object_mut()
14
13
.ok_or(eyre!("Failed to parse value"))?;
15
14
16
16
-
let uri = get_uri(obj)?;
17
17
-
let uri_value = Value::String(uri);
18
18
-
obj.insert("uri".to_string(), uri_value);
15
15
+
if let Ok(uri) = get_uri(obj) {
16
16
+
let uri_value = Value::String(uri);
17
17
+
obj.insert("uri".to_string(), uri_value);
19
18
20
20
-
Ok((key, value.to_string().as_str().into()))
19
19
+
Ok(Some((key, value.to_string().as_str().into())))
20
20
+
} else {
21
21
+
Ok(None)
22
22
+
}
21
23
}
22
24
23
25
fn get_uri(obj: &Map<String, Value>) -> Result<String> {