forked from ProjectOpenSea/metadata-api-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (47 loc) · 1.79 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
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])
const data = {
'name': person.name,
'attributes': {
'birthday': person.birthday,
'birth month': monthName(month),
'zodiac sign': zodiac(day, month),
// 'age': moment().diff(person.birthday, 'years')
},
'image': `${HOST}/images/${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]
}