"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,t)=>{t.r(r),t.d(r,{config:()=>v,default:()=>S,routeModule:()=>g});var a={};t.r(a),t.d(a,{config:()=>f,default:()=>h});var i=t(89947),s=t(2706),l=t(96762),o=t(98e3),n=t(96551),u=t(45185),d=t(67619),c=t(69842);let m=t(29021),_=t(33873),{execSync:p}=t(79646),f={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};async function h(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,c.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let a=e.body,{media:i}=a,s=a.folder,l=a.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-${t.id}/${s}`);m.existsSync(e)||m.mkdirSync(e,{recursive:!0});let r=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media/${s}`;m.existsSync(r)||m.mkdirSync(r,{recursive:!0})}try{let e=[];for(let r=0;r{t.d(r,{A:()=>o});var a=t(9288),i=t.n(a),s=t(67619),l=t(45185);async function o({imageSourceBase64:e,imageName:r,userId:t,mimeType:a,thumbnailSize:o,folder:n,isPrivate:u}){try{let s=Buffer.from(e,"base64"),d=o?parseInt(o.toString()):400,c=i()(s),m=i()(s),_=(0,l.A)({isPrivate:u,userId:t,folder:n});if(!_)return null;let{fileRootPath:p,urlRootPath:f,relativePath:h}=_,{width:S,height:v,format:g}=await c.metadata(),E=a||g;S&&v&&S>1800&&c.resize(1800,Math.round(1800/S*v),{fit:"cover"}),c.toFormat(E,{quality:80}),await c.metadata();let y=`${r}.${E}`;if(await c.toFile(p+y),S&&v&&S>d){let e=d/S;m.resize(d,Math.round(v*e),{fit:"cover"})}else S&&v&&m.resize(150,Math.round(150/S*v),{fit:"cover"});m.toFormat(E,{quality:80});let $=`${r}_thumbnail.${E}`;return await m.toFile(p+$),{urlPath:f+y,urlThumbnailPath:f+$,urlRelativePath:h+y,urlThumbnailRelativePath:h+$}}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,t)=>{t.d(r,{A:()=>o});var a=t(29021),i=t.n(a),s=t(33873),l=t.n(s);function o({isPrivate:e,userId:r,folder:t,video:a,pathOnly:s}){"production".match(/production/);let o=process.env.DSQL_STATIC_SERVER_DIR;if(!o)return console.log("Static File ENV not Found!"),null;let n=e?`@/${a?"videos":"media"}/${t?t+"/":""}`:a?`/videos/user-videos/user-${r}/${t?t+"/":""}`:`/images/user-images/user-${r}/${t?t+"/":""}`,u=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${t?t+"/":""}`:l().join(o,n);return i().existsSync(u)||s||i().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${n}`,relativePath:n}}},69842:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(48786),i=t(95969),s=t(29021),l=t.n(s),o=t(89159);async function n(e,r,t){try{let{keyCookieName:s,csrfCookieName:n}=(0,o.A)();if(!e.cookies?.[s]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,i.A)({encryptedString:e.cookies[s]});if(!u)throw Error("Couldn't decrypt auth cookie!");let d=JSON.parse(u);if(!d.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!l().existsSync(`${c}/${d.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==d.verification_status&&!t){let e=await (0,a.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"])}if(d?.date&&Date.now()-d.date>6048e5)throw Error("Key expired!");return d}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=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+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),s&&(o+=`${s}_`),o+=a;let n=r;return e?.userId&&(n+=`user_${e.userId}_`),s&&(n+=`${s}_`),{keyCookieName:l,csrfCookieName:o,oneTimeCodeName:n+=i}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>s});var a=t(29021),i=t.n(a);async function s({user:e,message:r,component:t,noMail:a,req:s}){let l=new Date,o=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||a||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),s?.url&&(a+=` URL: ${s.url}`),s?.body&&(a+=` Request Body: ${JSON.stringify(s.body,null,4)}`),o&&(a+=` IP: ${o}`),a+=` Date: ${l.toDateString()} ========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let n=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",a),i().appendFileSync("./.tmp/error.log",` ${n}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(55511),i=t(79428);function s({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let s=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,o=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 n=(0,a.scryptSync)(s,l,o),u=i.Buffer.alloc(16,0),d=(0,a.createDecipheriv)("aes-192-cbc",n,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 t=e=>r(r.s=e),a=r.X(0,[1251],()=>t(27973));module.exports=a})();