@@ -98,30 +98,24 @@ pub async fn bulk_check_hash_exists(
98
98
mongo_uri : & str ,
99
99
) -> Result < HashSet < String > , Box < dyn std:: error:: Error > > {
100
100
let client = connect_to_mongodb ( mongo_uri, "code-security-open-source" ) . await ?;
101
- // let existing_hashes = find_messages_in_hashes(&client, hashes).await?;
102
- // returb blank HashSet if no hashes found
103
- let existing_hashes = HashSet :: new ( ) ;
104
- let blank_hashset = HashSet :: new ( ) ;
105
- if existing_hashes. is_empty ( ) {
106
- return Ok ( blank_hashset) ;
107
- }
101
+ let existing_hashes = find_messages_in_hashes ( & client, hashes) . await ?;
108
102
Ok ( existing_hashes)
109
103
}
110
104
111
105
pub async fn register_hash ( message : & str , mongo_uri : & str ) {
112
106
let hashed_message = hash_text ( message) ;
113
- // match connect_to_mongodb(mongo_uri, "code-security-open-source").await {
114
- // Ok(client) => {
115
- // let collection = client
116
- // .database("code-security-open-source")
117
- // .collection("hashes");
118
- // let document = doc! { "message": hashed_message };
119
- // collection.insert_one(document, None).await.unwrap();
120
- // }
121
- // Err(e) => {
122
- // print_error(&format!("Error: {}", e.to_string()), 101);
123
- // }
124
- // }
107
+ match connect_to_mongodb ( mongo_uri, "code-security-open-source" ) . await {
108
+ Ok ( client) => {
109
+ let collection = client
110
+ . database ( "code-security-open-source" )
111
+ . collection ( "hashes" ) ;
112
+ let document = doc ! { "message" : hashed_message } ;
113
+ collection. insert_one ( document, None ) . await . unwrap ( ) ;
114
+ }
115
+ Err ( e) => {
116
+ print_error ( & format ! ( "Error: {}" , e. to_string( ) ) , 101 ) ;
117
+ }
118
+ }
125
119
}
126
120
pub fn print_error ( error : & str , error_code : i32 ) {
127
121
if error. to_lowercase ( ) . starts_with ( "warning" ) {
0 commit comments