"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,a){return a in r?r[a]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,a)):"function"==typeof r&&"default"===a?r:void 0}}})},8639:(e,r,a)=>{a.r(r),a.d(r,{config:()=>f,default:()=>D,routeModule:()=>v});var t={};a.r(t),a.d(t,{default:()=>S});var s=a(89947),n=a(2706),o=a(96762),i=a(29021),l=a.n(i),d=a(69842),u=a(67619),c=a(48786),_=a(45185),p=a(27825),m=a.n(p);async function S(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let a=await (0,d.A)(e,r,!0);if(!a)return r.json({success:!1,msg:"Unauthorized"});let t=e.body.mediaObject,s=e.body.newName,n=e.body.newThumbnailName,o=e.body.replace;try{"production".match(/production/);let e=t.media_url.match(/\..{3,4}$/)[0],i=t?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let d=(0,_.A)({isPrivate:i,userId:a.id,folder:t.folder?t.folder+"/":"",video:!!t.media_type?.match(/video/i)});if(!d)throw Error("Couldn't grab paths!");let{fileRootPath:u,urlRootPath:p,relativePath:S}=d,D=`${u}${t.media_name}${e}`,f=`${u}${s}${e}`,v=`${u}${t.media_name}_thumbnail${e}`,g=`${u}${s}_thumbnail${e}`,h=new RegExp(m().escapeRegExp(`${t.media_name}`)),A=t.media_url.replace(h,s),E=t.media_url.replace(h,s+"_thumbnail"),R=t.media_path?t.media_path.replace(h,s):`${S}${s}`,y=t.media_thumbnail_path?t.media_thumbnail_path.replace(h,s):`${S}${n}`;if(l().existsSync(f)&&!o)return r.json({success:!1,msg:"File already exists"});l().renameSync(D,f);try{l().renameSync(v,g)}catch(e){}await (0,c.A)("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[s,A,E,R,y,t.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),(0,u.A)({component:"/api/renameMedia/catch-error",message:e.message,user:a}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let D=(0,o.M)(t,"default"),f=(0,o.M)(t,"config"),v=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:t})},55153:(e,r,a)=>{a.d(r,{On:()=>s.a,_n:()=>o}),a(76102);var t=a(65967),s=a.n(t);a(30889);var n=a(93726);let o=a.n(n)()},45185:(e,r,a)=>{a.d(r,{A:()=>i});var t=a(29021),s=a.n(t),n=a(33873),o=a.n(n);function i({isPrivate:e,userId:r,folder:a,video:t,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 l=e?`@/${t?"videos":"media"}/${a?a+"/":""}`:t?`/videos/user-videos/user-${r}/${a?a+"/":""}`:`/images/user-images/user-${r}/${a?a+"/":""}`,d=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${a?a+"/":""}`:o().join(i,l);return s().existsSync(d)||n||s().mkdirSync(d,{recursive:!0}),{fileRootPath:d,urlRootPath:e?`@/media/${a?a+"/":""}`:`${process.env.DSQL_STATIC_HOST}${l}`,relativePath:l}}},69842:(e,r,a)=>{a.d(r,{A:()=>o});var t=a(39383),s=a.n(t),n=a(55153);async function o(e,r,a,t){let o=s()({req:e,level:a?"deep":void 0});return t&&o.payload?.id&&(0,n._n)(process.env.DSQL_SU_USER_ID)!==o.payload.id?null:o.payload}},67619:(e,r,a)=>{a.d(r,{A:()=>n});var t=a(29021),s=a.n(t);async function n({user:e,message:r,component:a,noMail:t,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"],a=n.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],s=a||t||r||n.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${a}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),n?.url&&(t+=` URL: ${n.url}`),n?.body&&(t+=` Request Body: ${JSON.stringify(n.body,null,4)}`),i&&(t+=` IP: ${i}`),t+=` Date: ${o.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",t),s().appendFileSync("./.tmp/error.log",` ${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,a)=>{a.d(r,{A:()=>s});var t=a(7447);async function s(...e){let r=(0,t.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let a=await r.query(...e);return JSON.parse(JSON.stringify(a))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},7447:(e,r,a)=>{a.d(r,{A:()=>n});var t=a(9973),s=a.n(t);function n(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"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return a}});var a=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,a)=>{e.exports=a(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var a=r(r.s=8639);module.exports=a})();