"use strict";(()=>{var e={};e.id=3338,e.ids=[3338],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},670:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>E,routeModule:()=>S});var o={};t.r(o),t.d(o,{default:()=>f});var s=t(89947),n=t(2706),i=t(96762),c=t(29021),a=t.n(c),u=t(48786),l=t(69842),d=t(33873),_=t.n(d);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});if(!await (0,l.A)(e,r,!0))return r.json({success:!1,msg:"Unauthorized"});let{paradigm:t,payload:o}=e.body;try{console.log("Deleting media =>",o.id);let e=o.media_url,t=process.env.DSQL_STATIC_SERVER_DIR,s=process.env.DSQL_STATIC_HOST;if(!t){console.log("No Static Root Path"),r.json({success:!1,msg:"No Static Root Path"});return}let n=e.replace(s,""),i=_().join(t,n),c=a().existsSync(i);if(console.log("relativePath",n),console.log("STATIC_ROOT",t),console.log("STATIC_HOST",s),console.log("filePath",i),console.log("fileExist",c),c){r.json({success:!1});return}}catch(e){console.log("File verification Error =>",e.message),console.log("File Truly doesn't exist, cotinuing ...")}"user_media"===t&&await (0,u.A)(`DELETE FROM user_media WHERE id='${o.id}'`),r.json({success:!0})}let E=(0,i.M)(o,"default"),p=(0,i.M)(o,"config"),S=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/purgeDb",pathname:"/api/purgeDb",bundlePath:"",filename:""},userland:o})},69842:(e,r,t)=>{t.d(r,{A:()=>a});var o=t(48786),s=t(95969),n=t(29021),i=t.n(n),c=t(89159);async function a(e,r,t){try{let{keyCookieName:n,csrfCookieName:a}=(0,c.A)();if(!e.cookies?.[n]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,s.A)({encryptedString:e.cookies[n]});if(!u)throw Error("Couldn't decrypt auth cookie!");let l=JSON.parse(u);if(!l.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",l),Error("Deep Auth Failed. `csrf` key not found in request headers!");let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!i().existsSync(`${d}/${l.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==l.verification_status&&!t){let e=await (0,o.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(l?.date&&Date.now()-l.date>6048e5)throw Error("Key expired!");return l}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>o});function o(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",o=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=t;let c=r;e?.userId&&(c+=`user_${e.userId}_`),n&&(c+=`${n}_`),c+=o;let a=r;return e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),{keyCookieName:i,csrfCookieName:c,oneTimeCodeName:a+=s}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var o=t(55511),s=t(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=t||process.env.DSQL_ENCRYPTION_SALT,c=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let a=(0,o.scryptSync)(n,i,c),u=s.Buffer.alloc(16,0),l=(0,o.createDecipheriv)("aes-192-cbc",a,u);try{let r=l.update(e,"hex","utf8");return r+=l.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>o});async function o(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=670);module.exports=t})();