"use strict";(()=>{var e={};e.id=8103,e.ids=[8103],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},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,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},8639:(e,r,s)=>{s.r(r),s.d(r,{config:()=>E,default:()=>D,routeModule:()=>v});var a={};s.r(a),s.d(a,{default:()=>m});var t=s(89947),n=s(2706),o=s(96762),i=s(29021),_=s.n(i),c=s(69842),l=s(67619),u=s(48786),d=s(45185),S=s(27825),p=s.n(S);async function m(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let{user:s,appData:a}=await (0,c.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=e.body.mediaObject,n=e.body.newName,o=e.body.newThumbnailName,i=e.body.replace;try{"production".match(/production/);let e=t.media_url.match(/\..{3,4}$/)[0],a=t?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let c=(0,d.A)({isPrivate:a,userId:s.id,folder:t.folder?t.folder+"/":"",video:!!t.media_type?.match(/video/i)});if(!c)throw Error("Couldn't grab paths!");let{fileRootPath:l,urlRootPath:S,relativePath:m}=c,D=`${l}${t.media_name}${e}`,E=`${l}${n}${e}`,v=`${l}${t.media_name}_thumbnail${e}`,L=`${l}${n}_thumbnail${e}`,f=new RegExp(p().escapeRegExp(`${t.media_name}`)),A=t.media_url.replace(f,n),g=t.media_url.replace(f,n+"_thumbnail"),h=t.media_path?t.media_path.replace(f,n):`${m}${n}`,O=t.media_thumbnail_path?t.media_thumbnail_path.replace(f,n):`${m}${o}`;if(_().existsSync(E)&&!i)return r.json({success:!1,msg:"File already exists"});_().renameSync(D,E);try{_().renameSync(v,L)}catch(e){}await (0,u.A)("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[n,A,g,h,O,t.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),(0,l.A)({component:"/api/renameMedia/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let D=(0,o.M)(a,"default"),E=(0,o.M)(a,"config"),v=new t.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:a})},55153:(e,r,s)=>{s.d(r,{On:()=>t.a,_n:()=>o}),s(76102);var a=s(65967),t=s.n(a);s(30889);var n=s(93726);let o=s.n(n)()},45185:(e,r,s)=>{s.d(r,{A:()=>i});var a=s(29021),t=s.n(a),n=s(33873),o=s.n(n);function i({isPrivate:e,userId:r,folder:s,video:a,pathOnly:n}){"production".match(/production/);let i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)return console.log("Static File ENV not Found!"),null;let _=e?`@/${a?"videos":"media"}/${s?s+"/":""}`:a?`/videos/user-videos/user-${r}/${s?s+"/":""}`:`/images/user-images/user-${r}/${s?s+"/":""}`,c=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${s?s+"/":""}`:o().join(i,_);return t().existsSync(c)||n||t().mkdirSync(c,{recursive:!0}),{fileRootPath:c,urlRootPath:e?`@/media/${s?s+"/":""}`:`${process.env.DSQL_STATIC_HOST}${_}`,relativePath:_}}},69842:(e,r,s)=>{s.d(r,{A:()=>o});var a=s(39383),t=s.n(a),n=s(55153);async function o(e,r,s,a){let o=t()({req:e,level:s?"deep":void 0}),i={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return a&&o.payload?.id&&(0,n._n)(process.env.DSQL_SU_USER_ID)!==o.payload.id?{user:null,appData:i}:{user:o.payload,appData:i}}},67619:(e,r,s)=>{s.d(r,{A:()=>n});var a=s(29021),t=s.n(a);async function n({user:e,message:r,component:s,noMail:a,req:n}){let o=new Date,i=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],s=n.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],t=s||a||r||n.socket.remoteAddress;if(!t)return null;return String(t)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${s}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),n?.url&&(a+=`
URL: ${n.url}`),n?.body&&(a+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),i&&(a+=`
IP: ${i}`),a+=`
Date: ${o.toDateString()}
========================================`,t().existsSync("./.tmp/error.log")||t().writeFileSync("./.tmp/error.log","","utf-8");let _=t().readFileSync("./.tmp/error.log","utf-8");t().writeFileSync("./.tmp/error.log",a),t().appendFileSync("./.tmp/error.log",`




${_}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,s)=>{s.d(r,{A:()=>t});var a=s(7447);async function t(...e){let r=(0,a.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>n});var a=s(9973),t=s.n(a);function n(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||t()({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||t()({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||t()({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||t()({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"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=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,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=r(r.s=8639);module.exports=s})();