-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
101 lines (83 loc) · 2.83 KB
/
routes.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
/*
Declare all URL patterns and their target templates
*/
Router.route("/", function () {
this.render("productsPage");
});
Router.route("/gallery", function () {
this.render("galleryPage");
});
Router.route("/vis/:prodId", function () {
console.log(Products.findOne({_id: this.params.prodId}));
if (Products.findOne({_id: this.params.prodId})) {
Session.set("currentProduct", this.params.prodId);
Session.set("changedProduct", true);
this.render("galleryPage");
} else {
this.render("productsPage");
}
});
Router.route("/products", function () {
this.render("productsPage");
});
Router.route("/products/:prodId", function () {
if (Products.findOne({_id: this.params.prodId})) {
Session.set("productSearchQuery", Products.findOne({_id: this.params.prodId}).name);
}
this.render("productsPage");
});
Router.route("/store/:storeName/*", function () {
if (Meteor.users.findOne({username: this.params.storeName})) {
Session.set("currentStore", this.params.storeName);
}
this.render("productsPage");
});
Router.route("/search/prod/:term", function () {
Session.set("productSearchQuery", this.params.term);
this.render("productsPage");
});
Router.route("/admin", function () {
if(Roles.userIsInRole(Meteor.userId(), ['admin'])) {
this.render("adminPage");
} else {
Session.set("unauthorized", true);
this.render("galleryPage");
}
});
Router.map(function() {
this.route('zip', {
where: 'server',
path: 'zip',
action: function() {
var self = this;
// Create zip
var zip = new JSZip();
var productList = Products.find().fetch();
var header = ["name", "description", "price", "link"];
var exportData = header;
for (var i =0; i < productList.length; i++){
var row = [
productList[i].name,
productList[i].description,
productList[i].price,
productList[i].link
];
exportData += ("\n" + row);
}
// Add a file to the zip
var filename = "export_" + new Date().getTime() + ".txt";
zip.file("export_" + new Date() + ".txt", exportData);
// Generate zip stream
var output = zip.generate({
type: "nodebuffer",
compression: "DEFLATE"
});
// Set headers
self.response.setHeader("Content-Type", "application/octet-stream");
self.response.setHeader("Content-disposition", "attachment; filename=filename.zip");
self.response.writeHead(200);
// Send content
self.response.end(output);
}
});
});