aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/request-image-size.ts
diff options
context:
space:
mode:
authorJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
committerJoanne <zehan_ding@brown.edu>2025-05-12 20:58:01 -0400
commitcd93c88b8fee83a99342eac4dc60f7b4373fa843 (patch)
treeb00d1f46c802752c90e54bb21be785a05e05195e /src/client/util/request-image-size.ts
parent4997c3de20a381eac30224a7a550afa66174f07d (diff)
parent3a733aa0fd24517e83649824dec0fc8bcc0bde43 (diff)
added tutorial tool, still need to integrate with metadatatool
Diffstat (limited to 'src/client/util/request-image-size.ts')
-rw-r--r--src/client/util/request-image-size.ts38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/client/util/request-image-size.ts b/src/client/util/request-image-size.ts
index 32ab23618..798390c7d 100644
--- a/src/client/util/request-image-size.ts
+++ b/src/client/util/request-image-size.ts
@@ -33,27 +33,25 @@ export function requestImageSize(url: string): Promise<ISizeCalculationResult> {
res.on('data', chunk => {
buffer = Buffer.concat([buffer, chunk]);
- });
-
- res.on('error', reject);
-
- res.on('end', () => {
- try {
- size = imageSize(buffer);
- if (size) {
- resolve(size);
- req.abort();
+ })
+ .on('error', reject)
+ .on('end', () => {
+ try {
+ size = imageSize(buffer);
+ if (size) {
+ resolve(size);
+ req.abort();
+ }
+ } catch (err) {
+ /* empty */
+ console.log('Error: ', err);
+ }
+ if (!size) {
+ reject(new Error('Image has no size'));
+ return;
}
- } catch (err) {
- /* empty */
- console.log('Error: ', err);
- }
- if (!size) {
- reject(new Error('Image has no size'));
- return;
- }
- resolve(size);
- });
+ resolve(size);
+ });
});
req.on('error', reject);