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

16 lines
9.0 KiB
JavaScript
Raw Normal View History

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