dsql-admin/dsql-app/.local_dist/server/pages/api/addUserMedia.js

16 lines
7.1 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=979,e.ids=[979],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")},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,a,r)=>{r.r(a),r.d(a,{config:()=>S,default:()=>v,routeModule:()=>y});var i={};r.r(i),r.d(i,{config:()=>h,default:()=>g});var t=r(89947),l=r(2706),s=r(96762),n=r(29021),o=r.n(n),u=r(33873),d=r.n(u),m=r(98e3),c=r(96551),p=r(45185),_=r(67619),f=r(69842);let h={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};async function g(e,a){if("POST"!==e.method)return a.json({msg:"Failed!"});let r=await (0,f.A)(e,a,!0);if(!r)return a.json({success:!1,msg:"Unauthorized"});let i=e.body,{media:t}=i,l=i.folder,s=i.type;"production".match(/production/);let n=process.env.DSQL_STATIC_SERVER_DIR;if(!n)return console.log("Static File ENV not Found!"),a.json({success:!1,msg:"No Static File Path"});if(l){let e=d().join(n,`images/user-images/user-${r.id}/${l}`);o().existsSync(e)||o().mkdirSync(e,{recursive:!0});let a=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r.id}/media/${l}`;o().existsSync(a)||o().mkdirSync(a,{recursive:!0})}try{let e=[];for(let a=0;a<t.length;a++){let i=t[a];if(s?.match(/image/i)){let{imageBase64:a,imageName:t,imageSize:s,mimeType:n}=i,o=await (0,c.A)({imageName:t.replace(/ /g,"-").replace(/\.{1,}|\//g,""),imageSourceBase64:a,userId:r.id,folder:l,mimeType:n,isPrivate:i.private});if(!o){console.log("Image Write Failed!");continue}let{urlPath:u,urlThumbnailPath:d,urlRelativePath:p,urlThumbnailRelativePath:_}=o;await (0,m.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:r.id,media_name:t.replace(/ /g,"-"),media_url:u,media_type:"image",media_thumbnail_url:d,media_path:p,media_thumbnail_path:_,folder:l,private:i.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:u}),e.push({media_name:t.replace(/ /g,"-"),media_url:u,media_thumbnail_url:d})}else if(s?.match(/file/i)){let{fileBase64:a,fileSize:t,fileType:s}=i,n=i.fileName.replace(/ /g,"-").replace(/\./g,""),u=(0,p.A)({isPrivate:i.private,userId:r.id,folder:l});if(!u)continue;let{fileRootPath:d,urlRootPath:c,relativePath:_}=u,f=s?.match(/pdf/)?".pdf":s?.match(/xlsx/)?".xlsx":s?.match(/csv/)?".csv":s?.match(/json/)?".json":null;if(!f)continue;let h=d+n+f,g=c+n+f,v=_+n+f;o().writeFileSync(h,a,"base64"),await (0,m.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:r.id,media_name:n,media_url:g,media_thumbnail_url:g,media_path:v,media_thumbnail_path:v,media_type:"file/"+f.replace(/\./,""),folder:l,private:i.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:g}),e.push({media_name:n,media_url:g,media_thumbnail_url:g})}else if(s?.match(/video/i)){let{fileBase64:a,fileSize:t,fileType:s}=i,n=i.fileName.replace(/ /g,"-").replace(/\./g,""),u=(0,p.A)({isPrivate:i.private,userId:r.id,folder:l,video:!0});if(!u)continue;let{fileRootPath:d,urlRootPath:c,relativePath:_}=u,f=s?.match(/mp4/)?".mp4":null;if(!f)continue;let h=d+n+f,g=c+n+f,v=_+n+f;o().writeFileSync(h,a,"base64"),await (0,m.A)({dbFullName:"datasquirel",tableName:"user_media",data:{user_id:r.id,media_name:n,media_url:g,media_thumbnail_url:g,media_path:v,media_thumbnail_path:v,media_type:"video/"+f.replace(/\./,""),folder:l,private:i.private?1:0},duplicateColumnName:"media_url",duplicateColumnValue:g}),e.push({media_name:n,media_url:g,media_thumbnail_url:g})}}a.json({success:!0,mediaData:e})}catch(e){console.log(`Add User Media Error: ${e.message}`),(0,_.A)({component:"/api/addUserMedia/catch-error",message:e.message,user:r}),a.json({success:!1,msg:"Database Files could not be written!"})}}let v=(0,s.M)(i,"default"),S=(0,s.M)(i,"config"),y=new t.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserMedia",pathname:"/api/addUserMedia",bundlePa
Error Message: ${a}
Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 15:27:08 +00:00
User Email: ${e?.email}`),l?.url&&(i+=`
URL: ${l.url}`),l?.body&&(i+=`
Request Body: ${JSON.stringify(l.body,null,4)}`),n&&(i+=`
IP: ${n}`),i+=`
Date: ${s.toDateString()}
========================================`,t().existsSync("./.tmp/error.log")||t().writeFileSync("./.tmp/error.log","","utf-8");let o=t().readFileSync("./.tmp/error.log","utf-8");t().writeFileSync("./.tmp/error.log",i),t().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}}};var a=require("../../webpack-api-runtime.js");a.C(e);var r=e=>a(a.s=e),i=a.X(0,[1251],()=>r(27973));module.exports=i})();