feat: history browse diffs

This commit is contained in:
NGPixel
2017-07-06 00:10:41 -04:00
committed by Nicolas Giard
parent fa1f332057
commit 20a2e0e3ce
6 changed files with 93 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
'use strict'
/* global entries, lang, winston */
/* global entries, git, lang, winston */
const express = require('express')
const router = express.Router()
@@ -202,6 +202,25 @@ router.get('/hist/*', (req, res, next) => {
})
})
/**
* View history of a document
*/
router.post('/hist', (req, res, next) => {
let commit = req.body.commit
let safePath = entryHelper.parsePath(req.body.path)
if (!/^[a-f0-9]{40}$/.test(commit)) {
return res.status(400).json({ ok: false, error: 'Invalid commit' })
}
git.getHistoryDiff(safePath, commit).then((diff) => {
res.json({ ok: true, diff })
return true
}).catch((err) => {
res.status(500).json({ ok: false, error: err.message })
})
})
/**
* View document
*/