File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
packages/cloudfront-signer/src Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,18 @@ import { getSignedCookies, getSignedUrl } from "./index";
77const url = "https://d111111abcdef8.cloudfront.net/private-content/private.jpeg" ;
88const keyPairId = "APKAEIBAERJR2EXAMPLE" ;
99const dateLessThan = "2020-01-01" ;
10- const epochDateLessThan = Math . round ( new Date ( dateLessThan ) . getTime ( ) / 1000 ) ;
10+ const epochDateLessThan = Math . round (
11+ ( typeof dateLessThan === "string" && / ^ \d + $ / . test ( dateLessThan )
12+ ? Number ( dateLessThan )
13+ : new Date ( dateLessThan ) . getTime ( ) ) / 1000
14+ ) ;
1115const dateGreaterThan = "2019-12-01" ;
12- const epochDateGreaterThan = Math . round ( new Date ( dateGreaterThan ) . getTime ( ) / 1000 ) ;
16+ const epochDateGreaterThan = Math . round (
17+ ( typeof dateGreaterThan === "string" && / ^ \d + $ / . test ( dateGreaterThan )
18+ ? Number ( dateGreaterThan )
19+ : new Date ( dateGreaterThan ) . getTime ( ) ) / 1000
20+ ) ;
21+
1322const ipAddress = "10.0.0.0" ;
1423const privateKey = Buffer . from ( `
1524-----BEGIN RSA PRIVATE KEY-----
Original file line number Diff line number Diff line change @@ -363,8 +363,13 @@ class CloudfrontSignBuilder {
363363 if ( ! date ) {
364364 return undefined ;
365365 }
366- const parsedDate = Date . parse ( date ) ;
367- return isNaN ( parsedDate ) ? undefined : this . epochTime ( new Date ( parsedDate ) ) ;
366+ let parsedDate : Date ;
367+ if ( / ^ \d + $ / . test ( date ) ) {
368+ parsedDate = new Date ( Number ( date ) ) ;
369+ } else {
370+ parsedDate = new Date ( date ) ;
371+ }
372+ return isNaN ( parsedDate . getTime ( ) ) ? undefined : this . epochTime ( parsedDate ) ;
368373 }
369374
370375 private parseDateWindow ( expiration : string , start ?: string ) : PolicyDates {
You can’t perform that action at this time.
0 commit comments