kopia lustrzana https://gitlab.com/rysiekpl/libresilient
loading external MIME sniffing library moved to executeConfig() (ref. #48)
rodzic
4bf42c1c93
commit
d40cf65714
|
@ -381,6 +381,26 @@ let executeConfig = (pluginsConfig) => {
|
|||
|
||||
}
|
||||
|
||||
// finally -- do we want to use MIME type guessing based on content?
|
||||
// dealing with this at the very end so that we know we can safely set detectMimeFromBuffer
|
||||
// and not need to re-set it back in case anything fails
|
||||
if (self.LibResilientConfig.useMimeSniffingLibrary === true) {
|
||||
// we do not want to hit a NetworkError and end up using the default config
|
||||
// much better to end up not using the fancy MIME type detection in such a case
|
||||
try {
|
||||
// we do! load the external lib
|
||||
self.importScripts(`./lib/file-type.js`)
|
||||
} catch (e) {
|
||||
self.log('service-worker', `error when fetching external MIME sniffing library: ${e.message}`)
|
||||
}
|
||||
if (typeof fileType !== 'undefined' && "fileTypeFromBuffer" in fileType) {
|
||||
detectMimeFromBuffer = fileType.fileTypeFromBuffer
|
||||
self.log('service-worker', 'loaded external MIME sniffing library')
|
||||
} else {
|
||||
self.log('service-worker', 'failed to load external MIME sniffing library!')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -447,24 +467,6 @@ let initServiceWorker = async () => {
|
|||
self.log('service-worker', 'config loading failed, using defaults; error:', e)
|
||||
}
|
||||
|
||||
// first let's deal with the easy part -- do we want to use MIME type guessing based on content?
|
||||
if (self.LibResilientConfig.useMimeSniffingLibrary === true) {
|
||||
// we do not want to hit a NetworkError and end up using the default config
|
||||
// much better to end up not using the fancy MIME type detection in such a case
|
||||
try {
|
||||
// we do! load the external lib
|
||||
self.importScripts(`./lib/file-type.js`)
|
||||
} catch (e) {
|
||||
self.log('service-worker', `error when fetching external MIME sniffing library: ${e.message}`)
|
||||
}
|
||||
if (typeof fileType !== 'undefined' && "fileTypeFromBuffer" in fileType) {
|
||||
detectMimeFromBuffer = fileType.fileTypeFromBuffer
|
||||
self.log('service-worker', 'loaded external MIME sniffing library')
|
||||
} else {
|
||||
self.log('service-worker', 'failed to load external MIME sniffing library!')
|
||||
}
|
||||
}
|
||||
|
||||
// create the LibResilientPluginConstructors map
|
||||
// the global... hack is here so that we can run tests; not the most elegant
|
||||
// TODO: find a better way
|
||||
|
|
Ładowanie…
Reference in New Issue