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

1 line
5.9 KiB
JavaScript
Raw Normal View History

2024-12-09 12:27:08 +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,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},10304:(e,r,s)=>{s.r(r),s.d(r,{config:()=>f,default:()=>m,routeModule:()=>E});var t={};s.r(t),s.d(t,{default:()=>S});var i=s(89947),n=s(2706),a=s(96762),o=s(51348),c=s.n(o),u=s(6420),l=s.n(u),d=s(33873),_=s.n(d);let p=s(29021);async function S(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});let s=await l()(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=e.body;if(t.media_url?.match(/\.\./)||t.folder?.match(/\.\./)||t.id?.toString()?.match(/\.\./))return r.json({success:!1,msg:"Error!",error:"Invalid url"});try{let e=t?.private==1,i=e?t?.media_path?.replace(/\@\/media/i,"")||t?.media_url.replace(/\@\/media/i,""):t?.media_path?.match(/\/user-images\/user-.*/)||t?.media_url?.match(/\/user-images\/user-.*/),n=t.folder?`/${t.folder}`:"",a=process.env.DSQL_STATIC_SERVER_DIR;if(!a)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let o=_().join(a,"images"),u=`${process.env.DSQL_STATIC_HOST}/images/user-images/user-${s.id}`,l=`/images/user-images/user-${s.id}`,d=(e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/media`:o)+i,S=e?`${o}/user-images/user-${s.id}`:`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/media`;if(!p.existsSync(S))try{p.mkdirSync(S,{recursive:!0})}catch(e){console.log("LINE 88 error:",e.message)}n&&n.split("/").reduce((e,r)=>{let s=e?.match(/./)?`${e}/${r}`:S;return p.existsSync(s)||p.mkdirSync(s,{recursive:!0}),s},"");let m=d?.match(/[^\/]+$/)?.[0];if(!m)throw Error("No File Name Detected!");let f=m.split(".")[0],E=m.split(".")[1],v=e?`${u}${n?n+"/":"/"}${m}`:`@/media${n?n+"/":"/"}${m}`,h=e?`${l}${n?n+"/":"/"}${m}`:`@/media${n?n+"/":"/"}${m}`,$=S+n+"/"+m;p.copyFileSync(d,$),p.unlinkSync(d);let P=f+"_thumbnail."+E,g=d.replace(m,P),D=e?`${u}${n?n+"/":"/"}${P}`:`@/media${n?n+"/":"/"}${P}`,A=e?`${l}${n?n+"/":"/"}${P}`:`@/media${n?n+"/":"/"}${P}`;try{p.copyFileSync(g,S+n+"/"+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,A,t.id]),r.json({success:!0,msg:"Success!"})}catch(e){console.log(e.message),r.json({success:!1,msg:"Error!",error:e})}}let m=(0,a.M)(t,"default"),f=(0,a.M)(t,"config"),E=new i.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/media/addPrivateMedia",pathname:"/api/media/addPrivateMedia",bundlePath:"",filename:""},userland:t})},6420:(e,r,s)=>{s(81630);let t=s(51348),i=s(72835),n=s(29021),a=s(31341);async function o(e,r,s,o){let{keyCookieName:c,csrfCookieName:u}=a();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||s&&!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(s&&!n.existsSync(`${_}/${d.csrf_k}`))return null;if(0==d.verification_status&&!s){let e=await t(`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_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=r;e?.userId&&(n+=`user_${e.user