"use strict";(()=>{var e={};e.id=8103,e.ids=[8103],e.modules={27825:e=>{e.exports=require("lodash")},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}}})},8639:(e,r,t)=>{t.r(r),t.d(r,{config:()=>E,default:()=>f,routeModule:()=>S});var n={};t.r(n),t.d(n,{default:()=>p});var i=t(89947),a=t(2706),s=t(96762),o=t(69842),l=t(67619),u=t(48786),c=t(45185),d=t(27825),_=t.n(d);let m=t(29021);async function p(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,o.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let n=e.body.mediaObject,i=e.body.newName,a=e.body.newThumbnailName,s=e.body.replace;try{"production".match(/production/);let e=n.media_url.match(/\..{3,4}$/)[0],o=n?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let l=(0,c.A)({isPrivate:o,userId:t.id,folder:n.folder?n.folder+"/":"",video:!!n.media_type?.match(/video/i)});if(!l)throw Error("Couldn't grab paths!");let{fileRootPath:d,urlRootPath:p,relativePath:f}=l,E=`${d}${n.media_name}${e}`,S=`${d}${i}${e}`,h=`${d}${n.media_name}_thumbnail${e}`,g=`${d}${i}_thumbnail${e}`,y=new RegExp(_().escapeRegExp(`${n.media_name}`)),$=n.media_url.replace(y,i),A=n.media_url.replace(y,i+"_thumbnail"),v=n.media_path?n.media_path.replace(y,i):`${f}${i}`,P=n.media_thumbnail_path?n.media_thumbnail_path.replace(y,i):`${f}${a}`;if(m.existsSync(S)&&!s)return r.json({success:!1,msg:"File already exists"});m.renameSync(E,S);try{m.renameSync(h,g)}catch(e){}await (0,u.A)("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[i,$,A,v,P,n.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),(0,l.default)({component:"/api/renameMedia/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let f=(0,s.M)(n,"default"),E=(0,s.M)(n,"config"),S=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:n})},45185:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),i=t.n(n),a=t(33873),s=t.n(a);function o({isPrivate:e,userId:r,folder:t,video:n,pathOnly:a}){"production".match(/production/);let o=process.env.DSQL_STATIC_SERVER_DIR;if(!o)return console.log("Static File ENV not Found!"),null;let l=e?`@/${n?"videos":"media"}/${t?t+"/":""}`:n?`/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+"/":""}`:s().join(o,l);return i().existsSync(u)||a||i().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${l}`,relativePath:l}}},69842:(e,r,t)=>{t.d(r,{A:()=>l});var n=t(48786),i=t(95969),a=t(29021),s=t.n(a),o=t(89159);async function l(e,r,t){let{keyCookieName:a,csrfCookieName:l}=(0,o.A)();if(!e.cookies?.[a]?.match(/./))return null;let u=(0,i.A)({encryptedString:e.cookies[a]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!s().existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,n.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,r,t)=>{t.d(r,{A:()=>n});function n(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",n=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),s=r;e?.userId&&(s+=`user_${e.userId}_`),a&&(s+=`${a}_`),s+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=n;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:s,csrfCookieName:o,oneTimeCodeName:l+=i}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var n=t(29021),i=t.n(n);async function a({user:e,message:r,component:t,noMail:n,req:a}){let s=new Date,o=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||n||r||a.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}`),a?.url&&(n+=` URL: ${a.url}`),a?.body&&(n+=` Request Body: ${JSON.stringify(a.body,null,4)}`),o&&(n+=` IP: ${o}`),n+=` Date: ${s.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)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(55511),i=t(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,s=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!s?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,n.scryptSync)(a,s,o),u=i.Buffer.alloc(16,0),c=(0,n.createDecipheriv)("aes-192-cbc",l,u);try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>n});async function n(...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=8639);module.exports=t})();