"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")},81630:e=>{e.exports=require("http")},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}}})},48069:(e,r,t)=>{t.r(r),t.d(r,{config:()=>P,default:()=>E,routeModule:()=>y});var i={};t.r(i),t.d(i,{config:()=>S,default:()=>_});var n=t(89947),s=t(2706),o=t(96762),a=t(33873),l=t.n(a),u=t(48227),c=t.n(u),d=t(48225),p=t.n(d),f=t(77619),g=t.n(f);let m=t(29021),S={api:{bodyParser:{sizeLimit:"100mb"}}};async function _(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 i=g()({key:t,user_id:String(e.query.user_id)});if(!i?.user_id)throw Error("Api Credentials invalid!");let{user_id:n,full_access:s}=i;if(!s)return r.json({success:!1,msg:"Unauthorized"});let{folder:o,fileName:a,downloadType:u}=e.body,d=c()({folder:o,isPrivate:!0,user:i});if(!d)throw Error("Couldn't Grab Image URLs");let{fileRootPath:p}=d,f=l().join(p,a);if(u?.match(/raw/i)){let e=m.readFileSync(f,"utf-8");return r.json({success:!0,data:e})}if(u?.match(/base64/i)){let e=m.readFileSync(f,"base64");return r.json({success:!0,data:e})}m.createReadStream(f).pipe(r)}catch(t){console.log("Get Private File Error:",t),p()({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 E=(0,o.M)(i,"default"),P=(0,o.M)(i,"config"),y=new n.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:i})},48227:(e,r,t)=>{let i=t(29021),n=t(33873);e.exports=function({isPrivate:e,user:r,folder:t,video:s,pathOnly:o}){"production".match(/production/);let a=r?.id||r?.user_id,l=process.env.DSQL_STATIC_SERVER_DIR;if(!l)return console.log("Static File ENV not Found!"),null;let u=e?`@/${s?"videos":"media"}/${t?t+"/":""}`:s?`/videos/user-videos/user-${a}/${t?t+"/":""}`:`/images/user-images/user-${a}/${t?t+"/":""}`,c=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${a}/media/${t?t+"/":""}`:n.join(l,u);return i.existsSync(c)||o||i.mkdirSync(c,{recursive:!0}),{fileRootPath:c,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${u}`,relativePath:u}}},77619:(e,r,t)=>{let i=t(29021),n=t(72835);e.exports=({key:e,database:r,table:t,user_id:s})=>{if(!e||!s)return null;try{let o=process.env.DSQL_API_KEYS_PATH;if(!o)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let a=n({encryptedString:e}),l=JSON.parse(a||""),u=i.existsSync(`${o}/${l.sign}`);if(String(l.user_id)!==String(s)||!u)return null;if(!l.target_database)return l;if(!r&&l.target_database)return null;let c=l.target_database?.split(",").includes(String(r));if(c&&!l.target_table)return l;if(c&&!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}`),null}}},48225:(e,r,t)=>{let i=t(29021),{IncomingMessage:n}=t(81630);e.exports=async function({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"],i=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||i||r||s.socket.remoteAddress;if(!n)return null;return String(n)}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 l=i.readFileSync("./.tmp/error.log","utf-8");i.writeFileSync("./.tmp/error.log",n),i.appendFileSync("./.tmp/error.log",`




${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:i,createDecipheriv:n}=t(55511),{Buffer:s}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;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 u=n("aes-192-cbc",i(o,a,l),s.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=48069);module.exports=t})();