@@ -28,10 +28,10 @@ class ExtAPI extends API
28
28
} ;
29
29
}
30
30
31
- get downloaderOpts ( ) {
31
+ downloaderOpts ( ) {
32
32
const softwareString = this . softwareString ;
33
33
34
- const signer = new Signer ( softwareString ) ;
34
+ const signer = new Signer ( softwareString , { cacheSig : true } ) ;
35
35
36
36
return { softwareString, signer} ;
37
37
}
@@ -50,7 +50,7 @@ class ExtAPI extends API
50
50
const format = params . _query . get ( "format" ) || "wacz" ;
51
51
let filename = params . _query . get ( "filename" ) ;
52
52
53
- const dl = new Downloader ( { ...this . downloaderOpts , coll, format, filename, pageList} ) ;
53
+ const dl = new Downloader ( { ...this . downloaderOpts ( ) , coll, format, filename, pageList} ) ;
54
54
return dl . download ( ) ;
55
55
}
56
56
@@ -96,9 +96,11 @@ class ExtAPI extends API
96
96
97
97
const client = await self . clients . get ( event . clientId ) ;
98
98
99
- const opts = { ... this . downloaderOpts , customSplits : body . customSplits } ;
99
+ const p = runIPFSAdd ( collId , coll , client , this . downloaderOpts ( ) , this . collections , body ) ;
100
100
101
- new IPFSAdd ( collId , coll , client , opts , this . collections ) . run ( body ) ;
101
+ if ( event . waitUntil ) {
102
+ event . waitUntil ( p ) ;
103
+ }
102
104
103
105
return { collId} ;
104
106
}
@@ -150,7 +152,7 @@ class ExtAPI extends API
150
152
}
151
153
152
154
async getPublicKey ( ) {
153
- const signer = new Signer ( ) ;
155
+ const { signer } = this . downloaderOpts ( ) ;
154
156
const keys = await signer . loadKeys ( ) ;
155
157
if ( ! keys || ! keys . public ) {
156
158
return { } ;
@@ -161,44 +163,27 @@ class ExtAPI extends API
161
163
}
162
164
163
165
// ===========================================================================
164
- class IPFSAdd
165
- {
166
- constructor ( collId , coll , client , opts , collections ) {
167
- this . collId = collId ;
168
- this . coll = coll ;
169
- this . client = client ;
170
- this . opts = opts ;
171
- this . collections = collections ;
172
-
173
- this . size = 0 ;
174
- }
166
+ async function runIPFSAdd ( collId , coll , client , opts , collections , replayOpts ) {
167
+ let size = 0 ;
175
168
176
- async run ( replayOpts ) {
177
- const { url, cid} = await ipfsAdd ( this . coll , this . opts , replayOpts , ( size ) => this . progress ( size ) ) ;
178
- const result = { cid, ipfsURL : url } ;
179
-
180
- if ( this . client ) {
181
- this . client . postMessage ( {
182
- type : "ipfsAdd" ,
183
- collId : this . collId ,
184
- size : this . size ,
185
- result
169
+ const sendMessage = ( type , result = null ) => {
170
+ if ( client ) {
171
+ client . postMessage ( {
172
+ type, collId, size, result
186
173
} ) ;
187
174
}
175
+ } ;
188
176
189
- await this . collections . updateMetadata ( this . coll . name , this . coll . config . metadata ) ;
190
- }
177
+ const { url, cid} = await ipfsAdd ( coll , opts , replayOpts , ( incSize ) => {
178
+ size += incSize ;
179
+ sendMessage ( "ipfsProgress" ) ;
180
+ } ) ;
191
181
192
- progress ( incSize ) {
193
- this . size += incSize ;
194
- if ( this . client ) {
195
- this . client . postMessage ( {
196
- type : "ipfsProgress" ,
197
- collId : this . collId ,
198
- size : this . size ,
199
- } ) ;
200
- }
201
- }
182
+ const result = { cid, ipfsURL : url } ;
183
+
184
+ sendMessage ( "ipfsAdd" , result ) ;
185
+
186
+ await collections . updateMetadata ( coll . name , coll . config . metadata ) ;
202
187
}
203
188
204
189
export { ExtAPI } ;
0 commit comments