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

16 lines
5.9 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=8103,e.ids=[8103],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},27825:e=>{e.exports=require("lodash")},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}}})},8639:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>D,routeModule:()=>A});var n={};t.r(n),t.d(n,{default:()=>S});var a=t(89947),o=t(2706),s=t(96762),i=t(29021),u=t.n(i),l=t(69842),c=t(67619),d=t(48786),_=t(45185),m=t(27825),p=t.n(m);async function S(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let n=e.body.mediaObject,a=e.body.newName,o=e.body.newThumbnailName,s=e.body.replace;try{"production".match(/production/);let e=n.media_url.match(/\..{3,4}$/)[0],i=n?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let l=(0,_.A)({isPrivate:i,userId:t.id,folder:n.folder?n.folder+"/":"",video:!!n.media_type?.match(/video/i)});if(!l)throw Error("Couldn't grab paths!");let{fileRootPath:c,urlRootPath:m,relativePath:S}=l,D=`${c}${n.media_name}${e}`,f=`${c}${a}${e}`,A=`${c}${n.media_name}_thumbnail${e}`,E=`${c}${a}_thumbnail${e}`,h=new RegExp(p().escapeRegExp(`${n.media_name}`)),v=n.media_url.replace(h,a),g=n.media_url.replace(h,a+"_thumbnail"),y=n.media_path?n.media_path.replace(h,a):`${S}${a}`,P=n.media_thumbnail_path?n.media_thumbnail_path.replace(h,a):`${S}${o}`;if(u().existsSync(f)&&!s)return r.json({success:!1,msg:"File already exists"});u().renameSync(D,f);try{u().renameSync(A,E)}catch(e){}await (0,d.A)("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[a,v,g,y,P,n.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),(0,c.A)({component:"/api/renameMedia/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let D=(0,s.M)(n,"default"),f=(0,s.M)(n,"config"),A=new a.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:n})},45185:(e,r,t)=>{t.d(r,{A:()=>i});var n=t(29021),a=t.n(n),o=t(33873),s=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 u=e?`@/${n?"videos":"media"}/${t?t+"/":""}`:n?`/videos/user-videos/user-${r}/${t?t+"/":""}`:`/images/user-images/user-${r}/${t?t+"/":""}`,l=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r}/media/${t?t+"/":""}`:s().join(i,u);return a().existsSync(l)||o||a().mkdirSync(l,{recursive:!0}),{fileRootPath:l,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${u}`,relativePath:u}}},69842:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(39908),a=t.n(n);async function o(e,r,t){let n=a()({req:e,level:t?"deep":void 0});return console.log(n),n.payload}},67619:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(29021),a=t.n(n);async function o({user:e,message:r,component:t,noMail:n,req:o}){let s=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],a=t||n||r||o.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 06:42:13 +00:00
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: ${s.toDateString()}
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let u=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",n),a().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,t)=>{t.d(r,{A:()=>a});var n=t(7447);async function a(...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()}}},7447:(e,r,t)=>{t.d(r,{A:()=>o});var n=t(9973),a=t.n(n);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||a()({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||a()({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||a()({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=8639);module.exports=t})();