This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keystone.js
106 lines (89 loc) · 2.35 KB
/
keystone.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
require("dotenv").config();
const keystone = require("keystone");
const handlebars = require("express-handlebars");
const websockets = require("./websockets");
const request = require("request-promise");
const helpers = new require("./templates/views/helpers")();
module.exports.storage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
path: keystone.expandPath("./public/uploads"),
publicPath: "/uploads"
}
});
const messageColours = {
red: 0xdd2e44,
green: 0x77b255,
blue: 0x3b88c3
};
keystone.set("log", function(message, colour, product, address) {
if (!process.env.DISCORD_WEBHOOK) return;
const serverURL = process.env.SERVER_URL || "https://market.switchcraft.pw";
const fields = [];
if (address) {
fields.push({
name: "Address",
value: `[${address}](${helpers.kristweb(address)})`,
inline: true
});
}
const embed = {
title: product.name,
description: message.replace(/@/g, ":monkey_face:"),
url: `${serverURL}/products/${product.slug}`,
color: messageColours[colour],
timestamp: new Date(),
thumbnail: product.image ? {
url: `${serverURL}/uploads/${product.image.filename}`
} : null,
fields
};
request(process.env.DISCORD_WEBHOOK, {
method: "POST",
body: { embeds: [embed] },
json: true
}).catch(error => {
console.error("Error logging to discord:");
console.error(error);
});
});
keystone.init({
"name": "SwitchMarket",
"brand": "SwitchMarket",
"sass": "public",
"static": "public",
"favicon": "public/favicon.ico",
"views": "templates/views",
"view engine": ".hbs",
"custom engine": handlebars.create({
layoutsDir: "templates/views/layouts",
partialsDir: "templates/views/partials",
defaultLayout: "default",
helpers,
extname: ".hbs"
}).engine,
"auto update": true,
"session": true,
"auth": true,
"user model": "User"
});
keystone.import("models");
keystone.set("locals", {
_: require("lodash"),
env: keystone.get("env"),
utils: keystone.utils,
editable: keystone.content.editable
});
keystone.set("routes", require("./routes"));
keystone.set("nav", {
users: "users",
bids: "bids",
products: "products"
});
keystone.start({
onStart() {
websockets.start();
const scheduler = require("./sale-scheduler");
scheduler.start().catch(console.error);
}
});