This repository was archived by the owner on Jul 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (57 loc) · 2.27 KB
/
Copy pathindex.js
File metadata and controls
68 lines (57 loc) · 2.27 KB
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
const { app } = require('electron');
const { CroissantAPI } = require('./croissant-api.js');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config("./.env");
function createWindow() {
const { BrowserWindow } = require('electron');
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
icon: path.join(__dirname, 'icon.png'),
});
mainWindow.loadURL('http://localhost:3000');
mainWindow.setMenuBarVisibility(false);
mainWindow.maximize();
}
app.whenReady().then(createWindow);
const croissantAPI = new CroissantAPI({token: process.env.CROISSANT_API_KEY || ''});
const express = require('express');
const cookieParser = require('cookie-parser');
const server = express();
server.use(express.json());
server.use(cookieParser());
server.use(express.static(path.join(__dirname, "public")));
server.post('/verifyUser', (req, res) => {
const { userId, verificationKey } = req.body;
if (userId && verificationKey) {
croissantAPI.users.verify(userId, verificationKey)
.then(response => {
if (response.error) {
return res.status(400).json({ error: response.error });
}
res.cookie('userId', userId, { maxAge: 31 * 24 * 60 * 60 * 1000 }); // 31 days
res.cookie('verificationKey', verificationKey, { maxAge: 31 * 24 * 60 * 60 * 1000 }); // 31 days
res.json({ message: "User verified successfully", userId: response.userId });
});
} else {
res.status(400).json({ error: "User ID and verification key are required" });
}
});
server.post('/click', async (req, res) => {
try {
const item = await croissantAPI.items.give("6ddf37c7-05b6-4aaf-a807-d1b7e6331dc2", 1, req.cookies.userId);
res.json(item);
} catch (error) {
console.error('Error fetching item:', error);
res.status(500).json({ error: error.message || 'Failed to give item' });
}
});
server.listen(3000, () => {
console.log("Server is running on http://localhost:3000");
});