@lighthouse/common
Advanced tools
Comparing version 4.24.3-canary.113.1429 to 4.24.3-canary.113.1432
@@ -19,2 +19,4 @@ "use strict"; | ||
var _constants = require("../../constants"); | ||
// NOTE use the native fetch if it's available in the browser, because the | ||
@@ -45,2 +47,5 @@ // ponyfill (which actually uses the github polyfill) does not support all the | ||
}; | ||
const { | ||
isHeader = false | ||
} = options; | ||
return fetch(url, fetchOptions).then(response => { | ||
@@ -79,3 +84,9 @@ const contentHeader = response.headers.get('content-length'); | ||
}).catch(error => { | ||
// NOTE: catch all error to log and then rethrow | ||
if (isHeader) { | ||
// NOTE: Replace failed headers with LH logo | ||
console.error('FetchImageHeaderError', error); | ||
return fetchImage(_constants.LIGHTHOUSE_LOGO_URL, defaultOptions); | ||
} // NOTE: catch all error to log and then rethrow | ||
console.error(error); | ||
@@ -82,0 +93,0 @@ throw error; |
@@ -25,3 +25,5 @@ "use strict"; | ||
return (0, _helpers.fetchImage)(logoUrl).then(image => _page => ({ | ||
return (0, _helpers.fetchImage)(logoUrl, { | ||
isHeader: true | ||
}).then(image => _page => ({ | ||
columns: [{ | ||
@@ -28,0 +30,0 @@ fit: [80, 30], |
@@ -10,20 +10,2 @@ "use strict"; | ||
const generateColumnsWithImage = ({ | ||
datetime, | ||
image | ||
}) => ({ | ||
columns: [{ | ||
fit: [130, 30], | ||
image, | ||
margin: [60, 60, 60, 0] | ||
}, { | ||
alignment: 'right', | ||
color: '#999', | ||
font: 'Gotham', | ||
fontSize: 11, | ||
text: datetime, | ||
margin: [60, 70, 60, 0] | ||
}] | ||
}); | ||
function defaultHeader({ | ||
@@ -40,12 +22,16 @@ logoUrl, | ||
}); | ||
return (0, _helpers.fetchImage)(logoUrl).then(image => generateColumnsWithImage({ | ||
datetime, | ||
image | ||
})).catch(error => { | ||
console.error(`GenerateDefinitionError: Invalid Image URL: ${logoUrl}`, error); | ||
return (0, _helpers.fetchImage)().then(image => generateColumnsWithImage({ | ||
datetime, | ||
image | ||
})); | ||
}); | ||
return (0, _helpers.fetchImage)(logoUrl).then(image => ({ | ||
columns: [{ | ||
fit: [130, 30], | ||
image, | ||
margin: [60, 60, 60, 0] | ||
}, { | ||
alignment: 'right', | ||
color: '#999', | ||
font: 'Gotham', | ||
fontSize: 11, | ||
text: datetime, | ||
margin: [60, 70, 60, 0] | ||
}] | ||
})); | ||
} |
@@ -10,3 +10,4 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import fetchPonyfill from 'fetch-ponyfill'; | ||
import Promise from 'bluebird'; // NOTE use the native fetch if it's available in the browser, because the | ||
import Promise from 'bluebird'; | ||
import { LIGHTHOUSE_LOGO_URL } from '../../constants'; // NOTE use the native fetch if it's available in the browser, because the | ||
// ponyfill (which actually uses the github polyfill) does not support all the | ||
@@ -37,2 +38,4 @@ // same options as native fetch | ||
var _options$isHeader = options.isHeader, | ||
isHeader = _options$isHeader === void 0 ? false : _options$isHeader; | ||
return fetch(url, fetchOptions).then(function (response) { | ||
@@ -72,3 +75,9 @@ var contentHeader = response.headers.get('content-length'); | ||
}).catch(function (error) { | ||
// NOTE: catch all error to log and then rethrow | ||
if (isHeader) { | ||
// NOTE: Replace failed headers with LH logo | ||
console.error('FetchImageHeaderError', error); | ||
return fetchImage(LIGHTHOUSE_LOGO_URL, defaultOptions); | ||
} // NOTE: catch all error to log and then rethrow | ||
console.error(error); | ||
@@ -75,0 +84,0 @@ throw error; |
@@ -16,3 +16,5 @@ import { fetchImage, getTimezoneDatetime } from '../../../helpers'; | ||
return fetchImage(logoUrl).then(function (image) { | ||
return fetchImage(logoUrl, { | ||
isHeader: true | ||
}).then(function (image) { | ||
return function (_page) { | ||
@@ -19,0 +21,0 @@ return { |
import { fetchImage, getTimezoneDatetime } from '../../../helpers'; | ||
var generateColumnsWithImage = function generateColumnsWithImage(_ref) { | ||
var datetime = _ref.datetime, | ||
image = _ref.image; | ||
return { | ||
columns: [{ | ||
fit: [130, 30], | ||
image: image, | ||
margin: [60, 60, 60, 0] | ||
}, { | ||
alignment: 'right', | ||
color: '#999', | ||
font: 'Gotham', | ||
fontSize: 11, | ||
text: datetime, | ||
margin: [60, 70, 60, 0] | ||
}] | ||
}; | ||
}; | ||
export function defaultHeader(_ref2) { | ||
var logoUrl = _ref2.logoUrl, | ||
timestamp = _ref2.timestamp, | ||
timezone = _ref2.timezone; | ||
export function defaultHeader(_ref) { | ||
var logoUrl = _ref.logoUrl, | ||
timestamp = _ref.timestamp, | ||
timezone = _ref.timezone; | ||
var datetime = getTimezoneDatetime({ | ||
@@ -33,16 +13,18 @@ format: 'ddd, Do MMM YYYY', | ||
return fetchImage(logoUrl).then(function (image) { | ||
return generateColumnsWithImage({ | ||
datetime: datetime, | ||
image: image | ||
}); | ||
}).catch(function (error) { | ||
console.error("GenerateDefinitionError: Invalid Image URL: ".concat(logoUrl), error); | ||
return fetchImage().then(function (image) { | ||
return generateColumnsWithImage({ | ||
datetime: datetime, | ||
image: image | ||
}); | ||
}); | ||
return { | ||
columns: [{ | ||
fit: [130, 30], | ||
image: image, | ||
margin: [60, 60, 60, 0] | ||
}, { | ||
alignment: 'right', | ||
color: '#999', | ||
font: 'Gotham', | ||
fontSize: 11, | ||
text: datetime, | ||
margin: [60, 70, 60, 0] | ||
}] | ||
}; | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@lighthouse/common", | ||
"version": "4.24.3-canary.113.1429", | ||
"version": "4.24.3-canary.113.1432", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1238536
11919