"use strict";function filterMediaCache(e){exports.mediaCache=exports.mediaCache.filter(t=>t.id!==e)}async function updateMediaCache(e){const t=[];await async function e(i){const r=await fs_1.promises.readdir(i,{withFileTypes:!0});for(const a of r){const r=(0,path_1.join)(i,a.name);if(a.isDirectory())await e(r);else if(/\.(jpg|jpeg|png|gif|webp)$/i.test(a.name))try{const{mtime:e}=await fs_1.promises.stat(r);let i=r.substring(exports.mediaDirectory.length).replace(/\\/g,"/");i.startsWith("/")||(i="/"+i);const o=(0,sharp_1.default)(r),s=await o.metadata();t.push({id:"/uploads"+i.replace(/\//g,"_"),name:a.name,path:"/uploads"+i,width:s.width,height:s.height,dateModified:e})}catch(e){console_1.logger.error("MEDIA",`Error accessing file: ${r}`,e)}}}(e);exports.mediaCache=t;exports.cacheInitialized=!0}async function initMediaWatcher(){await updateMediaCache(exports.mediaDirectory);(0,fs_1.watch)(exports.mediaDirectory,{recursive:!0},async()=>{await updateMediaCache(exports.mediaDirectory)})}var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.publicDirectory=exports.mediaDirectory=exports.cacheInitialized=exports.mediaCache=exports.operatorMap=void 0;exports.filterMediaCache=filterMediaCache;exports.initMediaWatcher=initMediaWatcher;const fs_1=require("fs"),path_1=require("path"),sharp_1=__importDefault(require("sharp")),console_1=require("@b/utils/console");exports.operatorMap={equal:(e,t,i)=>e[t]===i,notEqual:(e,t,i)=>e[t]!==i,greaterThan:(e,t,i)=>e[t]>i,greaterThanOrEqual:(e,t,i)=>e[t]>=i,lessThan:(e,t,i)=>e[t]<i,lessThanOrEqual:(e,t,i)=>e[t]<=i,between:(e,t,i)=>e[t]>=i[0]&&e[t]<=i[1],notBetween:(e,t,i)=>e[t]<i[0]||e[t]>i[1],like:(e,t,i)=>new RegExp(i,"i").test(e[t]),notLike:(e,t,i)=>!new RegExp(i,"i").test(e[t]),startsWith:(e,t,i)=>{var r;return null===(r=e[t])||void 0===r?void 0:r.startsWith(i)},endsWith:(e,t,i)=>{var r;return null===(r=e[t])||void 0===r?void 0:r.endsWith(i)},substring:(e,t,i)=>{var r;return null===(r=e[t])||void 0===r?void 0:r.includes(i)},regexp:(e,t,i)=>new RegExp(i).test(e[t]),notRegexp:(e,t,i)=>!new RegExp(i).test(e[t])};exports.mediaCache=[];exports.cacheInitialized=!1;const isProduction="production"===process.env.NODE_ENV;exports.mediaDirectory=isProduction?(0,path_1.join)(process.cwd(),"frontend","public","uploads"):(0,path_1.join)(process.cwd(),"..","frontend","public","uploads");exports.publicDirectory=isProduction?(0,path_1.join)(process.cwd(),"frontend","public"):(0,path_1.join)(process.cwd(),"..","frontend","public");