@@ -9,18 +9,62 @@ const bucket = new AWS.S3({params: {Bucket: bucketName}});
9
9
10
10
const urlPrefix = "https://s3-us-west-2.amazonaws.com/" + bucketName + '/' ;
11
11
12
- bucket . listObjectsV2 ( function ( err , data ) {
12
+ const params = {
13
+ Prefix : 'download'
14
+ } ;
15
+
16
+ bucket . listObjectsV2 ( params , function ( err , data ) {
13
17
if ( err ) {
14
18
document . getElementById ( 'status' ) . innerHTML =
15
19
'Could not load objects from S3 error: ' + err ;
16
20
} else {
17
21
document . getElementById ( 'spinner' ) . style . display = 'none' ;
18
22
document . getElementById ( 'status' ) . innerHTML = 'Loaded ' + data . Contents . length + ' items from S3' ;
19
-
20
- for ( var i = 0 ; i < data . Contents . length ; i ++ ) {
23
+ const objects = document . getElementById ( 'objects' ) ;
24
+ const list = document . createElement ( 'ul' ) ;
25
+ objects . appendChild ( list ) ;
26
+ for ( let i = 0 ; i < data . Contents . length ; i ++ ) {
21
27
let fileNameWithPath = data . Contents [ i ] . Key ;
22
28
let fileName = fileNameWithPath . substr ( fileNameWithPath . lastIndexOf ( '/' ) + 1 ) ;
23
- document . getElementById ( 'objects' ) . innerHTML += `<li><a href=${ urlPrefix } ${ data . Contents [ i ] . Key } >${ fileName } </a></li>`
29
+ const listItem = document . createElement ( "li" ) ;
30
+ const linkContainer = document . createElement ( 'span' ) ;
31
+ linkContainer . setAttribute ( 'class' , 'col-md-5' ) ;
32
+ const link = document . createElement ( "a" ) ;
33
+ link . setAttribute ( 'href' , `${ urlPrefix } ${ data . Contents [ i ] . Key } ` ) ;
34
+ link . appendChild ( document . createTextNode ( fileName ) ) ;
35
+ linkContainer . appendChild ( link ) ;
36
+ listItem . appendChild ( linkContainer ) ;
37
+ list . appendChild ( listItem ) ;
38
+ // Read meta data
39
+ const xhr = new XMLHttpRequest ( ) ;
40
+ xhr . open ( 'GET' , `${ urlPrefix } meta/${ fileName } .json` , true ) ;
41
+ xhr . send ( ) ;
42
+
43
+ xhr . onreadystatechange = ( e ) => {
44
+ if ( xhr . readyState == 4 && xhr . status == 200 ) {
45
+ const response = JSON . parse ( xhr . responseText ) ;
46
+ console . log ( "Success: " + response . time ) ;
47
+ const t = moment . unix ( response . time ) ;
48
+ t . utc ( ) ;
49
+ const formatted = t . format ( "YYYY-MM-DD HH:mm" ) ;
50
+ const gitText = `${ formatted } UTC | ${ response . commitMessage } | ${ response . sha . substring ( 0 , 7 ) } ` ;
51
+
52
+ const gitDetails = document . createElement ( 'span' ) ;
53
+ gitDetails . setAttribute ( 'id' , 'gitDetails' ) ;
54
+ gitDetails . setAttribute ( 'class' , 'col-md-7' ) ;
55
+ gitDetails . setAttribute ( 'data-toggle' , 'tooltip' ) ;
56
+ gitDetails . setAttribute ( 'title' , gitText ) ;
57
+ gitDetails . appendChild ( document . createTextNode ( gitText ) ) ;
58
+ listItem . appendChild ( gitDetails ) ;
59
+ }
60
+ else if ( xhr . readyState == 4 && xhr . status != 200 ) {
61
+ const gitDetails = document . createElement ( 'span' ) ;
62
+ gitDetails . setAttribute ( 'id' , 'gitDetails' ) ;
63
+ gitDetails . setAttribute ( 'class' , 'col-md-7' ) ;
64
+ gitDetails . appendChild ( document . createTextNode ( `N/A: ${ xhr . status } ` ) ) ;
65
+ listItem . appendChild ( gitDetails ) ;
66
+ }
67
+ } ;
24
68
}
25
69
}
26
70
} ) ;
0 commit comments