MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / check_profanity

Method check_profanity

ch_11/mock-server/src/lib.rs:24–59  ·  view source on GitHub ↗
(
        _: (),
        content: Bytes,
    )

Source from the content-addressed store, hash-verified

22 }
23
24 async fn check_profanity(
25 _: (),
26 content: Bytes,
27 ) -> Result<impl warp::Reply, warp::Rejection> {
28 let content = String::from_utf8(content.to_vec()).expect("Invalid UTF-8");
29 if content.contains("shitty") {
30 Ok(warp::reply::with_status(
31 warp::reply::json(&json!({
32 "bad_words_list": [
33 {
34 "deviations": 0,
35 "end": 16,
36 "info": 2,
37 "original": "shitty",
38 "replacedLen": 6,
39 "start": 10,
40 "word": "shitty"
41 }
42 ],
43 "bad_words_total": 1,
44 "censored_content": "this is a ****** sentence",
45 "content": "this is a shitty sentence"
46 })),
47 http::StatusCode::OK))
48 } else {
49 Ok(warp::reply::with_status(
50 warp::reply::json(&json!({
51 "bad_words_list": [],
52 "bad_words_total": 0,
53 "censored_content": "",
54 "content": "this is a sentence"
55 })),
56 http::StatusCode::OK,
57 ))
58 }
59 }
60
61 fn build_routes() -> impl Filter<Extract = impl Reply> + Clone {
62 warp::post()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected