Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -7,6 +7,7 @@ const path = require("path");
|
|
| 7 |
const crypto = require("crypto");
|
| 8 |
|
| 9 |
const app = express();
|
|
|
|
| 10 |
const tempDir = os.tmpdir();
|
| 11 |
|
| 12 |
function generateRandomHex(length) {
|
|
@@ -15,22 +16,26 @@ function generateRandomHex(length) {
|
|
| 15 |
|
| 16 |
app.use("/tmp", express.static(tempDir));
|
| 17 |
|
| 18 |
-
app.
|
| 19 |
const captcha = svgCaptcha.create({
|
| 20 |
size: 6,
|
| 21 |
ignoreChars: "0oO1iIl",
|
| 22 |
noise: 2,
|
| 23 |
-
color:
|
|
|
|
| 24 |
});
|
| 25 |
|
| 26 |
-
const fileName = `
|
| 27 |
const filePath = path.join(tempDir, fileName);
|
| 28 |
|
| 29 |
const canvas = createCanvas(200, 80);
|
| 30 |
const ctx = canvas.getContext("2d");
|
| 31 |
const img = await loadImage(`data:image/svg+xml;base64,${Buffer.from(captcha.data).toString("base64")}`);
|
| 32 |
|
|
|
|
|
|
|
| 33 |
ctx.drawImage(img, 0, 0, 200, 80);
|
|
|
|
| 34 |
const buffer = canvas.toBuffer("image/png");
|
| 35 |
|
| 36 |
fs.writeFile(filePath, buffer, (err) => {
|
|
|
|
| 7 |
const crypto = require("crypto");
|
| 8 |
|
| 9 |
const app = express();
|
| 10 |
+
app.set('json spaces', 4)
|
| 11 |
const tempDir = os.tmpdir();
|
| 12 |
|
| 13 |
function generateRandomHex(length) {
|
|
|
|
| 16 |
|
| 17 |
app.use("/tmp", express.static(tempDir));
|
| 18 |
|
| 19 |
+
app.all("/", async (req, res) => {
|
| 20 |
const captcha = svgCaptcha.create({
|
| 21 |
size: 6,
|
| 22 |
ignoreChars: "0oO1iIl",
|
| 23 |
noise: 2,
|
| 24 |
+
color: false,
|
| 25 |
+
background: "#FFFFFF"
|
| 26 |
});
|
| 27 |
|
| 28 |
+
const fileName = `temp_${generateRandomHex(8)}.png`;
|
| 29 |
const filePath = path.join(tempDir, fileName);
|
| 30 |
|
| 31 |
const canvas = createCanvas(200, 80);
|
| 32 |
const ctx = canvas.getContext("2d");
|
| 33 |
const img = await loadImage(`data:image/svg+xml;base64,${Buffer.from(captcha.data).toString("base64")}`);
|
| 34 |
|
| 35 |
+
ctx.fillStyle = "#FFFFFF";
|
| 36 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 37 |
ctx.drawImage(img, 0, 0, 200, 80);
|
| 38 |
+
|
| 39 |
const buffer = canvas.toBuffer("image/png");
|
| 40 |
|
| 41 |
fs.writeFile(filePath, buffer, (err) => {
|