DEV: Remvoe IMAGES_EXTENSIONS_REGEX const in lib/uploads (#18497)

This IMAGES_EXTENSIONS_REGEX const just creates redundancy
when we already have the `isImage` function -- the two can
easily get out of sync. Replace all usages of the former
with the latter.
This commit is contained in:
Martin Brennan
2022-10-07 09:24:08 +10:00
committed by GitHub
parent 0059be6856
commit cb26d52d33

View File

@ -135,9 +135,6 @@ export function validateUploadedFile(file, opts) {
return true; return true;
} }
export const IMAGES_EXTENSIONS_REGEX =
/(png|jpe?g|gif|svg|ico|heic|heif|webp)/i;
function extensionsToArray(exts) { function extensionsToArray(exts) {
return exts return exts
.toLowerCase() .toLowerCase()
@ -155,12 +152,10 @@ function staffExtensions(siteSettings) {
} }
function imagesExtensions(staff, siteSettings) { function imagesExtensions(staff, siteSettings) {
let exts = extensions(siteSettings).filter((ext) => let exts = extensions(siteSettings).filter((ext) => isImage(`.${ext}`));
IMAGES_EXTENSIONS_REGEX.test(ext)
);
if (staff) { if (staff) {
const staffExts = staffExtensions(siteSettings).filter((ext) => const staffExts = staffExtensions(siteSettings).filter((ext) =>
IMAGES_EXTENSIONS_REGEX.test(ext) isImage(`.${ext}`)
); );
exts = exts.concat(staffExts); exts = exts.concat(staffExts);
} }
@ -234,7 +229,7 @@ export function authorizesOneOrMoreImageExtensions(staff, siteSettings) {
} }
export function isImage(path) { export function isImage(path) {
return /\.(png|webp|jpe?g|gif|svg|ico)$/i.test(path); return /\.(png|webp|jpe?g|gif|svg|ico|heic|heif)$/i.test(path);
} }
export function isVideo(path) { export function isVideo(path) {
@ -252,9 +247,7 @@ function uploadTypeFromFileName(fileName) {
export function allowsImages(staff, siteSettings) { export function allowsImages(staff, siteSettings) {
return ( return (
authorizesAllExtensions(staff, siteSettings) || authorizesAllExtensions(staff, siteSettings) ||
IMAGES_EXTENSIONS_REGEX.test( authorizedExtensions(staff, siteSettings).some((ext) => isImage(`.${ext}`))
authorizedExtensions(staff, siteSettings).join()
)
); );
} }