"use strict";(()=>{var e={};e.id=2678,e.ids=[2678],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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}}})},38887:(e,r,s)=>{s.r(r),s.d(r,{config:()=>p,default:()=>m,routeModule:()=>D});var t={};s.r(t),s.d(t,{default:()=>S});var i=s(89947),o=s(2706),a=s(96762),n=s(29021),c=s.n(n),u=s(48786),d=s(69842),_=s(33873),l=s.n(_);async function S(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});let s=await (0,d.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=e.body;if(t.media_url?.match(/\.\./)||t.folder?.match(/\.\./)||t.id?.toString()?.match(/\.\./))return r.json({success:!1,msg:"Error!",error:"Invalid url"});try{let e=t?.private==1,i=e?t?.media_path?.replace(/\@\/media/i,"")||t?.media_url.replace(/\@\/media/i,""):t?.media_path?.match(/\/user-images\/user-.*/)||t?.media_url?.match(/\/user-images\/user-.*/),o=t.folder?`/${t.folder}`:"",a=process.env.DSQL_STATIC_SERVER_DIR;if(!a)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let n=l().join(a,"images"),d=`${process.env.DSQL_STATIC_HOST}/images/user-images/user-${s.id}`,_=`/images/user-images/user-${s.id}`,S=(e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/media`:n)+i,m=e?`${n}/user-images/user-${s.id}`:`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/media`;if(!c().existsSync(m))try{c().mkdirSync(m,{recursive:!0})}catch(e){console.log("LINE 88 error:",e.message)}o&&o.split("/").reduce((e,r)=>{let s=e?.match(/./)?`${e}/${r}`:m;return c().existsSync(s)||c().mkdirSync(s,{recursive:!0}),s},"");let p=S?.match(/[^\/]+$/)?.[0];if(!p)throw Error("No File Name Detected!");let D=p.split(".")[0],v=p.split(".")[1],A=e?`${d}${o?o+"/":"/"}${p}`:`@/media${o?o+"/":"/"}${p}`,f=e?`${_}${o?o+"/":"/"}${p}`:`@/media${o?o+"/":"/"}${p}`,E=m+o+"/"+p;c().copyFileSync(S,E),c().unlinkSync(S);let P=D+"_thumbnail."+v,h=S.replace(p,P),g=e?`${d}${o?o+"/":"/"}${P}`:`@/media${o?o+"/":"/"}${P}`,L=e?`${_}${o?o+"/":"/"}${P}`:`@/media${o?o+"/":"/"}${P}`;try{c().copyFileSync(h,m+o+"/"+P),c().unlinkSync(h)}catch(e){}await (0,u.A)("UPDATE user_media SET private = ?, media_url= ?, media_thumbnail_url= ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[e?0:1,A,g,f,L,t.id]),r.json({success:!0,msg:"Success!"})}catch(e){console.log(e.message),r.json({success:!1,msg:"Error!",error:e})}}let m=(0,a.M)(t,"default"),p=(0,a.M)(t,"config"),D=new i.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/media/addPrivateMedia",pathname:"/api/media/addPrivateMedia",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>o});var t=s(39908),i=s.n(t);async function o(e,r,s){let t=i()({req:e,level:s?"deep":void 0});return console.log(t),t.payload}},48786:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(7447);async function i(...e){let r=(0,t.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:()=>o});var t=s(9973),i=s.n(t);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||i()({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||i()({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||i()({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=38887);module.exports=s})();