dsql-admin/dsql-app/.local_dist/server/pages/api/getDiskUsage.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

22 lines
7.0 KiB
JavaScript

"use strict";(()=>{var e={};e.id=2139,e.ids=[2139],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}}})},53662:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>p,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>E});var o=t(89947),n=t(2706),i=t(96762),a=t(29021),c=t.n(a),l=t(33873),u=t.n(l),d=t(48786),_=t(67619),f=t(69842);async function E(e,r){if("GET"!==e.method)return r.json({msg:"Failed!"});let t=await (0,f.A)(e,r);if(!t)return r.json({success:!1,msg:"Unauthorized"});try{"production".match(/production/);let e=await (0,d.A)(`
SELECT table_schema,
SUM((data_length+index_length)/1024/1024) AS "mb" from
information_schema.tables
where table_schema like ?
group by table_schema
`,[`datasquirel_user_${t.id}%`]),o=(Array.isArray(e)?e:[]).reduce((e,r,t)=>e?.mb?e.mb+r.mb:e+r.mb,0),n=0,i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)throw console.log("Static File ENV not Found!"),Error("No Static Path!");i||c().existsSync(i)||c().mkdirSync(i,{recursive:!0});let a=u().join(i,`images/user-images/user-${t.id}`);c().existsSync(a)||c().mkdirSync(a,{recursive:!0});let l=u().join(i,`images/user-images/user-${t.id}`),f=u().join(i,`videos/user-videos/user-${t.id}`);async function s(e){try{let r=c().readdirSync(e);for(let t=0;t<r.length;t++){let o=r[t],a=e+"/"+o;if(!o.match(/\..{3,4}$/)){await s(a);continue}if(c().existsSync(a)){let e=c().statSync(a);n+=e.size/1024/1024}else{if("production".match(/production/),!i)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let e=a.replace(i,process.env.DSQL_STATIC_HOST||""),r=a.replace(i,"");await (0,d.A)("DELETE FROM user_media WHERE media_path = ? OR media_thumbnail_path = ? OR media_url=? OR media_thumbnail_url=?",[r,r,e,e]),console.log(`MEDIA => ${e} DELETED FROM DATABASE`)}}}catch(e){console.log("ERROR in getDiskUsage API route =>",e.message),(0,_.A)({component:"/api/getDiskUsage/lines-93-101",message:e.message})}}c().existsSync(f)||c().mkdirSync(f,{recursive:!0}),await s(l),await s(f);let E=n+o;r.json({success:!0,total:E})}catch(e){(0,_.A)({component:"/api/getDiskUsage/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Disk Usage Calculation Error!"})}}let p=(0,i.M)(s,"default"),m=(0,i.M)(s,"config"),S=new o.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/getDiskUsage",pathname:"/api/getDiskUsage",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>c});var s=t(48786),o=t(95969),n=t(29021),i=t.n(n),a=t(89159);async function c(e,r,t){try{let{keyCookieName:n,csrfCookieName:c}=(0,a.A)();if(!e.cookies?.[n]?.match(/./))throw Error("Request Cookies not Found!");let l=(0,o.A)({encryptedString:e.cookies[n]});if(!l)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(l);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw console.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!i().existsSync(`${d}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(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",o=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+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),n&&(i+=`${n}_`),i+=t;let a=r;e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),a+=s;let c=r;return e?.userId&&(c+=`user_${e.userId}_`),n&&(c+=`${n}_`),{keyCookieName:i,csrfCookieName:a,oneTimeCodeName:c+=o}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(29021),o=t.n(s);async function n({user:e,message:r,component:t,noMail:s,req:n}){let i=new Date,a=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],o=t||s||r||n.socket.remoteAddress;if(!o)return null;return String(o)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),n?.url&&(s+=`
URL: ${n.url}`),n?.body&&(s+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),a&&(s+=`
IP: ${a}`),s+=`
Date: ${i.toDateString()}
========================================`,o().existsSync("./.tmp/error.log")||o().writeFileSync("./.tmp/error.log","","utf-8");let c=o().readFileSync("./.tmp/error.log","utf-8");o().writeFileSync("./.tmp/error.log",s),o().appendFileSync("./.tmp/error.log",`
${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(55511),o=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,i=t||process.env.DSQL_ENCRYPTION_SALT,a=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(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=(0,s.scryptSync)(n,i,a),l=o.Buffer.alloc(16,0),u=(0,s.createDecipheriv)("aes-192-cbc",c,l);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...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=53662);module.exports=t})();