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

1 line
5.8 KiB
JavaScript
Raw Normal View History

2024-12-09 09:39:09 +00:00
"use strict";(()=>{var e={};e.id=2678,e.ids=[2678],e.modules={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:()=>f,default:()=>S,routeModule:()=>E});var s={};t.r(s),t.d(s,{default:()=>m});var i=t(89947),a=t(2706),n=t(96762),o=t(51348),c=t.n(o),u=t(6420),l=t.n(u),d=t(33873),_=t.n(d);let p=t(29021);async function m(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=e.body;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=_().join(n,"images"),u=`${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,m=e?`${o}/user-images/user-${t.id}`:`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media`;if(!p.existsSync(m))try{p.mkdirSync(m,{recursive:!0})}catch(e){console.log("LINE 88 error:",e.message)}a&&a.split("/").reduce((e,r)=>{let t=e?.match(/./)?`${e}/${r}`:m;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],E=S.split(".")[1],v=e?`${u}${a?a+"/":"/"}${S}`:`@/media${a?a+"/":"/"}${S}`,h=e?`${l}${a?a+"/":"/"}${S}`:`@/media${a?a+"/":"/"}${S}`,$=m+a+"/"+S;p.copyFileSync(d,$),p.unlinkSync(d);let P=f+"_thumbnail."+E,g=d.replace(S,P),D=e?`${u}${a?a+"/":"/"}${P}`:`@/media${a?a+"/":"/"}${P}`,y=e?`${l}${a?a+"/":"/"}${P}`:`@/media${a?a+"/":"/"}${P}`;try{p.copyFileSync(g,m+a+"/"+P),p.unlinkSync(g)}catch(e){}await c()("UPDATE user_media SET private = ?, media_url= ?, media_thumbnail_url= ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[e?0:1,v,D,h,y,s.id]),r.json({success:!0,msg:"Success!"})}catch(e){console.log(e.message),r.json({success:!1,msg:"Error!",error:e})}}let S=(0,n.M)(s,"default"),f=(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(72835),a=t(29021),n=t(31341);async function o(e,r,t,o){let{keyCookieName:c,csrfCookieName:u}=n();if(!e.cookies?.[c]?.match(/./))return null;let l=i({encryptedString:e.cookies[c]});if(!l)return null;let d=JSON.parse(l);if(!d.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))return null;let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${_}/${d.csrf_k}`))return null;if(0==d.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}e.exports=o},31341:e=>{e.exports=function(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=r;e?.userId&&(i+=`user_${e.userId}_`),e?.database&&(i+=`${e.database}_`),i+=t;let a=r;return e?.userId&&(a+=`