dsql-admin/dsql-app/.local_dist/server/pages/api/admin/docs/[action].js
Benjamin Toby 8b7ea057d0 Updates
2024-12-06 14:24:26 +01:00

1 line
5.4 KiB
JavaScript

"use strict";(()=>{var e={};e.id=2927,e.ids=[2927],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},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")},24296:(e,t,a)=>{a.r(t),a.d(t,{config:()=>N,default:()=>w,routeModule:()=>R});var r={};a.r(r),a.d(r,{default:()=>v});var s=a(89947),n=a(2706),o=a(96762),l=a(77509),i=a.n(l),d=a(73921),c=a.n(d),u=a(29131),p=a.n(u),_=a(30573),g=a.n(_),E=a(6983),f=a.n(E),y=a(46238),S=a.n(y),m=a(19131),h=a.n(m);async function v(e,t){if("POST"!==e.method)return t.json({success:!1,msg:"Wrong Method"});let a=await h()(e);if(!a?.logged_in_status)return t.json({success:!1,log:"Unauthorized"});let{action:r}=e.query,s=e.body;try{let e;switch(r){case"add-page":e=await i()({body:s});break;case"update-page":e=await i()({body:s,update:!0});break;case"delete-page":e=await c()({body:s});break;case"get-snippets":e=await p()();break;case"grab-parent-pages":e=await f()({body:s});break;case"get-child-pages":e=await g()({body:s});break;case"persist":e=await S()({body:s})}if(!e)throw Error("Operation failed!");t.json({success:!0,result:e})}catch(e){t.json({success:!1})}}let w=(0,o.M)(r,"default"),N=(0,o.M)(r,"config"),R=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/admin/docs/[action]",pathname:"/api/admin/docs/[action]",bundlePath:"",filename:""},userland:r})},77509:(e,t,a)=>{let r=a(72583),s=a(51348),n=a(47670),o=a(16570);e.exports=async function({body:e,update:t}){let a=e.title.toLowerCase().replace(/ /g,"-").replace(/[^a-z0-9\-]/g,""),l=await async function(){if(t)return null;try{return(await s("SELECT page_order FROM docs_pages ORDER BY page_order DESC LIMIT 1"))[0].page_order}catch(e){return null}}(),i=await n({data:{title:e.title,slug:a,description:r(e.description,o),content:r(e.content,o),text_content:e.text_content,level:e.level,page_order:t?e.page_order:parseInt(l)+1,parent_id:e?.parent_id},tableName:"docs_pages",update:t,duplicateColumnName:"id",duplicateColumnValue:e.id});return i?.insertId?i:t&&i.affectedRows?i:null}},73921:(e,t,a)=>{let r=a(51348);e.exports=async function({body:e}){return await r("DELETE FROM docs_pages WHERE id=?",[e.id])||null}},29131:(e,t,a)=>{let r=a(29021);e.exports=async function(){let e="./components/su/components/RichText/html-presets",t=[];return r.existsSync(e)&&r.readdirSync(e).forEach(a=>{if(a?.endsWith(".html")){let s={};s[a.replace(/\.html$/,"")]=r.readFileSync(`${e}/${a}`,"utf-8"),t.push({...s})}}),t}},30573:(e,t,a)=>{a(29021);let r=a(51348);e.exports=async function({body:e}){let t=await r("SELECT id, title, slug FROM docs_pages WHERE parent_id = ?",[e.pageId]);return t[0]?t:null}},6983:(e,t,a)=>{let r=a(51348);e.exports=async function({body:e}){return e?.currentPageId?await r("SELECT * FROM docs_pages WHERE level = ? AND id != ?",[e.pagesLevel,e.currentPageId]):await r("SELECT * FROM docs_pages WHERE level = ?",[e.pagesLevel])}},46238:(e,t,a)=>{let r=a(29021),s=a(51348);e.exports=async function({body:e}){let{pull:t}=e,a="./jsonData/docs.json";if(t)try{let e=JSON.parse(r.readFileSync(a,"utf-8"));for(let t=0;t<e.length;t++){let a=e[t],r=await s("SELECT id FROM docs_pages WHERE slug = ? AND level = ?",[a.slug,a.level]);if(r&&r[0]){let e={...a};delete e.date_created,delete e.date_created_code,delete e.date_created_timestamp,delete e.date_updated,delete e.date_updated_code,delete e.date_updated_timestamp,delete e.id,await s(`UPDATE docs_pages SET ? WHERE slug = '${a.slug}' AND level = '${a.level}'`,e)}else{let e={...a};delete e.date_created_timestamp,delete e.date_updated_timestamp,await s("INSERT INTO docs_pages SET ?",e)}}}catch(e){return null}else{let e=await s("SELECT * FROM docs_pages");r.writeFileSync(a,JSON.stringify(e,null,4),"utf-8")}return!0}},19131:(e,t,a)=>{let{IncomingMessage:r}=a(81630),s=a(72835),n=a(31341);e.exports=async function(e){let{keyCookieName:t,csrfCookieName:a}=n(),r=`${t}_su`;if(!e.cookies?.[r])return console.log("No auth key cookie found"),null;let o=s({encryptedString:e.cookies[r]});if(!o)return console.log("No user payload found"),null;let l=JSON.parse(o);return l.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):l.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):l}},31341:e=>{e.exports=function(){let e=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},72835:(e,t,a)=>{let{scryptSync:r,createDecipheriv:s}=a(55511),{Buffer:n}=a(79428);e.exports=({encryptedString:e,encryptionKey:t,encryptionSalt:a})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=t||process.env.DSQL_ENCRYPTION_PASSWORD,l=a||process.env.DSQL_ENCRYPTION_SALT,i=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=s("aes-192-cbc",r(o,l,i),n.alloc(16,0));try{let t=d.update(e,"hex","utf8");return t+=d.final("utf8")}catch(t){return console.log("Error in decrypting =>",t.message),e}}}};var t=require("../../../../webpack-api-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[4050],()=>a(24296));module.exports=r})();