1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
"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("Invalid auth key"),null):o}},89159:(e,t,a)=>{a.d(t,{A:()=>r});function r(e){let t=process.env.DSQL_COOKIES_PREFIX||"dsql_",a=process.env.DSQL_COOKIES_KEY_NAME||"key",r=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),l=t;e?.userId&&(l+=`user_${e.userId}_`),n&&(l+=`${n}_`),l+=a;let o=t;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=r;let d=t;return e?.userId&&(d+=`user_${e.userId}_`),n&&(d+=`${n}_`),{keyCookieName:l,csrfCookieName:o,oneTimeCodeName:d+=s}}},95969:(e,t,a)=>{a.d(t,{A:()=>n});var r=a(55511),s=a(79428);function n({encryptedString:e,encryptionKey:t,encryptionSalt:a}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=t||process.env.DSQL_ENCRYPTION_PASSWORD,l=a||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,r.scryptSync)(n,l,o),i=s.Buffer.alloc(16,0),c=(0,r.createDecipheriv)("aes-192-cbc",d,i);try{let t=c.update(e,"hex","utf8");return t+=c.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,[1251],()=>a(40806));module.exports=r})(); |