Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CorTeXDummy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Wiesing
CorTeXDummy
Commits
36d508a4
Commit
36d508a4
authored
Nov 2, 2015
by
Felix Schmoll
Browse files
Options
Downloads
Patches
Plain Diff
Allow Cross reference requests
parent
c609f05c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.js
+4
-1
4 additions, 1 deletion
index.js
index.js~
+113
-0
113 additions, 0 deletions
index.js~
with
117 additions
and
1 deletion
index.js
+
4
−
1
View file @
36d508a4
...
...
@@ -26,6 +26,7 @@ app.use(bodyParser.urlencoded({
// serve only *.xhtml documents
app
.
use
(
'
/docs
'
,
function
(
req
,
res
,
next
){
res
.
set
(
'
Access-Control-Allow-Origin
'
,
'
http://localhost:3000
'
);
if
(
req
.
path
.
endsWith
(
'
.xhtml
'
)){
next
();
}
else
{
...
...
@@ -92,6 +93,8 @@ app.get('/get_task', function(req, res){
// get a mode
var
mode
=
[
'
annotate
'
,
'
review
'
][
Math
.
random
()
>
0.5
?
0
:
1
]
res
.
set
(
'
Access-Control-Allow-Origin
'
,
'
http://localhost:3000
'
);
// TODO: Serve a proper document and result
res
.
jsonp
({
'
id
'
:
jobname
,
// a job id. Should be posted as a job id to the result page.
...
...
@@ -106,7 +109,7 @@ app.get('/get_task', function(req, res){
var
server
=
http
.
Server
(
app
);
var
port
=
3
000
||
process
.
env
.
port
;
var
port
=
4
000
||
process
.
env
.
port
;
server
.
listen
(
port
,
function
(){
console
.
log
(
'
CorTeXDummy listening at
'
+
port
);
...
...
This diff is collapsed.
Click to expand it.
index.js~
0 → 100644
+
113
−
0
View file @
36d508a4
// import some modules
var bodyParser = require("body-parser"),
express = require('express'),
http = require('http'),
fs = require("fs"),
path = require("path");
require("string.prototype.endswith");
// counter and prefix for jobs
var job_counter = 0;
var job_prefix = (new Date()).getTime();
var jobs = [];
// get the path for the docs and the dumps
var pathDocs = path.resolve(__dirname+'/docs');
var pathDumps = path.resolve(__dirname+'/dumps');
// Create a really simple API
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
// serve only *.xhtml documents
app.use('/docs', function(req, res, next){
if(req.path.endsWith('.xhtml')){
next();
} else {
res.status(404).send('Not found');
}
}, express.static('docs/'));
app.post('/dumps/', function(req, res, next){
// read post data from the body
var post_data = req.body || {};
var id, doc;
if(!post_data.hasOwnProperty('id')){
return res.jsonp({'success': false, 'message': "Missing 'id' parameter. "});
} else {
id = post_data.id;
}
if(jobs.indexOf(id) === -1){
return res.jsonp({'success': false, 'message': "Unknown JOB id. "})
}
if(!post_data.hasOwnProperty('content')){
return res.jsonp({'success': false, 'message': "Missing 'content' parameter. "});
} else {
content = post_data.content;
}
// remove this job from the jobs list
jobs.splice(jobs.indexOf(id));
try{
fs.writeFileSync(pathDumps + '/'+id+'.xhtml', content);
} catch(e) {
console.log(e);
return res.jsonp({'success': false, 'message': 'Unable to save file. '});
}
res.jsonp({
'success': true,
'path': '/dumps/'+id+'.xhtml'
});
});
app.use('/dumps', function(req, res, next){
if(req.path.endsWith('.xhtml')){
next();
} else {
res.status(404).send('Not found');
}
}, express.static('dumps/'));
app.get('/get_task', function(req, res){
// make a job id and name
var jobid = job_counter++;
var jobname = job_prefix+'_'+jobid
jobs.push(jobname);
// get a document
var documents = fs.readdirSync(pathDocs).filter(function(e,i){return e.endsWith('.xhtml');});
var doc = documents[jobid % documents.length];
// get a mode
var mode = ['annotate', 'review'][Math.random() > 0.5 ? 0 : 1]
// TODO: Serve a proper document and result
res.jsonp({
'id': jobname, // a job id. Should be posted as a job id to the result page.
'path': 'docs/'+doc, // the path to the document to annotate
'post': 'dumps/'+doc, // the path you want to post results to. Should contain a 'content' field with the document and a 'id' field with the job id
'mode': mode, // the mode. One of 'annotate', 'review'
'annotations': null, // might contain another path to existing annotations in the future
});
});
// TODO: Implement document dumping & re-reading
var server = http.Server(app);
var port = 3000 || process.env.port;
server.listen(port, function(){
console.log('CorTeXDummy listening at '+port);
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment