mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 01:55:59 +00:00
markdown manifest
This commit is contained in:
@@ -3,16 +3,16 @@ const currentVersion = require('../currentVersion');
|
||||
module.exports = {
|
||||
get_meta: 'get',
|
||||
async get() {
|
||||
const toolbarButtons = process.env.TOOLBAR;
|
||||
const toolbar = toolbarButtons
|
||||
? toolbarButtons.split(',').map((name) => ({
|
||||
name,
|
||||
icon: process.env[`ICON_${name}`],
|
||||
title: process.env[`TITLE_${name}`],
|
||||
page: process.env[`PAGE_${name}`],
|
||||
}))
|
||||
: null;
|
||||
const startupPages = process.env.STARTUP_PAGES ? process.env.STARTUP_PAGES.split(',') : [];
|
||||
// const toolbarButtons = process.env.TOOLBAR;
|
||||
// const toolbar = toolbarButtons
|
||||
// ? toolbarButtons.split(',').map((name) => ({
|
||||
// name,
|
||||
// icon: process.env[`ICON_${name}`],
|
||||
// title: process.env[`TITLE_${name}`],
|
||||
// page: process.env[`PAGE_${name}`],
|
||||
// }))
|
||||
// : null;
|
||||
// const startupPages = process.env.STARTUP_PAGES ? process.env.STARTUP_PAGES.split(',') : [];
|
||||
const permissions = process.env.PERMISSIONS ? process.env.PERMISSIONS.split(',') : null;
|
||||
const singleDatabase =
|
||||
process.env.SINGLE_CONNECTION && process.env.SINGLE_DATABASE
|
||||
@@ -24,8 +24,8 @@ module.exports = {
|
||||
|
||||
return {
|
||||
runAsPortal: !!process.env.CONNECTIONS,
|
||||
toolbar,
|
||||
startupPages,
|
||||
// toolbar,
|
||||
// startupPages,
|
||||
singleDatabase,
|
||||
permissions,
|
||||
...currentVersion,
|
||||
|
||||
@@ -5,6 +5,10 @@ const hasPermission = require('../utility/hasPermission');
|
||||
const socket = require('../utility/socket');
|
||||
const scheduler = require('./scheduler');
|
||||
|
||||
const markdownAutorunRegex = /<\!--.*@autorun\s*(\n.*-->|-->)/s;
|
||||
const markdownButtonRegex = /<\!--.*@button\s+([^\n]+)(\n.*-->|-->)/s;
|
||||
const markdownIconRegex = /<\!--.*@icon\s+([^\n]+)(\n.*-->|-->)/s;
|
||||
|
||||
function serialize(format, data) {
|
||||
if (format == 'text') return data;
|
||||
if (format == 'json') return JSON.stringify(data);
|
||||
@@ -61,4 +65,29 @@ module.exports = {
|
||||
scheduler.reload();
|
||||
}
|
||||
},
|
||||
|
||||
markdownManifest_meta: 'get',
|
||||
async markdownManifest() {
|
||||
if (!hasPermission(`files/markdown/write`)) return {};
|
||||
const dir = path.join(filesdir(), 'markdown');
|
||||
if (!(await fs.exists(dir))) return {};
|
||||
const files = await fs.readdir(dir);
|
||||
const res = [];
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file);
|
||||
const text = await fs.readFile(filePath, { encoding: 'utf-8' });
|
||||
const autorun = text.match(markdownAutorunRegex);
|
||||
const button = text.match(markdownButtonRegex);
|
||||
const icon = text.match(markdownIconRegex);
|
||||
if (autorun || button) {
|
||||
res.push({
|
||||
file,
|
||||
autorun: !!autorun,
|
||||
button: button ? button[1].trim() : undefined,
|
||||
icon: icon ? icon[1].trim() : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user