express-sharp
Version:
Real-time image processing for your express application
39 lines • 1.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpAdapter = void 0;
const got_1 = __importDefault(require("got"));
const logger_1 = require("../logger");
class HttpAdapter {
constructor(gotOptions) {
this.log = logger_1.getLogger('adapter:http');
this.client = got_1.default.extend({
...gotOptions,
});
this.log(`Using prefixUrl: ${this.getPrefixUrl()}`);
}
getPrefixUrl() {
return this.client.defaults.options.prefixUrl;
}
async fetch(url) {
var _a;
this.log(`Fetching: ${this.getPrefixUrl()}${url}`);
try {
const response = await this.client.get(url, {
responseType: 'buffer',
});
return response.body;
}
catch (error) {
// eslint-disable-next-line no-magic-numbers
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.statusCode) === 404) {
return undefined;
}
throw error;
}
}
}
exports.HttpAdapter = HttpAdapter;
//# sourceMappingURL=http.adapter.js.map