"use strict";(()=>{var e={};e.id=5287,e.ids=[5287],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}}})},45096:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>_,routeModule:()=>A});var n={};t.r(n),t.d(n,{config:()=>g,default:()=>m});var i=t(89947),s=t(2706),o=t(96762),a=t(29021),u=t.n(a),l=t(33873),c=t.n(l),d=t(45185),f=t(67619),p=t(56081);let g={api:{bodyParser:{sizeLimit:"100mb"}}};async function m(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});try{let t=e.headers.authorization;if(!t)return r.json({success:!1,msg:"Unauthorized"});let n=(0,p.A)({key:t,user_id:String(e.query.user_id)});if(!n?.user_id)throw Error("Api Credentials invalid!");let{user_id:i,full_access:s}=n;if(!s)return r.json({success:!1,msg:"Unauthorized"});let{folder:o,fileName:a,downloadType:l}=e.body,f=(0,d.A)({folder:o,isPrivate:!0,userId:n.user_id});if(!f)throw Error("Couldn't Grab Image URLs");let{fileRootPath:g}=f,m=c().join(g,a);if(l?.match(/raw/i)){let e=u().readFileSync(m,"utf-8");return r.json({success:!0,data:e})}if(l?.match(/base64/i)){let e=u().readFileSync(m,"base64");return r.json({success:!0,data:e})}u().createReadStream(m).pipe(r)}catch(t){console.log("Get Private File Error:",t),(0,f.A)({component:"/api/query/get-private-file/main-catch-error",message:t.message,req:e}),r.json({success:!1,msg:"Get Private File Error!",error:t.message})}}let _=(0,o.M)(n,"default"),S=(0,o.M)(n,"config"),A=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/query/[user_id]/get-private-file",pathname:"/api/query/[user_id]/get-private-file",bundlePath:"",filename:""},userland:n})},45185:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(29021),i=t.n(n),s=t(33873),o=t.n(s);function a({isPrivate:e,userId:r,folder:t,video:n,pathOnly:s}){"production".match(/production/);let a=process.env.DSQL_STATIC_SERVER_DIR;if(!a)return console.log("Static File ENV not Found!"),null;let u=e?`@/${n?"videos":"media"}/${t?t+"/":""}`:n?`/videos/user-videos/user-${r}/${t?t+"/":""}`:`/images/user-images/user-${r}/${t?t+"/":""}`,l=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${t?t+"/":""}`:o().join(a,u);return i().existsSync(l)||s||i().mkdirSync(l,{recursive:!0}),{fileRootPath:l,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${u}`,relativePath:u}}},56081:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),i=t.n(n),s=t(95969);let o=({key:e,database:r,table:t,user_id:n,media:o})=>{if(!e||!n)return null;try{let a=process.env.DSQL_API_KEYS_PATH;if(!a)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let u=(0,s.A)({encryptedString:e}),l=JSON.parse(u||""),c=i().existsSync(`${a}/${l.sign}`);if(String(l.user_id)!==String(n)||!c)return null;if(!l.target_database||o)return l;if(!r&&l.target_database)return null;let d=l.target_database?.split(",").includes(String(r));if(d&&!l.target_table)return l;if(d&&!t&&l.target_table)return null;if(l.target_table?.split(",").includes(String(t)))return l;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),{error:`api-cred ERROR: ${e.message}`}}}},67619:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(29021),i=t.n(n);async function s({user:e,message:r,component:t,noMail:n,req:s}){let o=new Date,a=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||n||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),s?.url&&(n+=`
URL: ${s.url}`),s?.body&&(n+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),a&&(n+=`
IP: ${a}`),n+=`
Date: ${o.toDateString()}
========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let u=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",n),i().appendFileSync("./.tmp/error.log",`




${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(55511),i=t(79428),s=t(31542);function o({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:o,salt:a,keyLen:u,algorithm:l,bufferAllocSize:c}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,n.scryptSync)(o,a,u),f=i.Buffer.alloc(c,0),p=(0,n.createDecipheriv)(l,d,f);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},31542:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(82535);function i(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?(0,n.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,t)=>{t.d(r,{A:()=>n});function n(e,r){try{let t=Number(e);if("number"!=typeof t||isNaN(t))return 0;if(r)return Number(t.toFixed(r));return Math.round(t)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}},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=45096);module.exports=t})();