-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexCreator.js
108 lines (100 loc) · 3.17 KB
/
indexCreator.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
96
97
98
99
100
101
102
103
104
105
106
107
108
var mongodb = require('mongodb');
//var mongoserver = new mongodb.Server('10.112.0.110', 26374);
var mongoserver = new mongodb.Server('localhost', 26374);
var dbConnector = new mongodb.Db('uenergy', mongoserver);
var locs, cities, bottom;
require('fs').readFile(__dirname + '/files/html/indexhalf.html', function(error, content){
if(error){
console.log(error);
}
else{
bottom = content;
}
});
dbConnector.open(function(err, DB){
if(err){
console.log('oh shit! connector.open error!');
console.log(err.message);
}
else{
db = DB;
db.createCollection('cities', function(err, city){
if(err){
console.log('oh shit! db.createCollection error!');
console.log(err);
return;
}
cities = city;
locs = {};
cities.find({}).each(function(err,doc){
if(err)console.log('OH NO AN ERROR!!!'+err.message);
else if(doc){
db.createCollection(doc._id+'Locs',function(err,curloc){
if(err)console.log('oh shit erroooorrr!!! '+ err.message);
else
locs[doc._id] = curloc;
});
}
else
console.log('index creatorized');
});
});
}
});
function returnIndexL(url, res){
var splitURL = url.split('/');
locs['NYC'].findOne({'_id':splitURL[2]}, function(err,loc){
if(err) console.log('error finding loc: ' + err);
else if(loc){
if(splitURL[3] && loc.list){
for(var i = 0; i < loc.list.length; i++){
if(loc.list[i].RID == splitURL[3]){
returnPage(url, res, loc.title, loc.list[i].title,loc.type);
return;
}
}
returnPage(url, res, loc.title,null,loc.type);
}
else{
returnPage(url, res, loc.title,null,loc.type);
}
}
else console.log('nothing!');
});
}
function returnIndexA(url,res){
var splitURL = url.split('/');
locs['NYC'].findOne({'alternate':splitURL[2]}, function(err,loc){
if(err) console.log('error finding loc: ' + err);
else{
var newrl = 'http://localhost:8888/l/'+loc._id;
res.writeHead(302, {'location':newrl});
res.end();
}
});
}
function returnPage(url, res, locName, locSub,type){
var title=''; //facebook title
var ftype = 'video'; //facebook type
if(locSub){
title = locSub;
if(type = 'artist'){
title += ' by ';
ftype = 'song';
}
else title+= ' at ';
}
title+=locName;
var top = '<html> <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# rapcities: http://ogp.me/ns/fb/rapcities#">'
+'<meta property="fb:app_id" content="134659439991720" />'
+'<meta property="og:type" content="rapcities:'+ftype+'" />'
+'<meta property="og:url" content="http://localhost:8888'+url+'" />'
+'<meta property="og:title" content="'+title+ '" />'
+'<meta property="og:description" content="Broadcasting Hip-Hop 24/7 from a virtual city of music and culture." />'
+'<meta property="og:image" content="http://localhost:8888/fblogo.png" />'
+' <title>RapCities - '+title+'</title>';
res.writeHead(200, {'Content-Type':'text/html; charset=utf-8'});
res.end(top + bottom);
}
exports.returnIndexL = returnIndexL;
exports.returnIndexA = returnIndexA;