dsql-admin/dsql-app/.local_dist/server/pages/api/admin/docs/[action].js

1 line
5.5 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";(()=>{var e={};e.id=2927,e.ids=[2927],e.modules={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")},40806:(e,t,a)=>{a.r(t),a.d(t,{config:()=>h,default:()=>I,routeModule:()=>N});var r={};a.r(r),a.d(r,{default:()=>A});var s=a(89947),n=a(2706),l=a(96762),o=a(72583),d=a.n(o),i=a(48786),c=a(98e3),u=a(92652);async function p({body:e,update:t}){let a=e.title.toLowerCase().replace(/ /g,"-").replace(/[^a-z0-9\-]/g,""),r=await async function(){if(t)return null;try{return(await (0,i.A)("SELECT page_order FROM docs_pages ORDER BY page_order DESC LIMIT 1"))[0].page_order}catch(e){return null}}(),s=await (0,c.A)({data:{title:e.title,slug:a,description:d()(e.description,u.A),content:d()(e.content,u.A),text_content:e.text_content,level:e.level,page_order:t?e.page_order:parseInt(r)+1,parent_id:e?.parent_id},tableName:"docs_pages",update:t,duplicateColumnName:"id",duplicateColumnValue:e.id});return s?.insertId?s:t&&s.affectedRows?s:null}async function _({body:e}){return await (0,i.A)("DELETE FROM docs_pages WHERE id=?",[e.id])||null}var E=a(29021),g=a.n(E);async function f(){let e="./components/su/components/RichText/html-presets",t=[];return g().existsSync(e)&&g().readdirSync(e).forEach(a=>{if(a?.endsWith(".html")){let r={};r[a.replace(/\.html$/,"")]=g().readFileSync(`${e}/${a}`,"utf-8"),t.push({...r})}}),t}async function S({body:e}){let t=await (0,i.A)("SELECT id, title, slug FROM docs_pages WHERE parent_id = ?",[e.pageId]);return t[0]?t:null}async function y({body:e}){return e?.currentPageId?await (0,i.A)("SELECT * FROM docs_pages WHERE level = ? AND id != ?",[e.pagesLevel,e.currentPageId]):await (0,i.A)("SELECT * FROM docs_pages WHERE level = ?",[e.pagesLevel])}async function m({body:e}){let{pull:t}=e,a="./jsonData/docs.json";if(t)try{let e=JSON.parse(g().readFileSync(a,"utf-8"));for(let t=0;t<e.length;t++){let a=e[t],r=await (0,i.A)("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 (0,i.A)(`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 (0,i.A)("INSERT INTO docs_pages SET ?",e)}}}catch(e){return null}else{let e=await (0,i.A)("SELECT * FROM docs_pages");g().writeFileSync(a,JSON.stringify(e,null,4),"utf-8")}return!0}var v=a(87369);async function A(e,t){if("POST"!==e.method)return t.json({success:!1,msg:"Wrong Method"});let a=await (0,v.A)(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 p({body:s});break;case"update-page":e=await p({body:s,update:!0});break;case"delete-page":e=await _({body:s});break;case"get-snippets":e=await f();break;case"grab-parent-pages":e=await y({body:s});break;case"get-child-pages":e=await S({body:s});break;case"persist":e=await m({body:s})}if(!e)throw Error("Operation failed!");t.json({success:!0,result:e})}catch(e){t.json({success:!1})}}let I=(0,l.M)(r,"default"),h=(0,l.M)(r,"config"),N=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/admin/docs/[action]",pathname:"/api/admin/docs/[action]",bundlePath:"",filename:""},userland:r})},87369:(e,t,a)=>{a.d(t,{A:()=>n});var r=a(95969),s=a(89159);async function n(e){let{keyCookieName:t,csrfCookieName:a}=(0,s.A)(),n=`${t}_su`;if(!e.cookies?.[n])return console.log("No auth key cookie found"),null;let l=(0,r.A)({encryptedString:e.cookies[n]});if(!l)return console.log("No user payload found"),null;let o=JSON.parse(l);return o.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):o.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("In