Merge branch 'exif-fix' into 'develop'

Swap out exif-js for exifr

Closes #1519

See merge request soapbox-pub/soapbox!2701
environments/review-main-yi2y9f/deployments/3909
Alex Gleason 2023-09-17 01:54:12 +00:00
commit 9f15991ab5
3 zmienionych plików z 21 dodań i 20 usunięć

Wyświetl plik

@ -118,24 +118,25 @@ const loadImage = (inputFile: File) => new Promise<HTMLImageElement>((resolve, r
}); });
/** Get the exif orientation for the image. */ /** Get the exif orientation for the image. */
const getOrientation = (img: HTMLImageElement, type = 'image/png') => new Promise<number>(resolve => { async function getOrientation(img: HTMLImageElement, type = 'image/png'): Promise<number> {
if (!['image/jpeg', 'image/webp'].includes(type)) { if (!['image/jpeg', 'image/webp'].includes(type)) {
resolve(1); return 1;
return;
} }
import('exif-js').then(({ default: EXIF }) => { try {
// @ts-ignore: The TypeScript definition is wrong. const exifr = await import('exifr');
EXIF.getData(img, () => { const orientation = await exifr.orientation(img) ?? 1;
const orientation = EXIF.getTag(img, 'Orientation');
if (orientation !== 1) { if (orientation !== 1) {
dropOrientationIfNeeded(orientation).then(resolve).catch(() => resolve(orientation)); return await dropOrientationIfNeeded(orientation);
} else { } else {
resolve(orientation); return orientation;
} }
}); } catch (error) {
}).catch(() => {}); console.error('Failed to get orientation:', error);
}); return 1;
}
}
const processImage = ( const processImage = (
img: HTMLImageElement, img: HTMLImageElement,

Wyświetl plik

@ -105,7 +105,7 @@
"emoji-datasource": "14.0.0", "emoji-datasource": "14.0.0",
"emoji-mart": "^5.5.2", "emoji-mart": "^5.5.2",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"exif-js": "^2.3.0", "exifr": "^7.1.3",
"graphemesplit": "^2.4.4", "graphemesplit": "^2.4.4",
"http-link-header": "^1.0.2", "http-link-header": "^1.0.2",
"immer": "^9.0.19", "immer": "^9.0.19",

Wyświetl plik

@ -4778,10 +4778,10 @@ exenv@^1.2.2:
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d" resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50= integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50=
exif-js@^2.3.0: exifr@^7.1.3:
version "2.3.0" version "7.1.3"
resolved "https://registry.yarnpkg.com/exif-js/-/exif-js-2.3.0.tgz#9d10819bf571f873813e7640241255ab9ce1a814" resolved "https://registry.yarnpkg.com/exifr/-/exifr-7.1.3.tgz#f6218012c36dbb7d843222011b27f065fddbab6f"
integrity sha1-nRCBm/Vx+HOBPnZAJBJVq5zhqBQ= integrity sha512-g/aje2noHivrRSLbAUtBPWFbxKdKhgj/xr1vATDdUXPOFYJlQ62Ft0oy+72V6XLIpDJfHs6gXLbBLAolqOXYRw==
expand-tilde@^2.0.2: expand-tilde@^2.0.2:
version "2.0.2" version "2.0.2"