dsql-admin/dsql-app/.local_dist/server/pages/api/media/addPrivateMedia.js
Benjamin Toby e0a030f10d Updates
2025-01-13 09:00:21 +01:00

1 line
5.6 KiB
JavaScript

"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_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),a+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=i;let c=r;return e?.userId&&(c+=`user_${e.userId}_`),n&&(c+=`${n}_`),{keyCookieName:a,csrfCookieName:o,oneTimeCodeName:c+=s}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var i=t(55511),s=t(79428);function n({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=(0,i.scryptSync)(n,a,o),u=s.Buffer.alloc(16,0),l=(0,i.createDecipheriv)("aes-192-cbc",c,u);try{let r=l.update(e,"hex","utf8");return r+=l.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>i});async function i(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=38887);module.exports=t})();