16 lines
9.3 KiB
JavaScript
16 lines
9.3 KiB
JavaScript
"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")},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});var a={};t.r(a),t.d(a,{config:()=>h,default:()=>S});var i=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);let h={api:{responseLimit:"1mb",bodyParser:{sizeLimit:"200mb"}}};async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,f.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let a=e.body,{media:i}=a,s=a.folder,o=a.type;"production".match(/production/);let l=process.env.DSQL_STATIC_SERVER_DIR;if(!l)return console.log("Static File ENV not Found!"),r.json({success:!1,msg:"No Static File Path"});if(s){let e=d().join(l,`images/user-images/user-${t.id}/${s}`);n().existsSync(e)||n().mkdirSync(e,{recursive:!0});let r=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media/${s}`;n().existsSync(r)||n().mkdirSync(r,{recursive:!0})}try{let e=[];for(let r=0;r<i.length;r++){let a=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})}else if(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;let h=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})}else if(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;let h=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!"})}}let g=(0,o.M)(a,"default"),v=(0,o.M)(a,"config"),E=new i.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});var a=t(9288),i=t.n(a),s=t(67619),o=t(45185);async function l({imageSourceBase64:e,imageName:r,userId:t,mimeType:a,thumbnailSize:l,folder:n,isPrivate:u}){try{let s=Buffer.from(e,"base64"),d=l?parseInt(l.toString()):400,c=i()(s),m=i()(s),_=(0,o.A)({isPrivate:u,userId:t,folder:n});if(!_)return null;let{fileRootPath:p,urlRootPath:f,relativePath:h}=_,{width:S,height:g,format:v}=await c.metadata(),E=a||v;S&&g&&S>1800&&c.resize(1800,Math.round(1800/S*g),{fit:"cover"}),c.toFormat(E,{quality:80}),await c.metadata();let y=`${r}.${E}`;if(await c.toFile(p+y),S&&g&&S>d){let e=d/S;m.resize(d,Math.round(g*e),{fit:"cover"})}else S&&g&&m.resize(150,Math.round(150/S*g),{fit:"cover"});m.toFormat(E,{quality:80});let A=`${r}_thumbnail.${E}`;return await m.toFile(p+A),{urlPath:f+y,urlThumbnailPath:f+A,urlRelativePath:h+y,urlThumbnailRelativePath:h+A}}catch(e){return console.log("Write Image to Disk error =>",e.message),(0,s.A)({component:"functions/backend/fsWriteImageToDiskFromBase64",message:e.message}),null}}},45185:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(29021),i=t.n(a),s=t(33873),o=t.n(s);function l({isPrivate:e,userId:r,folder:t,video:a,pathOnly:s}){"production".match(/production/);let l=process.env.DSQL_STATIC_SERVER_DIR;if(!l)return console.log("Static File ENV not Found!"),null;let n=e?`@/${a?"videos":"media"}/${t?t+"/":""}`:a?`/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+"/":""}`:o().join(l,n);return i().existsSync(u)||s||i().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${n}`,relativePath:n}}},69842:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(48786),i=t(95969),s=t(29021),o=t.n(s),l=t(89159);async function n(e,r,t){try{let{keyCookieName:s,csrfCookieName:n}=(0,l.A)();if(!e.cookies?.[s]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,i.A)({encryptedString:e.cookies[s]});if(!u)throw Error("Couldn't decrypt auth cookie!");let d=JSON.parse(u);if(!d.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",d),Error("Deep Auth Failed. `csrf` key not found in request headers!");let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!o().existsSync(`${c}/${d.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==d.verification_status&&!t){let e=await (0,a.A)(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(d?.date&&Date.now()-d.date>6048e5)throw Error("Key expired!");return d}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",s=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),s&&(o+=`${s}_`),o+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),s&&(l+=`${s}_`),l+=a;let n=r;return e?.userId&&(n+=`user_${e.userId}_`),s&&(n+=`${s}_`),{keyCookieName:o,csrfCookieName:l,oneTimeCodeName:n+=i}}},67619:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(29021),i=t.n(a);async function s({user:e,message:r,component:t,noMail:a,req:s}){let o=new Date,l=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||a||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),s?.url&&(a+=`
|
|
URL: ${s.url}`),s?.body&&(a+=`
|
|
Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(a+=`
|
|
IP: ${l}`),a+=`
|
|
Date: ${o.toDateString()}
|
|
========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let n=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",a),i().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${n}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(55511),i=t(79428);function s({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let s=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=t||process.env.DSQL_ENCRYPTION_SALT,l=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(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let n=(0,a.scryptSync)(s,o,l),u=i.Buffer.alloc(16,0),d=(0,a.createDecipheriv)("aes-192-cbc",n,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 t=e=>r(r.s=e),a=r.X(0,[1251],()=>t(27973));module.exports=a})(); |