aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/request-image-size.js
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-01-03 10:58:56 -0500
committerbobzel <zzzman@gmail.com>2023-01-03 10:58:56 -0500
commit183789b1d5e9ee9d8906a29eb3fde3f651a8c29c (patch)
treec7461e9965c8ca21c10be3948efcaa4503da8d37 /src/client/util/request-image-size.js
parent9211251c8a632ef84198253a0d3086df11af9ead (diff)
fixed occasional errors loading images
Diffstat (limited to 'src/client/util/request-image-size.js')
-rw-r--r--src/client/util/request-image-size.js77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/client/util/request-image-size.js b/src/client/util/request-image-size.js
deleted file mode 100644
index 502e0fbac..000000000
--- a/src/client/util/request-image-size.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * request-image-size: Detect image dimensions via request.
- * Licensed under the MIT license.
- *
- * https://github.com/FdezRomero/request-image-size
- * © 2017 Rodrigo Fernández Romero
- *
- * Based on the work of Johannes J. Schmidt
- * https://github.com/jo/http-image-size
- */
-
-const request = require('request');
-const imageSize = require('image-size');
-const HttpError = require('standard-http-error');
-
-module.exports = function requestImageSize(options) {
- let opts = {
- encoding: null,
- };
-
- if (options && typeof options === 'object') {
- opts = Object.assign(options, opts);
- } else if (options && typeof options === 'string') {
- opts = Object.assign(
- {
- uri: options,
- },
- opts
- );
- } else {
- return Promise.reject(new Error('You should provide an URI string or a "request" options object.'));
- }
-
- opts.encoding = null;
-
- return new Promise((resolve, reject) => {
- const req = request(opts);
-
- req.on('response', res => {
- if (res.statusCode >= 400) {
- return reject(new HttpError(res.statusCode, res.statusMessage));
- }
-
- let buffer = Buffer.from([]);
- let size;
-
- res.on('data', chunk => {
- buffer = Buffer.concat([buffer, chunk]);
-
- try {
- size = imageSize(buffer);
- } catch (err) {
- reject(err);
- return req.abort();
- }
-
- if (size) {
- resolve(size);
- return req.abort();
- }
- });
-
- res.on('error', reject);
-
- res.on('end', () => {
- if (!size) {
- return reject(new Error('Image has no size'));
- }
-
- size.downloaded = buffer.length;
- return resolve(size);
- });
- });
-
- req.on('error', reject);
- });
-};