@@ -5,52 +5,36 @@ export class MavenAccess {
5
5
const url = `/maven2/${ groupId . replaceAll ( "." , "/" ) } /${ artifactId
6
6
} /${ version } /${ artifactId } -${ version } .pom`;
7
7
8
- const pom = await fetch ( url )
8
+ return await fetch ( url )
9
9
. then ( ( response ) => response . text ( ) )
10
10
. then ( ( str ) => {
11
11
const parser = new XMLParser ( ) ;
12
12
return parser . parse ( str ) . project ;
13
13
} )
14
14
. catch ( ( reason ) => console . error ( reason ) ) ;
15
- return pom ;
16
15
}
17
16
18
- async getArtifact ( groupId : string , artifactId : string ) : Promise < any > {
19
- const url = `/maven2/${ groupId . replaceAll ( "." , "/" ) } /${ artifactId } /` ;
20
-
21
- const artifacts = await fetch ( url )
17
+ private async retrieveAndProcessDirectory ( url : string ) : Promise < any > {
18
+ return await fetch ( url )
22
19
. then ( ( response ) => response . text ( ) )
23
20
. then ( ( text ) => {
24
21
const parser = new DOMParser ( ) ;
25
22
return Array . from ( parser . parseFromString ( text , "text/html" )
26
- . getElementById ( "contents" )
27
- ?. querySelectorAll ( "A" ) ! )
28
- . slice ( 1 ) . map ( a => a . textContent )
29
- . filter ( link => link ?. endsWith ( "/" ) )
30
- . map ( link => link ?. replace ( "/" , "" ) ) ;
23
+ . getElementById ( "contents" )
24
+ ?. querySelectorAll ( "A" ) ! )
25
+ . slice ( 1 ) . map ( a => a . textContent )
26
+ . filter ( link => link ?. endsWith ( "/" ) )
27
+ . map ( link => link ?. replace ( "/" , "" ) ) ;
31
28
} )
32
29
. catch ( ( reason ) => console . error ( reason ) ) ;
30
+ }
33
31
34
- return artifacts ;
32
+ async getArtifact ( groupId : string , artifactId : string ) : Promise < any > {
33
+ return this . retrieveAndProcessDirectory ( `/maven2/${ groupId . replaceAll ( "." , "/" ) } /${ artifactId } /` ) ;
35
34
}
36
35
37
36
async getGroup ( groupId : string ) : Promise < any > {
38
- const url = `/maven2/${ groupId . replaceAll ( "." , "/" ) } /` ;
39
-
40
- const group = await fetch ( url )
41
- . then ( ( response ) => response . text ( ) )
42
- . then ( ( text ) => {
43
- const parser = new DOMParser ( ) ;
44
- return Array . from ( parser . parseFromString ( text , "text/html" )
45
- . getElementById ( "contents" )
46
- ?. querySelectorAll ( "A" ) ! )
47
- . slice ( 1 ) . map ( a => a . textContent )
48
- . filter ( link => link ?. endsWith ( "/" ) )
49
- . map ( link => link ?. replace ( "/" , "" ) ) ;
50
- } )
51
- . catch ( ( reason ) => console . error ( reason ) ) ;
52
-
53
- return group ;
37
+ return this . retrieveAndProcessDirectory ( `/maven2/${ groupId . replaceAll ( "." , "/" ) } /` ) ;
54
38
}
55
39
56
40
0 commit comments