-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (20 loc) · 880 Bytes
/
server.js
File metadata and controls
34 lines (20 loc) · 880 Bytes
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
const express = require('express');
const fs = require('fs');
const path = require('path');
const QRCode = require('qrcode');
const app = express();
app.use(express.json({ limit: '10mb' }));
app.use(express.static('public'));
const PHOTO_DIR = path.join(__dirname, 'public/photos');
if (!fs.existsSync(PHOTO_DIR)) fs.mkdirSync(PHOTO_DIR, { recursive: true });
app.post('/save-photo', async (req, res) => {
const image = req.body.image;
const base64Data = image.replace(/^data:image\/png;base64,/, '');
const filename = `photo_${Date.now()}.png`;
const filepath = path.join(PHOTO_DIR, filename);
fs.writeFileSync(filepath, base64Data, 'base64');
const photoURL = `http://localhost:3000/photos/${filename}`;
const qr = await QRCode.toDataURL(photoURL);
res.json({ photoURL, qr });
});
app.listen(3000, () => console.log('Photobooth running at http://localhost:3000'));