dsql-admin/dsql-app/.local_dist/server/pages/api/media/addPrivateMedia.js

1 line
5.1 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=2678,e.ids=[2678],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},10304:(e,r,t)=>{t.r(r),t.d(r,{config:()=>h,default:()=>f,routeModule:()=>E});var s={};t.r(s),t.d(s,{default:()=>S});var i=t(89947),a=t(2706),n=t(96762),o=t(51348),u=t.n(o),c=t(6420),l=t.n(c),d=t(33873),m=t.n(d);let p=t(29021),_=t(28187);async function S(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});let t=await l()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=_.sanitizeSql(e.body,null);if(s.media_url?.match(/\.\./)||s.folder?.match(/\.\./)||s.id?.toString()?.match(/\.\./))return r.json({success:!1,msg:"Error!",error:"Invalid url"});try{let e=s?.private==1,i=e?s?.media_path?.replace(/\@\/media/i,"")||s?.media_url.replace(/\@\/media/i,""):s?.media_path?.match(/\/user-images\/user-.*/)||s?.media_url?.match(/\/user-images\/user-.*/),a=s.folder?`/${s.folder}`:"",n=process.env.DSQL_STATIC_SERVER_DIR;if(!n)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let o=m().join(n,"images"),c=`${process.env.DSQL_STATIC_HOST}/images/user-images/user-${t.id}`,l=`/images/user-images/user-${t.id}`,d=(e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media`:o)+i,_=e?`${o}/user-images/user-${t.id}`:`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media`;if(!p.existsSync(_))try{p.mkdirSync(_,{recursive:!0})}catch(e){console.log("LINE 88 error:",e.message)}a&&a.split("/").reduce((e,r)=>{let t=e?.match(/./)?`${e}/${r}`:_;return p.existsSync(t)||p.mkdirSync(t,{recursive:!0}),t},"");let S=d?.match(/[^\/]+$/)?.[0];if(!S)throw Error("No File Name Detected!");let f=S.split(".")[0],h=S.split(".")[1],E=e?`${c}${a?a+"/":"/"}${S}`:`@/media${a?a+"/":"/"}${S}`,$=e?`${l}${a?a+"/":"/"}${S}`:`@/media${a?a+"/":"/"}${S}`;p.copyFileSync(d,_+a+"/"+S),p.unlinkSync(d);let P=f+"_thumbnail."+h,v=d.replace(S,P),A=e?`${c}${a?a+"/":"/"}${P}`:`@/media${a?a+"/":"/"}${P}`,g=e?`${l}${a?a+"/":"/"}${P}`:`@/media${a?a+"/":"/"}${P}`;try{p.copyFileSync(v,_+a+"/"+P),p.unlinkSync(v)}catch(e){}await u()("UPDATE user_media SET private = ?, media_url= ?, media_thumbnail_url= ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[e?0:1,E,A,$,g,s.id]),r.json({success:!0,msg:"Success!"})}catch(e){console.log(e.message),r.json({success:!1,msg:"Error!",error:e})}}let f=(0,n.M)(s,"default"),h=(0,n.M)(s,"config"),E=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/media/addPrivateMedia",pathname:"/api/media/addPrivateMedia",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),i=t(72907),a=t(29021);async function n(e,r,t,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=i(e.cookies.datasquirelAuthKey);if(!o)return null;let u=JSON.parse(o);if(!u.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=n},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:i}=t(55511),{Buffer:a}=t(79428);e.exports=e=>{let r=i("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let t=r.updat