-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (48 loc) · 1.94 KB
/
app.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
const express = require('express');
const { addTextAndOverlay, uploadToIPFS } = require('./imageProcessing');
const { createMetadata } = require('./metadataProcessing');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const PORT = 3001;
app.use(bodyParser.json());
app.use(cors());
// POST endpoint to create NFT image and upload to IPFS
app.post('/process-image', async (req, res) => {
try {
const { ownerWallet, igpostId } = req.body;
if (!ownerWallet || !igpostId) {
return res.status(400).send({ error: 'Missing required parameters: ownerWallet or igpostId' });
}
const imagePath = await addTextAndOverlay('background.jpg', ownerWallet, igpostId);
const ipfsResult = await uploadToIPFS(imagePath);
res.send({
message: 'Image processed and uploaded successfully',
data: ipfsResult
});
} catch (error) {
console.error('Error processing image:', error);
res.status(500).send({ error: 'Failed to process image and upload to IPFS' });
}
});
// POST endpoint to process metadata and upload to IPFS
app.post('/process-metadata', async (req, res) => {
try {
const { imageHash, igpostId } = req.body;
if (!imageHash || !igpostId) {
return res.status(400).send({ error: 'Missing required parameters: hash of the image or igpostId' });
}
const metadataPath = createMetadata(imageHash, igpostId);
const ipfsResult = await uploadToIPFS(metadataPath);
res.send({
message: 'Metadata processed and uploaded successfully',
data: ipfsResult
});
} catch (error) {
console.error('Error processing image:', error);
res.status(500).send({ error: 'Failed to process metadata and upload to IPFS' });
}
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});