feat: history browse diffs
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
@@ -265,7 +265,7 @@ module.exports = {
|
||||
let self = this
|
||||
let gitFilePath = entryPath + '.md'
|
||||
|
||||
return self._git.exec('log', ['-n', '25', '--format=format:%H %h %cI %cE %cN', '--', gitFilePath]).then((cProc) => {
|
||||
return self._git.exec('log', ['--max-count=25', '--skip=1', '--format=format:%H %h %cI %cE %cN', '--', gitFilePath]).then((cProc) => {
|
||||
let out = cProc.stdout.toString()
|
||||
if (_.includes(out, 'fatal')) {
|
||||
let errorMsg = _.capitalize(_.head(_.split(_.replace(out, 'fatal: ', ''), ',')))
|
||||
@@ -286,6 +286,24 @@ module.exports = {
|
||||
}).value()
|
||||
return hist
|
||||
})
|
||||
},
|
||||
|
||||
getHistoryDiff(path, commit, comparewith) {
|
||||
let self = this
|
||||
if (!comparewith) {
|
||||
comparewith = 'HEAD'
|
||||
}
|
||||
|
||||
return self._git.exec('diff', ['--no-color', `${commit}:${path}.md`, `${comparewith}:${path}.md`]).then((cProc) => {
|
||||
let out = cProc.stdout.toString()
|
||||
if (_.startsWith(out, 'fatal: ')) {
|
||||
throw new Error(out)
|
||||
} else if (!_.includes(out, 'diff')) {
|
||||
throw new Error('Unable to query diff data.')
|
||||
} else {
|
||||
return out
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -45,6 +45,16 @@
|
||||
"videosupportedtitle": "The following are supported:",
|
||||
"videotitle": "Insert Video"
|
||||
},
|
||||
"history": {
|
||||
"pastversions": "Past Versions",
|
||||
"timestamp": "Timestamp",
|
||||
"author": "Author",
|
||||
"commit": "Commit",
|
||||
"comparewith": "Compare With...",
|
||||
"view": "View",
|
||||
"reverttoversion": "Revert to Version",
|
||||
"sidebyside": "Side-by-side View"
|
||||
},
|
||||
"modal": {
|
||||
"abort": "Abort",
|
||||
"anchorerror": "Clipboard copy failed. Copy the URL manually.",
|
||||
@@ -103,4 +113,4 @@
|
||||
"placeholder": "Search...",
|
||||
"results": "Search Results"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user