This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bibConverter.js
95 lines (71 loc) · 2.53 KB
/
bibConverter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var express =require('express');
var bibtex =require('bibtex');
var bodyParser=require('body-parser');
var request=require('request');
var path = require('path');
var a=express();
var bibtexParse = require('bibtex-parse-js');
var fs= require('fs');
var multer = require('multer');
const upload = multer({ dest: './uploads/' });
//var multerupload = multer({ dest: 'fileprint/' })
a.use(bodyParser.urlencoded({ extended: true }));
a.use(bodyParser.json());
/*var sample = bibtexParse.toJSON(`
@InProceedings{mut2011,
author = {Pradeep Muthukrishnan and Dragomir Radev and Qiaozhu Mei},
title = {Simultaneous Similarity Learning and Feature-Weight Learning for Document Clustering},
booktitle = {Proceedings of TextGraphs-6: Graph-based Methods for Natural Language Processing},
month = {June},
year = {2011},
address = {Portland, Oregon},
publisher = {Association for Computational Linguistics},
url = {http://www.aclweb.org/anthology/W11-1107},
pages = {42--50}
}
`);
*/
a.get("/convert",function(req,res){
res.send("hello");
console.log("Got you");
console.log(sample);
const bibFile = bibtex.parseBibFile(`
@InProceedings{mut2011,
author = {Pradeep Muthukrishnan and Dragomir Radev and Qiaozhu Mei},
title = {Simultaneous Similarity Learning and Feature-Weight Learning for Document Clustering},
booktitle = {Proceedings of TextGraphs-6: Graph-based Methods for Natural Language Processing},
month = {June},
year = {2011},
address = {Portland, Oregon},
publisher = {Association for Computational Linguistics},
url = {http://www.aclweb.org/anthology/W11-1107},
pages = {42--50}
}
`);
console.log(
// Keys are case-insensitive
bibFile.getEntry("MUT2011").getField("TITLE")
);
});
a.post('/convertbib', upload.single('myFile'), (req, res) => {
if (req.file) {
console.log('Uploading file...');
var filename = req.file.filename;
var uploadStatus = 'File Uploaded Successfully';
} else {
console.log('No File Uploaded');
var filename = 'FILE NOT UPLOADED';
var uploadStatus = 'File Upload Failed';
}
// res.send(req.file.path);
var data = fs.readFileSync(req.file.path, 'utf8');
console.log(data);
var sample = bibtexParse.toJSON(data);
console.log(sample);
res.send(sample);
/* ===== Add the function to save filename to database ===== */
// res.render('index.hbs', { status: uploadStatus, filename: `Name Of File: ${filename}` });
});
a.listen(3000,function(){
console.log("server initiated");
});