@@ -10,20 +10,15 @@ use crate::controllers::helpers::pagination::*;
10
10
use crate :: email;
11
11
use crate :: models:: version:: TopVersions ;
12
12
use crate :: models:: {
13
- Badge , Category , CrateOwner , CrateOwnerInvitation , Keyword , NewCrateOwnerInvitation , Owner ,
14
- OwnerKind , ReverseDependency , User , Version ,
13
+ Badge , CrateOwner , CrateOwnerInvitation , NewCrateOwnerInvitation , Owner , OwnerKind ,
14
+ ReverseDependency , User , Version ,
15
15
} ;
16
16
use crate :: util:: errors:: { cargo_err, AppResult } ;
17
- use crate :: views:: { EncodableCrate , EncodableCrateLinks } ;
18
17
19
18
use crate :: models:: helpers:: with_count:: * ;
20
19
use crate :: publish_rate_limit:: PublishRateLimit ;
21
20
use crate :: schema:: * ;
22
21
23
- /// Hosts in this list are known to not be hosting documentation,
24
- /// and are possibly of malicious intent e.g. ad tracking networks, etc.
25
- const DOCUMENTATION_BLOCKLIST : [ & str ; 2 ] = [ "rust-ci.org" , "rustless.org" ] ;
26
-
27
22
#[ derive( Debug , Queryable , Identifiable , Associations , Clone , Copy ) ]
28
23
#[ belongs_to( Crate ) ]
29
24
#[ primary_key( crate_id) ]
@@ -296,127 +291,6 @@ impl Crate {
296
291
&& prefix_part. map_or ( true , Crate :: valid_feature_prefix)
297
292
}
298
293
299
- pub fn minimal_encodable (
300
- self ,
301
- top_versions : & TopVersions ,
302
- badges : Option < Vec < Badge > > ,
303
- exact_match : bool ,
304
- recent_downloads : Option < i64 > ,
305
- ) -> EncodableCrate {
306
- self . encodable (
307
- top_versions,
308
- None ,
309
- None ,
310
- None ,
311
- badges,
312
- exact_match,
313
- recent_downloads,
314
- )
315
- }
316
-
317
- #[ allow( clippy:: too_many_arguments) ]
318
- pub fn encodable (
319
- self ,
320
- top_versions : & TopVersions ,
321
- versions : Option < Vec < i32 > > ,
322
- keywords : Option < & [ Keyword ] > ,
323
- categories : Option < & [ Category ] > ,
324
- badges : Option < Vec < Badge > > ,
325
- exact_match : bool ,
326
- recent_downloads : Option < i64 > ,
327
- ) -> EncodableCrate {
328
- let Crate {
329
- name,
330
- created_at,
331
- updated_at,
332
- downloads,
333
- description,
334
- homepage,
335
- documentation,
336
- repository,
337
- ..
338
- } = self ;
339
- let versions_link = match versions {
340
- Some ( ..) => None ,
341
- None => Some ( format ! ( "/api/v1/crates/{}/versions" , name) ) ,
342
- } ;
343
- let keyword_ids = keywords. map ( |kws| kws. iter ( ) . map ( |kw| kw. keyword . clone ( ) ) . collect ( ) ) ;
344
- let category_ids = categories. map ( |cats| cats. iter ( ) . map ( |cat| cat. slug . clone ( ) ) . collect ( ) ) ;
345
- let badges = badges. map ( |bs| bs. into_iter ( ) . map ( Badge :: into) . collect ( ) ) ;
346
- let documentation = Crate :: remove_blocked_documentation_urls ( documentation) ;
347
-
348
- let max_version = top_versions
349
- . highest
350
- . as_ref ( )
351
- . map ( |v| v. to_string ( ) )
352
- . unwrap_or_else ( || "0.0.0" . to_string ( ) ) ;
353
-
354
- let newest_version = top_versions
355
- . newest
356
- . as_ref ( )
357
- . map ( |v| v. to_string ( ) )
358
- . unwrap_or_else ( || "0.0.0" . to_string ( ) ) ;
359
-
360
- let max_stable_version = top_versions. highest_stable . as_ref ( ) . map ( |v| v. to_string ( ) ) ;
361
-
362
- EncodableCrate {
363
- id : name. clone ( ) ,
364
- name : name. clone ( ) ,
365
- updated_at,
366
- created_at,
367
- downloads,
368
- recent_downloads,
369
- versions,
370
- keywords : keyword_ids,
371
- categories : category_ids,
372
- badges,
373
- max_version,
374
- newest_version,
375
- max_stable_version,
376
- documentation,
377
- homepage,
378
- exact_match,
379
- description,
380
- repository,
381
- links : EncodableCrateLinks {
382
- version_downloads : format ! ( "/api/v1/crates/{}/downloads" , name) ,
383
- versions : versions_link,
384
- owners : Some ( format ! ( "/api/v1/crates/{}/owners" , name) ) ,
385
- owner_team : Some ( format ! ( "/api/v1/crates/{}/owner_team" , name) ) ,
386
- owner_user : Some ( format ! ( "/api/v1/crates/{}/owner_user" , name) ) ,
387
- reverse_dependencies : format ! ( "/api/v1/crates/{}/reverse_dependencies" , name) ,
388
- } ,
389
- }
390
- }
391
-
392
- /// Return `None` if the documentation URL host matches a blocked host
393
- fn remove_blocked_documentation_urls ( url : Option < String > ) -> Option < String > {
394
- // Handles if documentation URL is None
395
- let url = match url {
396
- Some ( url) => url,
397
- None => return None ,
398
- } ;
399
-
400
- // Handles unsuccessful parsing of documentation URL
401
- let parsed_url = match Url :: parse ( & url) {
402
- Ok ( parsed_url) => parsed_url,
403
- Err ( _) => return None ,
404
- } ;
405
-
406
- // Extract host string from documentation URL
407
- let url_host = match parsed_url. host_str ( ) {
408
- Some ( url_host) => url_host,
409
- None => return None ,
410
- } ;
411
-
412
- // Match documentation URL host against blocked host array elements
413
- if DOCUMENTATION_BLOCKLIST . contains ( & url_host) {
414
- None
415
- } else {
416
- Some ( url)
417
- }
418
- }
419
-
420
294
/// Return both the newest (most recently updated) and
421
295
/// highest version (in semver order) for the current crate.
422
296
pub fn top_versions ( & self , conn : & PgConnection ) -> QueryResult < TopVersions > {
@@ -576,39 +450,6 @@ mod tests {
576
450
assert_err ! ( krate. validate( ) ) ;
577
451
}
578
452
579
- #[ test]
580
- fn documentation_blocked_no_url_provided ( ) {
581
- assert_eq ! ( Crate :: remove_blocked_documentation_urls( None ) , None ) ;
582
- }
583
-
584
- #[ test]
585
- fn documentation_blocked_invalid_url ( ) {
586
- assert_eq ! (
587
- Crate :: remove_blocked_documentation_urls( Some ( String :: from( "not a url" ) ) ) ,
588
- None
589
- ) ;
590
- }
591
-
592
- #[ test]
593
- fn documentation_blocked_url_contains_partial_match ( ) {
594
- assert_eq ! (
595
- Crate :: remove_blocked_documentation_urls( Some ( String :: from(
596
- "http://rust-ci.organists.com"
597
- ) ) , ) ,
598
- Some ( String :: from( "http://rust-ci.organists.com" ) )
599
- ) ;
600
- }
601
-
602
- #[ test]
603
- fn documentation_blocked_url ( ) {
604
- assert_eq ! (
605
- Crate :: remove_blocked_documentation_urls( Some ( String :: from(
606
- "http://rust-ci.org/crate/crate-0.1/doc/crate-0.1" ,
607
- ) , ) , ) ,
608
- None
609
- ) ;
610
- }
611
-
612
453
#[ test]
613
454
fn valid_name ( ) {
614
455
assert ! ( Crate :: valid_name( "foo" ) ) ;
0 commit comments