"use strict";(()=>{vare={};e.id=979,e.ids=[979],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},9288:e=>{e.exports=require("sharp")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},27973:(e,r,t)=>{t.r(r),t.d(r,{config:()=>v,default:()=>g,routeModule:()=>E});vara={};t.r(a),t.d(a,{config:()=>h,default:()=>S});vari=t(89947),s=t(2706),o=t(96762),l=t(29021),n=t.n(l),u=t(33873),d=t.n(u),c=t(98e3),m=t(96551),_=t(45185),p=t(67619),f=t(69842);leth={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};asyncfunctionS(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,f.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});leta=e.body,{media:i}=a,s=a.folder,o=a.type;"production".match(/production/);letl=process.env.DSQL_STATIC_SERVER_DIR;if(!l)returnconsole.log("Static File ENV not Found!"),r.json({success:!1,msg:"No Static File Path"});if(s){lete=d().join(l,`images/user-images/user-${t.id}/${s}`);n().existsSync(e)||n().mkdirSync(e,{recursive:!0});letr=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media/${s}`;n().existsSync(r)||n().mkdirSync(r,{recursive:!0})}try{lete=[];for(letr=0;r<i.length;r++){leta=i[r];if(o?.match(/image/i)){let{imageBase64:r,imageName:i,imageSize:o,mimeType:l}=a,n=await(0,m.A)({imageName:i.replace(/ /g,"-").replace(/\.{1,}|\//g,""),imageSourceBase64:r,userId:t.id,folder:s,mimeType:l,isPrivate:a.private});if(!n){console.log("Image Write Failed!");continue}let{urlPath:u,urlThumbnailPath:d,urlRelativePath:_,urlThumbnailRelativePath:p}=n;await(0,c.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:t.id,media_name:i.replace(/ /g,"-"),media_url:u,media_type:"image",media_thumbnail_url:d,media_path:_,media_thumbnail_path:p,folder:s,private:a.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:u}),e.push({media_name:i.replace(/ /g,"-"),media_url:u,media_thumbnail_url:d})}elseif(o?.match(/file/i)){let{fileBase64:r,fileSize:i,fileType:o}=a,l=a.fileName.replace(/ /g,"-").replace(/\./g,""),u=(0,_.A)({isPrivate:a.private,userId:t.id,folder:s});if(!u)continue;let{fileRootPath:d,urlRootPath:m,relativePath:p}=u,f=o?.match(/pdf/)?".pdf":o?.match(/xlsx/)?".xlsx":o?.match(/csv/)?".csv":o?.match(/json/)?".json":null;if(!f)continue;leth=d+l+f,S=m+l+f,g=p+l+f;n().writeFileSync(h,r,"base64"),await(0,c.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:t.id,media_name:l,media_url:S,media_thumbnail_url:S,media_path:g,media_thumbnail_path:g,media_type:"file/"+f.replace(/\./,""),folder:s,private:a.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:S}),e.push({media_name:l,media_url:S,media_thumbnail_url:S})}elseif(o?.match(/video/i)){let{fileBase64:r,fileSize:i,fileType:o}=a,l=a.fileName.replace(/ /g,"-").replace(/\./g,""),u=(0,_.A)({isPrivate:a.private,userId:t.id,folder:s,video:!0});if(!u)continue;let{fileRootPath:d,urlRootPath:m,relativePath:p}=u,f=o?.match(/mp4/)?".mp4":null;if(!f)continue;leth=d+l+f,S=m+l+f,g=p+l+f;n().writeFileSync(h,r,"base64"),await(0,c.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:t.id,media_name:l,media_url:S,media_thumbnail_url:S,media_path:g,media_thumbnail_path:g,media_type:"video/"+f.replace(/\./,""),folder:s,private:a.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:S}),e.push({media_name:l,media_url:S,media_thumbnail_url:S})}}r.json({success:!0,mediaData:e})}catch(e){console.log(`Add User Media Error: ${e.message}`),(0,p.A)({component:"/api/addUserMedia/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}}letg=(0,o.M)(a,"default"),v=(0,o.M)(a,"config"),E=newi.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addUserMedia",pathname:"/api/addUserMedia",bundlePath:"",filename:""},userland:a})},96551:(e,r,t)=>{t.d(r,{A:()=>l});vara=t(9288