diff options
author | bobzel <zzzman@gmail.com> | 2024-05-03 10:55:33 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-03 10:55:33 -0400 |
commit | f927a585c75a20629379bcb34d1483c0ca9d8db9 (patch) | |
tree | f070e9e64ecaf251e6708b8ce4d722f121a6d039 /src/client/util/request-image-size.ts | |
parent | 723c8b33ade753764d1d02b130c189fb65e20425 (diff) | |
parent | 9b424c94d7a89950e9cf3f72e684bd15a61e87ae (diff) |
merged with new version of master
Diffstat (limited to 'src/client/util/request-image-size.ts')
-rw-r--r-- | src/client/util/request-image-size.ts | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/client/util/request-image-size.ts b/src/client/util/request-image-size.ts index 57e8516ac..0f98a2710 100644 --- a/src/client/util/request-image-size.ts +++ b/src/client/util/request-image-size.ts @@ -14,19 +14,17 @@ const imageSize = require('image-size'); const HttpError = require('standard-http-error'); module.exports = function requestImageSize(options: any) { - let opts = { + let opts: any = { encoding: null, }; if (options && typeof options === 'object') { opts = Object.assign(options, opts); } else if (options && typeof options === 'string') { - opts = Object.assign( - { - uri: options, - }, - opts - ); + opts = { + uri: options, + ...opts, + }; } else { return Promise.reject(new Error('You should provide an URI string or a "request" options object.')); } @@ -38,7 +36,8 @@ module.exports = function requestImageSize(options: any) { req.on('response', (res: any) => { if (res.statusCode >= 400) { - return reject(new HttpError(res.statusCode, res.statusMessage)); + reject(new HttpError(res.statusCode, res.statusMessage)); + return; } let buffer = Buffer.from([]); @@ -51,20 +50,23 @@ module.exports = function requestImageSize(options: any) { size = imageSize(buffer); if (size) { resolve(size); - return req.abort(); + req.abort(); } - } catch (err) {} + } catch (err) { + /* empty */ + } }); res.on('error', reject); res.on('end', () => { if (!size) { - return reject(new Error('Image has no size')); + reject(new Error('Image has no size')); + return; } size.downloaded = buffer.length; - return resolve(size); + resolve(size); }); }); |