"use strict";(()=>{var e={};e.id=979,e.ids=[979],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},9288:e=>{e.exports=require("sharp")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},27973:(e,r,a)=>{a.r(r),a.d(r,{config:()=>v,default:()=>h,routeModule:()=>g});var t={};a.r(t),a.d(t,{config:()=>f,default:()=>S});var i=a(89947),s=a(2706),l=a(96762),n=a(98e3),o=a(96551),u=a(45185),d=a(67619),c=a(69842);let m=a(29021),_=a(33873),{execSync:p}=a(79646),f={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let a=await (0,c.A)(e,r,!0);if(!a)return r.json({success:!1,msg:"Unauthorized"});let t=e.body,{media:i}=t,s=t.folder,l=t.type;"production".match(/production/);let p=process.env.DSQL_STATIC_SERVER_DIR;if(!p)return console.log("Static File ENV not Found!"),r.json({success:!1,msg:"No Static File Path"});if(s){let e=_.join(p,`images/user-images/user-${a.id}/${s}`);m.existsSync(e)||m.mkdirSync(e,{recursive:!0});let r=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${a.id}/media/${s}`;m.existsSync(r)||m.mkdirSync(r,{recursive:!0})}try{let e=[];for(let r=0;r{a.d(r,{A:()=>n});var t=a(9288),i=a.n(t),s=a(67619),l=a(45185);async function n({imageSourceBase64:e,imageName:r,userId:a,mimeType:t,thumbnailSize:n,folder:o,isPrivate:u}){try{let s=Buffer.from(e,"base64"),d=n?parseInt(n.toString()):400,c=i()(s),m=i()(s),_=(0,l.A)({isPrivate:u,userId:a,folder:o});if(!_)return null;let{fileRootPath:p,urlRootPath:f,relativePath:S}=_,{width:h,height:v,format:g}=await c.metadata(),E=t||g;h&&v&&h>1800&&c.resize(1800,Math.round(1800/h*v),{fit:"cover"}),c.toFormat(E,{quality:80}),await c.metadata();let y=`${r}.${E}`;if(await c.toFile(p+y),h&&v&&h>d){let e=d/h;m.resize(d,Math.round(v*e),{fit:"cover"})}else h&&v&&m.resize(150,Math.round(150/h*v),{fit:"cover"});m.toFormat(E,{quality:80});let $=`${r}_thumbnail.${E}`;return await m.toFile(p+$),{urlPath:f+y,urlThumbnailPath:f+$,urlRelativePath:S+y,urlThumbnailRelativePath:S+$}}catch(e){return console.log("Write Image to Disk error =>",e.message),(0,s.default)({component:"functions/backend/fsWriteImageToDiskFromBase64",message:e.message}),null}}},45185:(e,r,a)=>{a.d(r,{A:()=>n});var t=a(29021),i=a.n(t),s=a(33873),l=a.n(s);function n({isPrivate:e,userId:r,folder:a,video:t,pathOnly:s}){"production".match(/production/);let n=process.env.DSQL_STATIC_SERVER_DIR;if(!n)return console.log("Static File ENV not Found!"),null;let o=e?`@/${t?"videos":"media"}/${a?a+"/":""}`:t?`/videos/user-videos/user-${r}/${a?a+"/":""}`:`/images/user-images/user-${r}/${a?a+"/":""}`,u=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${a?a+"/":""}`:l().join(n,o);return i().existsSync(u)||s||i().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${a?a+"/":""}`:`${process.env.DSQL_STATIC_HOST}${o}`,relativePath:o}}},69842:(e,r,a)=>{a.d(r,{A:()=>o});var t=a(48786),i=a(95969),s=a(29021),l=a.n(s),n=a(89159);async function o(e,r,a){let{keyCookieName:s,csrfCookieName:o}=(0,n.A)();if(!e.cookies?.[s]?.match(/./))return null;let u=(0,i.A)({encryptedString:e.cookies[s]});if(!u)return null;let d=JSON.parse(u);if(!d.csrf_k||a&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(a&&!l().existsSync(`${c}/${d.csrf_k}`))return null;if(0==d.verification_status&&!a){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}},89159:(e,r,a)=>{a.d(r,{A:()=>t});function t(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",a=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",s=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),l=r;e?.userId&&(l+=`user_${e.userId}_`),s&&(l+=`${s}_`),l+=a;let n=r;e?.userId&&(n+=`user_${e.userId}_`),s&&(n+=`${s}_`),n+=t;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),s&&(o+=`${s}_`),{keyCookieName:l,csrfCookieName:n,oneTimeCodeName:o+=i}}},67619:(e,r,a)=>{a.r(r),a.d(r,{default:()=>s});var t=a(29021),i=a.n(t);async function s({user:e,message:r,component:a,noMail:t,req:s}){let l=new Date,n=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],a=s.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],i=a||t||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${a}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),s?.url&&(t+=` URL: ${s.url}`),s?.body&&(t+=` Request Body: ${JSON.stringify(s.body,null,4)}`),n&&(t+=` IP: ${n}`),t+=` Date: ${l.toDateString()} ========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let o=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",t),i().appendFileSync("./.tmp/error.log",` ${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,a)=>{a.d(r,{A:()=>s});var t=a(55511),i=a(79428);function s({encryptedString:e,encryptionKey:r,encryptionSalt:a}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let s=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=a||process.env.DSQL_ENCRYPTION_SALT,n=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!s?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=(0,t.scryptSync)(s,l,n),u=i.Buffer.alloc(16,0),d=(0,t.createDecipheriv)("aes-192-cbc",o,u);try{let r=d.update(e,"hex","utf8");return r+=d.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var a=e=>r(r.s=e),t=r.X(0,[1251],()=>a(27973));module.exports=t})();