@@ -40,9 +40,6 @@ export namespace Resources {
4040 scriptId : CRM . NodeId < CRM . ScriptNode > ;
4141 } , name : string ) {
4242 switch ( message . type ) {
43- case 'register' :
44- registerResource ( name , message . url , message . scriptId ) ;
45- break ;
4643 case 'remove' :
4744 removeResource ( name , message . scriptId ) ;
4845 break ;
@@ -56,50 +53,6 @@ export namespace Resources {
5653 }
5754 }
5855
59- function getUrlData ( scriptId : CRM . NodeId < CRM . ScriptNode > , url : string , callback : ( dataURI : string ,
60- dataString : string ) => void ) {
61- //First check if the data has already been fetched
62- if ( modules . storages . urlDataPairs . get ( url ) ) {
63- const dataPairs = modules . storages . urlDataPairs . get ( url ) ;
64- if ( dataPairs . refs . indexOf ( scriptId ) === - 1 ) {
65- dataPairs . refs . push ( scriptId ) ;
66- }
67- callback ( dataPairs . dataURI , dataPairs . dataString ) ;
68- } else {
69- modules . Util . convertFileToDataURI ( url , ( dataURI , dataString ) => {
70- //Write the data away to the url-data-pairs object
71- modules . storages . urlDataPairs . set ( url , {
72- dataURI : dataURI ,
73- dataString : dataString ,
74- refs : [ scriptId ]
75- } ) ;
76- callback ( dataURI , dataString ) ;
77- } ) ;
78- }
79- }
80- function getHashes ( url : string ) : {
81- algorithm : string ;
82- hash : string ;
83- } [ ] {
84- const hashes : {
85- algorithm : string ;
86- hash : string ;
87- } [ ] = [ ] ;
88- const hashString = url . split ( '#' ) [ 1 ] ;
89- if ( ! hashString ) {
90- return [ ] ;
91- }
92-
93- const hashStrings = hashString . split ( / [ , | ; ] / g) ;
94- hashStrings . forEach ( ( hash ) => {
95- const split = hash . split ( '=' ) ;
96- hashes . push ( {
97- algorithm : split [ 0 ] ,
98- hash : split [ 1 ]
99- } ) ;
100- } ) ;
101- return hashes ;
102- }
10356 function doAlgorithm ( name : string , data : any , lastMatchingHash : {
10457 algorithm : string ;
10558 hash : string ;
@@ -161,45 +114,6 @@ export namespace Resources {
161114 }
162115 return false ;
163116 }
164- function registerResource ( name : string , url : string , scriptId : CRM . NodeId < CRM . ScriptNode > ) {
165- const registerHashes = getHashes ( url ) ;
166- if ( window . navigator . onLine ) {
167- getUrlData ( scriptId , url , ( dataURI , dataString ) => {
168- const resources = modules . storages . resources ;
169- modules . Util . setMapDefault ( resources , scriptId , { } ) ;
170- resources . get ( scriptId ) [ name ] = {
171- name : name ,
172- sourceUrl : url ,
173- dataURI : dataURI ,
174- dataString : dataString ,
175- hashes : registerHashes ,
176- matchesHashes : matchesHashes ( registerHashes , dataString ) ,
177- crmUrl : `https://www.localhost.io/resource/${ scriptId } /${ name } `
178- } ;
179- browserAPI . storage . local . set ( {
180- resources : modules . Util . fromMap ( resources ) ,
181- urlDataPairs : modules . Util . fromMap ( modules . storages . urlDataPairs )
182- } ) ;
183- } ) ;
184- }
185-
186- const resourceKeys = modules . storages . resourceKeys ;
187- for ( const resourceKey of resourceKeys ) {
188- if ( resourceKey . name === name &&
189- resourceKey . scriptId === scriptId ) {
190- return ;
191- }
192- }
193- resourceKeys . push ( {
194- name : name ,
195- sourceUrl : url ,
196- hashes : registerHashes ,
197- scriptId : scriptId
198- } ) ;
199- browserAPI . storage . local . set ( {
200- resourceKeys : resourceKeys
201- } ) ;
202- }
203117 function removeResource ( name : string , scriptId : CRM . NodeId < CRM . ScriptNode > ) {
204118 for ( let i = 0 ; i < modules . storages . resourceKeys . length ; i ++ ) {
205119 if ( modules . storages . resourceKeys [ i ] . name === name &&
0 commit comments