-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (56 loc) · 2.05 KB
/
index.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
const express = require('express')
const path = require('path')
const moment = require('moment')
const { HOST } = require('./src/constants')
const db = require('./src/database')
const PORT = process.env.PORT || 5000
const app = express()
.set('port', PORT)
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
// Static public files
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', function(req, res) {
res.send('Get ready for OpenSea!');
})
app.get('/api/token/:token_id', function(req, res) {
const tokenId = parseInt(req.params.token_id).toString()
const person = db[tokenId]
//const bdayParts = person.birthday.split(' ')
//const day = parseInt(bdayParts[1])
//const month = parseInt(bdayParts[0])
var imageText = 'images';
if(tokenId < 1000) {
imageText = 'images';
} else if(tokenId < 2000){
imageText = 'images2';
} else {
imageText = 'images3';
}
const data = {
'name': person.name,
'attributes': {
'color': person.color,
'hat': person.hattype,
// 'birth month': monthName(month),
// 'zodiac sign': zodiac(day, month),
//'age': moment().diff(person.birthday, 'years')
}, //images/
'image': `${HOST}/${imageText}/${tokenId}.png`
}
res.send(data)
})
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
})
// returns the zodiac sign according to day and month ( https://coursesweb.net/javascript/zodiac-signs_cs )
function zodiac(day, month) {
var zodiac =['', 'Capricorn', 'Aquarius', 'Pisces', 'Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo', 'Libra', 'Scorpio', 'Sagittarius', 'Capricorn'];
var last_day =['', 19, 18, 20, 20, 21, 21, 22, 22, 21, 22, 21, 20, 19];
return (day > last_day[month]) ? zodiac[month*1 + 1] : zodiac[month];
}
function monthName(month) {
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
]
return monthNames[month - 1]
}