"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")},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,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:()=>f,default:()=>D,routeModule:()=>v});var o={};t.r(o),t.d(o,{default:()=>S});var n=t(89947),s=t(2706),a=t(96762),i=t(29021),c=t.n(i),u=t(69842),d=t(67619),l=t(48786),_=t(45185),m=t(27825),p=t.n(m);async function S(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,u.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let o=e.body.mediaObject,n=e.body.newName,s=e.body.newThumbnailName,a=e.body.replace;try{"production".match(/production/);let e=o.media_url.match(/\..{3,4}$/)[0],i=o?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let u=(0,_.A)({isPrivate:i,userId:t.id,folder:o.folder?o.folder+"/":"",video:!!o.media_type?.match(/video/i)});if(!u)throw Error("Couldn't grab paths!");let{fileRootPath:d,urlRootPath:m,relativePath:S}=u,D=`${d}${o.media_name}${e}`,f=`${d}${n}${e}`,v=`${d}${o.media_name}_thumbnail${e}`,E=`${d}${n}_thumbnail${e}`,A=new RegExp(p().escapeRegExp(`${o.media_name}`)),h=o.media_url.replace(A,n),g=o.media_url.replace(A,n+"_thumbnail"),L=o.media_path?o.media_path.replace(A,n):`${S}${n}`,R=o.media_thumbnail_path?o.media_thumbnail_path.replace(A,n):`${S}${s}`;if(c().existsSync(f)&&!a)return r.json({success:!1,msg:"File already exists"});c().renameSync(D,f);try{c().renameSync(v,E)}catch(e){}await (0,l.A)("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[n,h,g,L,R,o.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),(0,d.A)({component:"/api/renameMedia/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let D=(0,a.M)(o,"default"),f=(0,a.M)(o,"config"),v=new n.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:o})},45185:(e,r,t)=>{t.d(r,{A:()=>i});var o=t(29021),n=t.n(o),s=t(33873),a=t.n(s);function i({isPrivate:e,userId:r,folder:t,video:o,pathOnly:s}){"production".match(/production/);let i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)return console.log("Static File ENV not Found!"),null;let c=e?`@/${o?"videos":"media"}/${t?t+"/":""}`:o?`/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+"/":""}`:a().join(i,c);return n().existsSync(u)||s||n().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${c}`,relativePath:c}}},69842:(e,r,t)=>{async function o(e,r,t){return Object(function(){var e=Error("Cannot find module '@moduletrace/datasquirel/dist/users/user-auth'");throw e.code="MODULE_NOT_FOUND",e}())({req:e,level:t?"deep":void 0}).payload}t.d(r,{A:()=>o}),function(){var e=Error("Cannot find module '@moduletrace/datasquirel/dist/users/user-auth'");throw e.code="MODULE_NOT_FOUND",e}()},67619:(e,r,t)=>{t.d(r,{A:()=>s});var o=t(29021),n=t.n(o);async function s({user:e,message:r,component:t,noMail:o,req:s}){let a=new Date,i=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],o=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||o||r||s.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let o=`🚀 SERVER ERROR =========================== Error Message: ${r} Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(o+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),s?.url&&(o+=` URL: ${s.url}`),s?.body&&(o+=` Request Body: ${JSON.stringify(s.body,null,4)}`),i&&(o+=` IP: ${i}`),o+=` Date: ${a.toDateString()} ========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let c=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",o),n().appendFileSync("./.tmp/error.log",` ${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,t)=>{t.d(r,{A:()=>n});var o=t(7447);async function n(...e){let r=(0,o.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()}}},7447:(e,r,t)=>{t.d(r,{A:()=>s});var o=t(9973),n=t.n(o);function s(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||n()({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||n()({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||n()({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||n()({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 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})();