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

16 lines
6.4 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=8103,e.ids=[8103],e.modules={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")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},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}}})},17499:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>$,routeModule:()=>y});var a={};t.r(a),t.d(a,{default:()=>E});var n=t(89947),s=t(2706),i=t(96762),o=t(6420),l=t.n(o),u=t(77538),c=t.n(u),d=t(51348),m=t.n(d);t(33873);var p=t(48227),_=t.n(p),f=t(27825),S=t.n(f);let h=t(29021);async function E(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await l()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let a=e.body.mediaObject,n=e.body.newName,s=e.body.newThumbnailName,i=e.body.replace;try{"production".match(/production/);let e=a.media_url.match(/\..{3,4}$/)[0],o=a?.private==1;if(!process.env.DSQL_STATIC_SERVER_DIR)throw console.log("Static File ENV not Found!"),Error("No Static Path!");let l=_()({isPrivate:o,user:t,folder:a.folder?a.folder+"/":"",video:!!a.media_type?.match(/video/i)});if(!l)throw Error("Couldn't grab paths!");let{fileRootPath:u,urlRootPath:c,relativePath:d}=l,p=`${u}${a.media_name}${e}`,f=`${u}${n}${e}`,E=`${u}${a.media_name}_thumbnail${e}`,$=`${u}${n}_thumbnail${e}`,g=new RegExp(S().escapeRegExp(`${a.media_name}`)),y=a.media_url.replace(g,n),P=a.media_url.replace(g,n+"_thumbnail"),v=a.media_path?a.media_path.replace(g,n):`${d}${n}`,R=a.media_thumbnail_path?a.media_thumbnail_path.replace(g,n):`${d}${s}`;if(h.existsSync(f)&&!i)return r.json({success:!1,msg:"File already exists"});h.renameSync(p,f);try{h.renameSync(E,$)}catch(e){}await m()("UPDATE user_media SET media_name = ?, media_url = ?, media_thumbnail_url = ?, media_path = ?, media_thumbnail_path = ? WHERE id = ?",[n,y,P,v,R,a.id]),r.json({success:!0})}catch(e){console.log("Error in renaming media =>",e.message),c()({component:"/api/renameMedia/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Renaming failed. Please try again."})}}let $=(0,i.M)(a,"default"),g=(0,i.M)(a,"config"),y=new n.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/renameMedia",pathname:"/api/renameMedia",bundlePath:"",filename:""},userland:a})},48227:(e,r,t)=>{let a=t(29021),n=t(33873);e.exports=function({isPrivate:e,user:r,folder:t,video:s,pathOnly:i}){"production".match(/production/);let o=r?.id||r?.user_id,l=process.env.DSQL_STATIC_SERVER_DIR;if(!l)return console.log("Static File ENV not Found!"),null;let u=e?`@/${s?"videos":"media"}/${t?t+"/":""}`:s?`/videos/user-videos/user-${o}/${t?t+"/":""}`:`/images/user-images/user-${o}/${t?t+"/":""}`,c=e?`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${o}/media/${t?t+"/":""}`:n.join(l,u);return a.existsSync(c)||i||a.mkdirSync(c,{recursive:!0}),{fileRootPath:c,urlRootPath:e?`@/media/${t?t+"/":""}`:`${process.env.DSQL_STATIC_HOST}${u}`,relativePath:u}}},77538:(e,r,t)=>{let a=t(29021),{IncomingMessage:n}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:n,req:s}){let i=new Date,o=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||a||r||s.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
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}
User Email: ${e?.email}`),s?.url&&(n+=`
URL: ${s.url}`),s?.body&&(n+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),o&&(n+=`
IP: ${o}`),n+=`
Date: ${i.toDateString()}
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let l=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",n),a.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let a=t(51348),n=t(72907),s=t(29021);async function i(e,r,t,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=n(e.cookies.datasquirelAuthKey);if(!o)return null;let l=JSON.parse(o);if(!l.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!s.existsSync(`${u}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await 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}e.exports=i},72907:(e,r,t)=>{let{scryptSync:a,createDecipheriv:n}=t(55511),{Buffer:s}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),s.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},51348:(e,r,t)=>{let a=t(9973),n=t(21580),s=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:n()}});async function i(...e){try{let r=await s.query(...e);return await s.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,r,t)=>{let a=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!a.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:a.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=17499);module.exports=t})();