Spaces:
Sleeping
Sleeping
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require("express");
|
| 2 |
+
const { generateIQC } = require("iqc-canvas");
|
| 3 |
+
|
| 4 |
+
const app = express();
|
| 5 |
+
const PORT = process.env.PORT || 7860;
|
| 6 |
+
|
| 7 |
+
app.get("/", async (req, res) => {
|
| 8 |
+
const { text, time, battery } = req.query;
|
| 9 |
+
|
| 10 |
+
// Kalau tidak ada parameter → tampilkan halaman HTML
|
| 11 |
+
if (!text || !time) {
|
| 12 |
+
return res.send(`
|
| 13 |
+
<html>
|
| 14 |
+
<head>
|
| 15 |
+
<title>IQC Canvas Generator</title>
|
| 16 |
+
<style>
|
| 17 |
+
body {
|
| 18 |
+
font-family: Arial;
|
| 19 |
+
background: #0f172a;
|
| 20 |
+
color: white;
|
| 21 |
+
text-align: center;
|
| 22 |
+
padding: 40px;
|
| 23 |
+
}
|
| 24 |
+
input, button {
|
| 25 |
+
padding: 10px;
|
| 26 |
+
margin: 10px;
|
| 27 |
+
border-radius: 8px;
|
| 28 |
+
border: none;
|
| 29 |
+
}
|
| 30 |
+
button {
|
| 31 |
+
background: #22c55e;
|
| 32 |
+
color: white;
|
| 33 |
+
cursor: pointer;
|
| 34 |
+
}
|
| 35 |
+
</style>
|
| 36 |
+
</head>
|
| 37 |
+
<body>
|
| 38 |
+
<h1>IQC Canvas Generator</h1>
|
| 39 |
+
<form method="GET">
|
| 40 |
+
<input type="text" name="text" placeholder="Chat Text" required /><br/>
|
| 41 |
+
<input type="text" name="time" placeholder="Time (12.30)" required /><br/>
|
| 42 |
+
<input type="number" name="battery" placeholder="Battery %" value="100"/><br/>
|
| 43 |
+
<button type="submit">Generate</button>
|
| 44 |
+
</form>
|
| 45 |
+
</body>
|
| 46 |
+
</html>
|
| 47 |
+
`);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
const result = await generateIQC(text, time, {
|
| 52 |
+
baterai: [true, battery || "100"],
|
| 53 |
+
operator: true,
|
| 54 |
+
timebar: true,
|
| 55 |
+
wifi: true
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
res.setHeader("Content-Type", result.mimeType);
|
| 59 |
+
res.send(result.image);
|
| 60 |
+
|
| 61 |
+
} catch (err) {
|
| 62 |
+
res.status(500).json({ error: err.message });
|
| 63 |
+
}
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
app.listen(PORT, () => {
|
| 67 |
+
console.log(`Server running on port ${PORT}`);
|
| 68 |
+
});
|