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

1 line
5.6 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +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")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},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}}})},38887:(e,r,t)=>{t.r(r),t.d(r,{config:()=>p,default:()=>m,routeModule:()=>f});var i={};t.r(i),t.d(i,{default:()=>_});var s=t(89947),n=t(2706),a=t(96762),o=t(48786),c=t(69842),u=t(33873),l=t.n(u);let d=t(29021);async function _(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});let t=await (0,c.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let i=e.body;if(i.media_url?.match(/\.\./)||i.folder?.match(/\.\./)||i.id?.toString()?.match(/\.\./))return r.json({success:!1,msg:"Error!",error:"Invalid url"});try{let e=i?.private==1,s=e?i?.media_path?.replace(/\@\/media/i,"")||i?.media_url.replace(/\@\/media/i,""):i?.media_path?.match(/\/user-images\/user-.*/)||i?.media_url?.match(/\/user-images\/user-.*/),n=i.folder?`/${i.folder}`:"",a=process.env.DSQL_STATIC_SERVER_DIR;if(!a)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let c=l().join(a,"images"),u=`${process.env.DSQL_STATIC_HOST}/images/user-images/user-${t.id}`,_=`/images/user-images/user-${t.id}`,m=(e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media`:c)+s,p=e?`${c}/user-images/user-${t.id}`:`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/media`;if(!d.existsSync(p))try{d.mkdirSync(p,{recursive:!0})}catch(e){console.log("LINE 88 error:",e.message)}n&&n.split("/").reduce((e,r)=>{let t=e?.match(/./)?`${e}/${r}`:p;return d.existsSync(t)||d.mkdirSync(t,{recursive:!0}),t},"");let f=m?.match(/[^\/]+$/)?.[0];if(!f)throw Error("No File Name Detected!");let S=f.split(".")[0],E=f.split(".")[1],A=e?`${u}${n?n+"/":"/"}${f}`:`@/media${n?n+"/":"/"}${f}`,v=e?`${_}${n?n+"/":"/"}${f}`:`@/media${n?n+"/":"/"}${f}`,$=p+n+"/"+f;d.copyFileSync(m,$),d.unlinkSync(m);let h=S+"_thumbnail."+E,g=m.replace(f,h),P=e?`${u}${n?n+"/":"/"}${h}`:`@/media${n?n+"/":"/"}${h}`,y=e?`${_}${n?n+"/":"/"}${h}`:`@/media${n?n+"/":"/"}${h}`;try{d.copyFileSync(g,p+n+"/"+h),d.unlinkSync(g)}catch(e){}await (0,o.A)("UPDATE user_media SET private = ?, media_url= ?, media_thumbnail_url= ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[e?0:1,A,P,v,y,i.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)(i,"default"),p=(0,a.M)(i,"config"),f=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/media/addPrivateMedia",pathname:"/api/media/addPrivateMedia",bundlePath:"",filename:""},userland:i})},69842:(e,r,t)=>{t.d(r,{A:()=>c});var i=t(48786),s=t(95969),n=t(29021),a=t.n(n),o=t(89159);async function c(e,r,t){let{keyCookieName:n,csrfCookieName:c}=(0,o.A)();if(!e.cookies?.[n]?.match(/./))return null;let u=(0,s.A)({encryptedString:e.cookies[n]});if(!u)return null;let l=JSON.parse(u);if(!l.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a().existsSync(`${d}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await (0,i.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}},89159:(e,r,t)=>{t.d(r,{A:()=>i});function i(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",i=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_use