...
 
Commits (13)
const app = require('express')();
const bodyParser = require('body-parser');
const proxy = require('express-http-proxy');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
......@@ -19,6 +20,64 @@ app.use(bodyParser.json());
*/
app.use('/api/v1/ping', require('./ping'));
/**
* @api {get} /api/v1/project/:project_id/articles List articles
* @apiVersion 1.0.0
* @apiDescription List all articles for the specified project.
* @apiName List articles
* @apiGroup Article
*
* @apiSuccess {String} id ID of the file
* @apiSuccess {String} name Name of the file
* @apiSuccess {String} type Type of the file
* @apiSuccess {String} path Path of the file
* @apiSuccess {String} mode Mode of the file
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* [
* {
* "id": "fc798eff13af1df4a91dc14d26b22c95a90e717d",
* "name": "Article_1.md",
* "type": "blob",
* "path": "Article_1.md",
* "mode": "100644"
* }
* ]
*/
app.get('/api/v1/project/:project_id/articles', proxy('localhost:8000', {
proxyReqPathResolver: (req) => {
return '/admin/api/v4/projects/' + req.params.project_id + '/repository/tree'
},
userResDecorator: (proxyRes, proxyResData, userRaq, userReq) => {
var data = JSON.parse(proxyResData.toString('utf8'));
data = data.filter((e) => e.name.endsWith('.md'));
return JSON.stringify(data);
}
}));
/**
* @api {get} /project/:project_id/:branch/:file_path An article
* @apiVersion 1.0.0
* @apiDescription Render a specific article for the specified project
* @apiName An article
* @apiGroup Utils
*
* @apiSuccess {String} text of file
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* [
* Ceci est le premier article.
* ]
*/
app.get('/api/v1/project/:project_id/:ref/:file_path', proxy('localhost:8000', {
proxyReqPathResolver: (req) => {
console.log('/admin/api/v4/projects/' + req.params.project_id + '/repository/files/' + req.params.file_path + '?re/raw=' + req.params.ref);
return '/admin/api/v4/projects/' + req.params.project_id + '/repository/files/' + req.params.file_path + '/raw?ref=' + req.params.ref
}
}));
app.listen(3001, () => {
console.log('API server listening on port 3001');
});