"use strict";(()=>{var e={};e.id=7918,e.ids=[7918],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},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}}})},83701:(e,r,t)=>{t.r(r),t.d(r,{config:()=>D,default:()=>f,routeModule:()=>g});var n={};t.r(n),t.d(n,{config:()=>d,default:()=>p});var s=t(89947),o=t(2706),i=t(96762),a=t(29021),l=t.n(a),c=t(48786),u=t(61932),_=t(67619),S=t(56081);let d={api:{bodyParser:{sizeLimit:"50mb"}}};async function p(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,S.A)({key:t,user_id:String(e.query.user_id)});if(!n?.user_id)throw Error("Api Credentials invalid!");let{user_id:s,full_access:o}=n;if(!o)return r.json({success:!1,msg:"Unauthorized"});let{url:i}=e.body,a=await (0,c.A)("SELECT * FROM user_media WHERE media_url = ?",[i]);if(!a?.length)return r.json({success:!1,msg:"Media not found!"});let{id:_,folder:d,media_url:p,media_thumbnail_url:f,media_type:D}=a[0],g=process.env.DSQL_STATIC_SERVER_DIR;if(!g)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let E=e=>!e||e?.match(/\.\./)?"":e?.match(/^\@/)?e.replace(/@\/media\//,`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s}/media/`):e.replace(process.env.DSQL_STATIC_HOST||"",g),m=E(p),A=E(f);if(!m?.match(/./))return r.json({success:!1,msg:"Invalid path!"});try{l().unlinkSync(m),l().unlinkSync(A),await (0,u.A)({dbFullName:"datasquirel",tableName:"user_media",identifierColumnName:"id",identifierValue:_}),r.json({success:!0,payload:{url:i}})}catch(e){console.log("File delete error:",e.message),r.json({success:!1,payload:{url:i},error:e.message})}}catch(t){console.log("File write error:",t),(0,_.A)({component:"/api/query/delete-file/main-catch-error",message:t.message,req:e}),r.json({success:!1,msg:"Delete File Error!",error:t.message})}}let f=(0,i.M)(n,"default"),D=(0,i.M)(n,"config"),g=new s.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/query/[user_id]/delete-file",pathname:"/api/query/[user_id]/delete-file",bundlePath:"",filename:""},userland:n})},56081:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(29021),s=t.n(n),o=t(95969);let i=({key:e,database:r,table:t,user_id:n,media:i})=>{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 l=(0,o.A)({encryptedString:e}),c=JSON.parse(l||""),u=s().existsSync(`${a}/${c.sign}`);if(String(c.user_id)!==String(n)||!u)return null;if(!c.target_database||i)return c;if(!r&&c.target_database)return null;let _=c.target_database?.split(",").includes(String(r));if(_&&!c.target_table)return c;if(_&&!t&&c.target_table)return null;if(c.target_table?.split(",").includes(String(t)))return c;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),{error:`api-cred ERROR: ${e.message}`}}}},61932:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(52939),s=t(64292);async function o({dbContext:e,dbFullName:r,tableName:t,identifierColumnName:o,identifierValue:i,forceLocal:a}){try{let l=!!a||(0,n.A)({dbContext:e,dbFullName:r}),c=l?global.DSQL_DB_CONN:global.DSQL_FULL_ACCESS_DB_CONN||global.DSQL_DB_CONN;l?global.DSQL_DB_CONN:global.DSQL_READ_ONLY_DB_CONN||global.DSQL_DB_CONN;let u=`DELETE FROM ${l?"":`\`${r}\`.`}\`${t}\` WHERE \`${o}\`=?`;return await (0,s.A)(c,u,[i])}catch(e){return null}}},67619:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),s=t.n(n);async function o({user:e,message:r,component:t,noMail:n,req:o}){let i=new Date,a=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],t=o.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||o.socket.remoteAddress;if(!s)return null;return String(s)}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}`),o?.url&&(n+=`
URL: ${o.url}`),o?.body&&(n+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),a&&(n+=`
IP: ${a}`),n+=`
Date: ${i.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let l=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",n),s().appendFileSync("./.tmp/error.log",`




${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(55511),s=t(79428),o=t(31542);function i({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:i,salt:a,keyLen:l,algorithm:c,bufferAllocSize:u}=(0,o.A)({encryptionKey:r});if(!i?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let _=(0,n.scryptSync)(i,a,l),S=s.Buffer.alloc(u,0),d=(0,n.createDecipheriv)(c,_,S);try{let r=d.update(e,"hex","utf8");return r+=d.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(7447);async function s(...e){let r=(0,n.A)();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()}}},52939:(e,r,t)=>{t.d(r,{A:()=>n});function n({dbContext:e,dbFullName:r}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!r||!!r.match(/^datasquirel$/))}},64292:(e,r,t)=>{async function n(e,r,t){try{if(!e)throw Error("No Connection Found!");if(!r)throw Error("Query String Required!");if("string"==typeof r){let n=await e.query(s(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;n<r.length;n++)try{let o=r[n],i=await e.query(s(o.query),o.values);t.push(JSON.parse(JSON.stringify(i)))}catch(e){console.log(`connDbHandler Query Error: ${e.message}`),t.push(null)}return t}}catch(r){return console.log(`connDbHandler Error: ${r.message}`),console.log(e?.config()),null}finally{e?.end()}}function s(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>n})},7447:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(9973),s=t.n(n);function o(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},31542:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(82535);function s(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=83701);module.exports=t})();