From: Tim Düsterhus Date: Wed, 2 Aug 2023 13:00:30 +0000 (+0200) Subject: Stop abusing enums in Image/ExifUtil.ts X-Git-Tag: 6.0.0_Alpha_8~16^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ec58d205bed7fe5d0c290ed3028d2515b2d5153c;p=GitHub%2FWoltLab%2FWCF.git Stop abusing enums in Image/ExifUtil.ts --- diff --git a/ts/WoltLabSuite/Core/Image/ExifUtil.ts b/ts/WoltLabSuite/Core/Image/ExifUtil.ts index 36db10e675..def032be9c 100644 --- a/ts/WoltLabSuite/Core/Image/ExifUtil.ts +++ b/ts/WoltLabSuite/Core/Image/ExifUtil.ts @@ -7,27 +7,26 @@ * @module WoltLabSuite/Core/Image/ExifUtil * @woltlabExcludeBundle tiny */ -/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */ - -const enum Tag { - SOI = 0xd8, // Start of image - APP0 = 0xe0, // JFIF tag - APP1 = 0xe1, // EXIF / XMP - APP2 = 0xe2, // General purpose tag - APP3 = 0xe3, // General purpose tag - APP4 = 0xe4, // General purpose tag - APP5 = 0xe5, // General purpose tag - APP6 = 0xe6, // General purpose tag - APP7 = 0xe7, // General purpose tag - APP8 = 0xe8, // General purpose tag - APP9 = 0xe9, // General purpose tag - APP10 = 0xea, // General purpose tag - APP11 = 0xeb, // General purpose tag - APP12 = 0xec, // General purpose tag - APP13 = 0xed, // General purpose tag - APP14 = 0xee, // Often used to store copyright information - COM = 0xfe, // Comments -} + +const Tag = { + SOI: 0xd8, // Start of image + APP0: 0xe0, // JFIF tag + APP1: 0xe1, // EXIF / XMP + APP2: 0xe2, // General purpose tag + APP3: 0xe3, // General purpose tag + APP4: 0xe4, // General purpose tag + APP5: 0xe5, // General purpose tag + APP6: 0xe6, // General purpose tag + APP7: 0xe7, // General purpose tag + APP8: 0xe8, // General purpose tag + APP9: 0xe9, // General purpose tag + APP10: 0xea, // General purpose tag + APP11: 0xeb, // General purpose tag + APP12: 0xec, // General purpose tag + APP13: 0xed, // General purpose tag + APP14: 0xee, // Often used to store copyright information + COM: 0xfe, // Comments +}; // Known sequence signatures const _signatureEXIF = "Exif"; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/ExifUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/ExifUtil.js index 260ea335e0..dd4e3193d6 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/ExifUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/ExifUtil.js @@ -7,11 +7,29 @@ * @module WoltLabSuite/Core/Image/ExifUtil * @woltlabExcludeBundle tiny */ -/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */ define(["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setExifData = exports.removeExifData = exports.getExifBytesFromJpeg = void 0; + const Tag = { + SOI: 0xd8, + APP0: 0xe0, + APP1: 0xe1, + APP2: 0xe2, + APP3: 0xe3, + APP4: 0xe4, + APP5: 0xe5, + APP6: 0xe6, + APP7: 0xe7, + APP8: 0xe8, + APP9: 0xe9, + APP10: 0xea, + APP11: 0xeb, + APP12: 0xec, + APP13: 0xed, + APP14: 0xee, + COM: 0xfe, // Comments + }; // Known sequence signatures const _signatureEXIF = "Exif"; const _signatureXMP = "http://ns.adobe.com/xap/1.0/"; @@ -51,7 +69,7 @@ define(["require", "exports"], function (require, exports) { } const bytes = await blobToUint8(blob); let exif = new Uint8Array(0); - if (bytes[0] !== 0xff && bytes[1] !== 216 /* Tag.SOI */) { + if (bytes[0] !== 0xff && bytes[1] !== Tag.SOI) { throw new Error("Not a JPEG"); } for (let i = 2; i < bytes.length;) { @@ -60,7 +78,7 @@ define(["require", "exports"], function (require, exports) { break; const length = 2 + ((bytes[i + 2] << 8) | bytes[i + 3]); // Check if the next byte indicates an EXIF sequence - if (bytes[i + 1] === 225 /* Tag.APP1 */) { + if (bytes[i + 1] === Tag.APP1) { let signature = ""; for (let j = i + 4; bytes[j] !== 0 && j < bytes.length; j++) { signature += String.fromCharCode(bytes[j]); @@ -85,7 +103,7 @@ define(["require", "exports"], function (require, exports) { throw new TypeError("The argument must be a Blob or a File"); } const bytes = await blobToUint8(blob); - if (bytes[0] !== 0xff && bytes[1] !== 216 /* Tag.SOI */) { + if (bytes[0] !== 0xff && bytes[1] !== Tag.SOI) { throw new Error("Not a JPEG"); } let result = bytes; @@ -95,7 +113,7 @@ define(["require", "exports"], function (require, exports) { break; const length = 2 + ((result[i + 2] << 8) | result[i + 3]); // Check if the next byte indicates an EXIF sequence - if (result[i + 1] === 225 /* Tag.APP1 */) { + if (result[i + 1] === Tag.APP1) { let signature = ""; for (let j = i + 4; result[j] !== 0 && j < result.length; j++) { signature += String.fromCharCode(result[j]); @@ -125,7 +143,7 @@ define(["require", "exports"], function (require, exports) { const bytes = await blobToUint8(blob); let offset = 2; // check if the second tag is the JFIF tag - if (bytes[2] === 0xff && bytes[3] === 224 /* Tag.APP0 */) { + if (bytes[2] === 0xff && bytes[3] === Tag.APP0) { offset += 2 + ((bytes[4] << 8) | bytes[5]); } const start = bytes.slice(0, offset);