Skip to content

Commit

Permalink
Update server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 authored Oct 9, 2019
1 parent 47261d1 commit 12518fc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class StoreServer {
allowCors = false,
exposeToInternet = false,
authenticationUsername = '',
authenticationPassword = ''
authenticationPassword = '',
manifestTimeout
}) {
storageLocation = storageLocation || DEFAULT_STORAGE_LOCATION

Expand All @@ -48,6 +49,7 @@ class StoreServer {

this.authenticationUsername = authenticationUsername
this.authenticationPassword = authenticationPassword
this.manifestTimeout = manifestTimeout

this.fastify = createFastify({ logger: verbose })

Expand Down Expand Up @@ -215,14 +217,11 @@ class StoreServer {
}
try {

// https://javascript.info/promise-api#promise-race
// give Paul's Dat API a moment to resolve and win the race
// otherwsie, just return the resolved manifest you've already got
manifest = Promise.race([
pda.readManifest(archive),
new Promise((resolve, reject) => setTimeout(() => resolve(manifest), 500))
await pda.readManifest(archive),
delay(manifestTimeout).then(() => manifest)
])

} catch (e) {
// It must not have a manifest, that's okay
}
Expand Down

0 comments on commit 12518fc

Please sign in to comment.