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

16 lines
7.0 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=8105,e.ids=[8105],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},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}}})},5134:(e,r,t)=>{t.r(r),t.d(r,{config:()=>D,default:()=>m,routeModule:()=>A});var n={};t.r(n),t.d(n,{default:()=>f});var s=t(89947),o=t(2706),a=t(96762),i=t(29021),l=t.n(i),u=t(33873),c=t.n(u),d=t(67619),S=t(69842),p=t(45185),_=t(61932);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,S.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let n=e.body,{media_name:s,media_url:o,media_thumbnail_url:a,media_path:i,media_thumbnail_path:u,folder:f}=n;"production".match(/production/);try{let e=n?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let s=(0,p.A)({isPrivate:e,userId:t.id,folder:n.folder?n.folder+"/":"",video:!!n.media_type?.match(/video/i)});if(!s)throw Error("Couldn't grab paths!");let{fileRootPath:i,urlRootPath:u,relativePath:d}=s;f?.match(/./);let S=o.match(/[^\/]+$/)[0],m=a.match(/[^\/]+$/)[0],D=c().normalize(i+S),A=c().normalize(i+m);l().unlinkSync(D);try{l().unlinkSync(A)}catch(e){}await (0,_.A)({dbFullName:"datasquirel",tableName:"user_media",identifierColumnName:"id",identifierValue:n.id}),r.json({success:!0})}catch(e){console.log("ERROR in deleting user media =>",e.message),(0,d.A)({component:"/api/deleteUserMedia/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}}let m=(0,a.M)(n,"default"),D=(0,a.M)(n,"config"),A=new s.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/deleteUserMedia",pathname:"/api/deleteUserMedia",bundlePath:"",filename:""},userland:n})},45185:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(29021),s=t.n(n),o=t(33873),a=t.n(o);function i({isPrivate:e,userId:r,folder:t,video:n,pathOnly:o}){"production".match(/production/);let i=process.env.DSQL_STATIC_SERVER_DIR;if(!i)return console.log("Static File ENV not Found!"),null;let l=e?`@/${n?"videos":"media"}/${t?t+"/":""}`:n?`/videos/user-videos/user-${r}/${t?t+"/":""}`:`/images/user-images/user-${r}/${t?t+"/":""}`,u=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${t?t+"/":""}`:a().join(i,l);return s().existsSync(u)||o||s().mkdirSync(u,{recursive:!0}),{fileRootPath:u,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${l}`,relativePath:l}}},69842:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(39908),s=t.n(n);async function o(e,r,t){let n=s()({req:e,level:t?"deep":void 0});return console.log(n),n.payload}},61932:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(48786),s=t(37897),o=t(62050);async function a({dbContext:e,paradigm:r,dbFullName:t,tableName:a,identifierColumnName:i,identifierValue:l,useLocal:u}){try{let c=!!u||!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),d=u?o.A:c?n.A:s.A,S=`DELETE FROM \`${t}\`.\`${a}\` WHERE \`${i}\`=?`;return c?await d(S,[l]):await d({paradigm:r,queryString:S,queryValues:[l]})}catch(e){return null}}},67619:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),s=t.n(n);async function o({user:e,message:r,component:t,noMail:n,req:o}){let a=new Date,i=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],t=o.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||o.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let n=`🚀 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&&(n+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),o?.url&&(n+=`
URL: ${o.url}`),o?.body&&(n+=`
2025-01-14 15:27:08 +00:00
Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(n+=`
IP: ${i}`),n+=`
Date: ${a.toDateString()}
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let l=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",n),s().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(7447);async function s(...e){let r=(0,n.A)();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()}}},37897:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(64292),s=t(7447);async function o({paradigm:e,queryString:r,queryValues:t}){let o="Read Only"==e?(0,s.A)({ro:!0}):(0,s.A)({fa:!0});try{return await (0,n.A)(o,r,t)}catch(e){return console.log(`DSQL_USER_DB_HANDLER Error: ${e.message}`),null}finally{o?.end()}}},62050:(e,r,t)=>{t.d(r,{A:()=>s});var n=t(7447);async function s(...e){let r=(0,n.A)();console.log("Querying ...");try{let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}finally{await r?.end()}}},64292:(e,r,t)=>{async function n(e,r,t){try{if("string"==typeof r){let n=await e.query(s(r),t);return JSON.parse(JSON.stringify(n))}if("object"!=typeof r)return null;{let t=[];for(let n=0;n<r.length;n++)try{let o=r[n],a=await e.query(s(o.query),o.values);t.push(JSON.parse(JSON.stringify(a)))}catch(e){t.push(null)}return t}}catch(e){return null}finally{e.end()}}function s(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>n})},7447:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(9973),s=t.n(n);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||s()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},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=5134);module.exports=t})();