Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions server/api/RTEDemoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import { sortBy } from 'lodash';
const router = express.Router();

router.post('/get-demo-doc-content', (req, res) => {
const contentDir = path.join(__dirname, '../../../../../public/rte_contents/');
const contentDir = path.resolve(__dirname, '../../../public/rte_contents');
const docContentPath = path.resolve(contentDir, `${req.body.name}`);
if (!docContentPath.startsWith(contentDir)) {
res.send(null);
const relativeToContentDir = path.relative(contentDir, docContentPath);
if (relativeToContentDir.startsWith('..') || path.isAbsolute(relativeToContentDir)) {
return res.send(null);
}
if (!fs.existsSync(docContentPath)) {
res.send(null);
} else {
const content = JSON.parse(JSON.parse(fs.readFileSync(docContentPath, 'utf8')).content);
res.send(content);
return res.send(null);
}
const content = JSON.parse(JSON.parse(fs.readFileSync(docContentPath, 'utf8')).content);
return res.send(content);
});

router.get('/get-contents-list', (req, res) => {
const propsFilePath = path.join(__dirname, '../../public/rte_contents');
const propsFilePath = path.join(__dirname, '../../../public/rte_contents');
const contentsList = [];
fs.readdirSync(propsFilePath).forEach((file) => {
contentsList.push(file);
Expand Down
Loading