NeahNew/.next/server/chunks/6781.js
2025-05-06 23:01:34 +02:00

1 line
7.2 KiB
JavaScript

"use strict";exports.id=6781,exports.ids=[6781],exports.modules={36781:(e,t,r)=>{r.d(t,{$:()=>R,FD:()=>I,Ij:()=>w,Kb:()=>g,Po:()=>_,QN:()=>O,Rk:()=>p,VP:()=>m,ax:()=>L,dF:()=>h,ds:()=>M,gU:()=>A,mX:()=>y,nF:()=>J,nV:()=>T,nr:()=>u,pO:()=>D,pz:()=>S,qF:()=>$,ql:()=>k,to:()=>C,vA:()=>v,wp:()=>N});var n=r(70300),o=r.n(n),s=r(40383),c=r.n(s);let a=null,i=!1,l=0;function u(){if(a&&"ready"===a.status)return a;if(i){if(a)return a;console.warn("Redis connection in progress, creating temporary client")}if(!a){i=!0,l=0;let e={host:process.env.REDIS_HOST,port:process.env.REDIS_PORT?parseInt(process.env.REDIS_PORT):void 0,password:process.env.REDIS_PASSWORD,retryStrategy:e=>{if(l=e,e>5)return console.error(`Redis connection failed after ${e} attempts, giving up`),null;let t=Math.min(100*e,5e3);return console.log(`Redis reconnect attempt ${e}, retrying in ${t}ms`),t},maxRetriesPerRequest:5,enableOfflineQueue:!0,connectTimeout:1e4,disconnectTimeout:2e3,keepAlive:1e4,keyPrefix:""};console.log("Connecting to Redis using environment variables"),(a=new(o())(e)).on("error",e=>{console.error("Redis connection error:",e),l>5&&(console.error("Redis connection failed permanently, will create new client on next request"),a=null,i=!1)}),a.on("connect",()=>{console.log("Successfully connected to Redis"),i=!1,l=0}),a.on("reconnecting",()=>{console.log("Reconnecting to Redis..."),i=!0}),a.on("ready",()=>{console.log("Redis connection warmed up"),i=!1}),a.on("end",()=>{console.log("Redis connection ended")})}return a}let d=()=>process.env.REDIS_ENCRYPTION_KEY||"default-encryption-key-change-in-production",p={CREDENTIALS:(e,t)=>`email:credentials:${e}:${t}`,SESSION:e=>`email:session:${e}`,EMAIL_LIST:(e,t,r,n,o)=>`email:list:${e}:${t}:${r}:${n}:${o}`,EMAIL_CONTENT:(e,t,r)=>`email:content:${e}:${t}:${r}`,CALENDAR:e=>`widget:calendar:${e}`,NEWS:(e="100")=>`widget:news:${e}`,TASKS:e=>`widget:tasks:${e}`,MESSAGES:e=>`widget:messages:${e}`},E={CREDENTIALS:86400,SESSION:14400,EMAIL_LIST:300,EMAIL_CONTENT:900,CALENDAR:600,NEWS:900,TASKS:600,MESSAGES:120};async function S(e,t,r){let n=u(),o=p.CREDENTIALS(e,t);if(!r.email||!r.host||!r.password&&!r.useOAuth)return void console.error(`Cannot cache incomplete credentials for user ${e}`);try{console.log(`Caching credentials for user ${e}`);let t={email:r.email,host:r.host,port:r.port,secure:r.secure??!0,...r.smtp_host&&{smtp_host:r.smtp_host},...r.smtp_port&&{smtp_port:r.smtp_port},...void 0!==r.smtp_secure&&{smtp_secure:r.smtp_secure},...r.display_name&&{display_name:r.display_name},...r.color&&{color:r.color},...void 0!==r.useOAuth&&{useOAuth:r.useOAuth},...r.accessToken&&{accessToken:r.accessToken},...r.refreshToken&&{refreshToken:r.refreshToken},...r.tokenExpiry&&{tokenExpiry:r.tokenExpiry}};if(r.password)try{var s;let n=(s=r.password,c().AES.encrypt(s,d()).toString());console.log(`Successfully encrypted password for user ${e}`),t.encryptedPassword=n}catch(t){console.error(`Failed to encrypt password for user ${e}:`,t)}await n.set(o,JSON.stringify(t),"EX",E.CREDENTIALS),console.log(`Credentials cached for user ${e}`)}catch(t){console.error(`Error caching credentials for user ${e}:`,t)}}async function f(e,t){let r=u(),n=p.CREDENTIALS(e,t);try{let t,s=await r.get(n);if(!s)return null;let a=JSON.parse(s);if(a.encryptedPassword)try{var o;o=a.encryptedPassword,t=c().AES.decrypt(o,d()).toString(c().enc.Utf8)}catch(t){if(console.error(`Failed to decrypt password for user ${e}:`,t),!a.useOAuth)return null}return{email:a.email,host:a.host,port:a.port,secure:a.secure??!0,...t&&{password:t},...a.smtp_host&&{smtp_host:a.smtp_host},...a.smtp_port&&{smtp_port:a.smtp_port},...void 0!==a.smtp_secure&&{smtp_secure:a.smtp_secure},...a.display_name&&{display_name:a.display_name},...a.color&&{color:a.color},...void 0!==a.useOAuth&&{useOAuth:a.useOAuth},...a.accessToken&&{accessToken:a.accessToken},...a.refreshToken&&{refreshToken:a.refreshToken},...a.tokenExpiry&&{tokenExpiry:a.tokenExpiry}}}catch(t){return console.error(`Error getting credentials for user ${e}:`,t),null}}async function g(e,t){let r=u(),n=p.SESSION(e);t.lastActive=Date.now(),await r.set(n,JSON.stringify(t),"EX",E.SESSION)}async function y(e){let t=u(),r=p.SESSION(e),n=await t.get(r);return n?JSON.parse(n):null}async function h(e,t,r,n,o,s){let c=u(),a=p.EMAIL_LIST(e,t,r,n,o);await c.set(a,JSON.stringify(s),"EX",E.EMAIL_LIST)}async function m(e,t,r,n,o){let s=u(),c=p.EMAIL_LIST(e,t,r,n,o),a=await s.get(c);return a?JSON.parse(a):null}async function N(e,t,r,n){let o=u(),s=p.EMAIL_CONTENT(e,t,r);await o.set(s,JSON.stringify(n),"EX",E.EMAIL_CONTENT)}async function w(e,t,r){let n=u(),o=p.EMAIL_CONTENT(e,t,r),s=await n.get(o);return s?JSON.parse(s):null}async function A(e,t,r){let n=u(),o=`email:list:${e}:${t}:${r}:*`,s="0";do{let[e,t]=await n.scan(s,"MATCH",o,"COUNT",100);s=e,t.length>0&&await n.del(...t)}while("0"!==s)}async function T(e,t,r){let n=u(),o=p.EMAIL_CONTENT(e,t,r);await n.del(o)}async function $(){try{let e=u();return await e.ping(),console.log("Redis connection warmed up"),!0}catch(e){return console.error("Error warming up Redis:",e),!1}}async function O(){try{let e=u(),t=await e.ping();return{status:"connected",ping:t}}catch(e){return{status:"error",error:e instanceof Error?e.message:String(e)}}}async function _(e,t){return f(e,t)}async function R(e,t){let r=u(),n=p.CALENDAR(e);try{await r.set(n,JSON.stringify(t),"EX",E.CALENDAR),console.log(`Calendar data cached for user ${e}`)}catch(t){console.error(`Error caching calendar data for user ${e}:`,t)}}async function I(e){let t=u(),r=p.CALENDAR(e);try{let e=await t.get(r);if(!e)return null;return JSON.parse(e)}catch(t){return console.error(`Error getting cached calendar data for user ${e}:`,t),null}}async function k(e,t="100"){let r=u(),n=p.NEWS(t);try{await r.set(n,JSON.stringify(e),"EX",E.NEWS),console.log(`News data cached successfully (${e.length} articles, limit=${t})`)}catch(e){console.error("Error caching news data:",e)}}async function L(e="100"){let t=u(),r=p.NEWS(e);try{let n=await t.get(r);if(!n)return null;let o=JSON.parse(n);return console.log(`Retrieved ${o.length} articles from cache with limit=${e}`),o}catch(e){return console.error("Error getting cached news data:",e),null}}async function v(e){let t=u();try{if(e){let r=p.NEWS(e);await t.del(r),console.log(`News cache invalidated for limit=${e}`)}else{for(let e of["5","50","100","200"]){let r=p.NEWS(e);await t.del(r)}console.log("All news caches invalidated")}}catch(e){console.error("Error invalidating news cache:",e)}}async function C(e,t){let r=u(),n=p.TASKS(e);try{await r.set(n,JSON.stringify(t),"EX",E.TASKS),console.log(`Tasks data cached for user ${e}`)}catch(t){console.error(`Error caching tasks data for user ${e}:`,t)}}async function M(e){let t=u(),r=p.TASKS(e);try{let e=await t.get(r);if(!e)return null;return JSON.parse(e)}catch(t){return console.error(`Error getting cached tasks data for user ${e}:`,t),null}}async function D(e,t){let r=u(),n=p.MESSAGES(e);try{await r.set(n,JSON.stringify(t),"EX",E.MESSAGES),console.log(`Messages data cached for user ${e}`)}catch(t){console.error(`Error caching messages data for user ${e}:`,t)}}async function J(e){let t=u(),r=p.MESSAGES(e);try{let e=await t.get(r);if(!e)return null;return JSON.parse(e)}catch(t){return console.error(`Error getting cached messages data for user ${e}:`,t),null}}}};