dsql-admin/dsql-app/.local_dist/server/pages/api/getDiskUsage.js

22 lines
6.9 KiB
JavaScript
Raw Normal View History

2025-01-14 07:24:54 +00:00
"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 i=t(89947),n=t(2706),o=t(96762),a=t(29021),c=t.n(a),u=t(33873),l=t.n(u),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)(`
2024-12-08 19:56:57 +00:00
SELECT table_schema,
SUM((data_length+index_length)/1024/1024) AS "mb" from
information_schema.tables
where table_schema like ?
group by table_schema
2025-01-14 07:24:54 +00:00
`,[`datasquirel_user_${t.id}%`]),i=(Array.isArray(e)?e:[]).reduce((e,r,t)=>e?.mb?e.mb+r.mb:e+r.mb,0),n=0,o=process.env.DSQL_STATIC_SERVER_DIR;if(!o)throw console.log("Static File ENV not Found!"),Error("No Static Path!");o||c().existsSync(o)||c().mkdirSync(o,{recursive:!0});let a=l().join(o,`images/user-images/user-${t.id}`);c().existsSync(a)||c().mkdirSync(a,{recursive:!0});let u=l().join(o,`images/user-images/user-${t.id}`),f=l().join(o,`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 i=r[t],a=e+"/"+i;if(!i.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/),!o)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let e=a.replace(o,process.env.DSQL_STATIC_HOST||""),r=a.replace(o,"");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(u),await s(f);let E=n+i;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,o.M)(s,"default"),m=(0,o.M)(s,"config"),S=new i.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),i=t(95969),n=t(29021),o=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 u=(0,i.A)({encryptedString:e.cookies[n]});if(!u)throw Error("Couldn't decrypt auth cookie!");let l=JSON.parse(u);if(!l.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))throw 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&&!o().existsSync(`${d}/${l.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==l.verification_status&&!t){let e=await (0,s.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"])}if(l?.date&&Date.now()-l.date>6048e5)throw Error("Key expired!");return l}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.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",i=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+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=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:o,csrfCookieName:a,oneTimeCodeName:c+=i}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(29021),i=t.n(s);async function n({user:e,message:r,component:t,noMail:s,req:n}){let o=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],i=t||s||r||n.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-13 08:00:21 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 06:19:19 +00:00
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+=`
2025-01-14 07:24:54 +00:00
Date: ${o.toDateString()}
========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let c=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",s),i().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 07:24:54 +00:00
${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(55511),i=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,o=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(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=(0,s.scryptSync)(n,o,a),u=i.Buffer.alloc(16,0),l=(0,s.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:()=>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})();