Skip to content

Commit 3482c33

Browse files
committed
Give access to previous version of static files though vcs app.
1 parent 056551e commit 3482c33

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

coder-apps/common/vcs/app/app.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
var pathutil = require('path');
2+
var fs = require('fs');
3+
var async = require('async');
4+
var Git = require('./git');
5+
var mime = require('mime');
6+
7+
var isVersionned = function(app, callback) {
8+
fs.fileExists(callback);
9+
};
110

211
exports.get_routes = [
312
{ path:'/', handler:'index_handler' },
13+
{ path:/^\/view\/(\w+)\/([0-9a-f]+)\/static\/(.+)$/, handler: 'static_handler' }
414
];
515

616
exports.post_routes = [
@@ -11,6 +21,38 @@ exports.index_handler = function( app, req, res ) {
1121
res.render( app.view() );
1222
};
1323

24+
exports.static_handler = function( app, req, res, match ) {
25+
var appname = match[1];
26+
var rev = match[2];
27+
var path = pathutil.resolve("/static", match[3]);
28+
29+
var repo;
30+
async.waterfall([
31+
coderlib.app.bind(null, appname),
32+
function(app, callback) {
33+
repo = new Git(app.rootPath);
34+
repo.parseCommit(rev, callback);
35+
},
36+
function(commit, callback) {
37+
repo.findBlob(commit.tree, path, callback);
38+
},
39+
function(blob, callback) {
40+
repo.cat_file(blob.object, blob.type, callback);
41+
}
42+
], function(err, data) {
43+
if (err)
44+
{
45+
console.log(err);
46+
res.send(404);
47+
}
48+
else
49+
{
50+
res.setHeader("Content-Type", mime.lookup(path));
51+
res.send(data);
52+
}
53+
});
54+
};
55+
1456
exports.on_destroy = function() {
1557
};
1658

coder-apps/common/vcs/app/meta.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"created": "2014-03-21",
3+
"modified": "2014-03-21",
4+
"color": "#80d4ea",
5+
"author": "Paul Lietar",
6+
"name": "VCS",
7+
"hidden": true,
8+
"public": false
9+
}
10+

coder-base/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"ncp": "0.5.*",
1818
"tmp": "0.0.23",
1919
"rimraf": "~2.2.6",
20-
"byline": "~4.1.1"
20+
"byline": "~4.1.1",
21+
"mime": "~1.2.11"
2122
}
2223
}

0 commit comments

Comments
 (0)