File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed
packages/core/src/storage/common Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { getTokenFileUrl } from './index' ;
2
+
3
+ const ZONEFILE_CONTENT = {
4
+ $origin : 'sigle.btc.' ,
5
+ $ttl : 3600 ,
6
+ uri : [
7
+ {
8
+ name : '@' ,
9
+ target : '' ,
10
+ priority : 10 ,
11
+ weight : 1 ,
12
+ } ,
13
+ {
14
+ name : '_http._tcp' ,
15
+ target : 'https://gaia.blockstack.org/hub/15FF6jnJ1vV4fvo8LFPY1AK6dSbxMP6hkE/profile.json' ,
16
+ priority : 10 ,
17
+ weight : 1 ,
18
+ } ,
19
+ ] ,
20
+ } ;
21
+
22
+ describe ( 'getTokenFileUrl tests' , ( ) => {
23
+ it ( 'should get token file url' , async ( ) => {
24
+ expect ( getTokenFileUrl ( ZONEFILE_CONTENT ) ) . toBe ( ZONEFILE_CONTENT . uri [ 1 ] . target ) ;
25
+ } ) ;
26
+ } ) ;
Original file line number Diff line number Diff line change @@ -38,12 +38,21 @@ export function getTokenFileUrl(zoneFileJson: any): string | null {
38
38
if ( zoneFileJson . uri . length < 1 ) {
39
39
return null ;
40
40
}
41
- const firstUriRecord = zoneFileJson . uri [ 0 ] ;
42
41
43
- if ( ! firstUriRecord . hasOwnProperty ( 'target' ) ) {
42
+ const validRecords = zoneFileJson . uri . filter (
43
+ ( record : any ) => record . hasOwnProperty ( 'target' ) && record . name === '_http._tcp'
44
+ ) ;
45
+
46
+ if ( validRecords . length < 1 ) {
47
+ return null ;
48
+ }
49
+
50
+ const firstValidRecord = validRecords [ 0 ] ;
51
+
52
+ if ( ! firstValidRecord . hasOwnProperty ( 'target' ) ) {
44
53
return null ;
45
54
}
46
- let tokenFileUrl = firstUriRecord . target ;
55
+ let tokenFileUrl = firstValidRecord . target ;
47
56
48
57
if ( tokenFileUrl . startsWith ( 'https' ) ) {
49
58
// pass
You can’t perform that action at this time.
0 commit comments