forked from iamsdas/Turtis-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (45 loc) · 1.41 KB
/
server.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
import fs from 'fs';
import express from 'express';
import { genRandomImage } from './image-blend-randomize.js';
import { NFTStorage, File } from "nft.storage";
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const port = process.env.PORT || 4000;
const apiKey = process.env.NFT_STORAGE_API_KEY;
const client = new NFTStorage({ token: apiKey });
let sameCallStr = "";
app.get('/', async (req, res) => {
await genRandomImage();
var characterId = req.query.characterId;
var characterName = "Turtle #" + characterId;
console.log("Turtle name: " + characterName);
var speed = parseInt(req.query.score);
speed += parseInt(Math.random() * 51);
console.log("Speed: " + speed);
const imgdata = fs.readFileSync('character.png');
const metadata = await client.store({
name: characterName,
description: 'An amazing turtle that can dodge through platforms',
image: new File([imgdata], 'character.png', { type: 'image/png' }),
attributes: [
{ trait_type: 'speed', value: speed },
],
});
var str = metadata.ipnft;
sameCallStr = str.slice(31);
str = str.slice(0, 31);
console.log("Part 1 Hash: " + str);
console.log("Part 2 Hash: " + sameCallStr);
res.json({
IPFS_PATH: str
});
});
app.get('/second', async (req, res) => {
res.json({
IPFS_PATH: sameCallStr
});
});
app.listen(port, () => {
console.log(`app listening at port: ${port}`);
});