Fixes to widget, demo
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
const express = require('express');
|
||||
const Cap = require('@cap.js/server');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.static('public'));
|
||||
|
||||
const cap = new Cap({
|
||||
tokens_store_path: '.data/tokensList.json'
|
||||
});
|
||||
|
||||
app.post('/api/challenge', (req, res) => {
|
||||
res.json(cap.createChallenge({
|
||||
challengeCount: 5,
|
||||
challengeSize: 16,
|
||||
challengeDifficulty: 3,
|
||||
expiresMs: 300000
|
||||
}));
|
||||
});
|
||||
|
||||
app.post('/api/redeem', async (req, res) => {
|
||||
const { token, solutions } = req.body;
|
||||
if (!token || !solutions) {
|
||||
return res.status(400).json({ success: false });
|
||||
}
|
||||
res.json(await cap.redeemChallenge({ token, solutions }));
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('Listening on port 3000');
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "cap-demo",
|
||||
"version": "0.0.1",
|
||||
"description": "Cap demo",
|
||||
"license": "AGPL-3.0",
|
||||
"author": "Tiago Rangel",
|
||||
"type": "commonjs",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cap.js/server": "^1.0.1",
|
||||
"express": "^4.21.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cap demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<cap-widget id="cap" data-api-endpoint="/api/"></cap-widget>
|
||||
</body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@cap.js/widget"></script>
|
||||
</html>
|
||||
+1
-1
@@ -20,7 +20,7 @@ Now, you'll need to change your server code to add the routes that Cap needs to
|
||||
|
||||
```js
|
||||
const express = require('express');
|
||||
const Cap = require('./index.js');
|
||||
const Cap = require('@cap.js/server');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cap.js/widget",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.5",
|
||||
"description": "Cap widget",
|
||||
"keywords": [
|
||||
"captcha",
|
||||
@@ -24,7 +24,7 @@
|
||||
"license": "AGPL-3.0",
|
||||
"author": "Tiago Rangel",
|
||||
"type": "commonjs",
|
||||
"main": "cap.js",
|
||||
"main": "cap.min.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"npm:publish": "sudo npm publish --access public"
|
||||
|
||||
+18
-18
@@ -1,6 +1,24 @@
|
||||
(function () {
|
||||
let workerScript;
|
||||
|
||||
const until = (predFn, timeout = 10000) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
reject(new Error("Initialize timeout"));
|
||||
}, timeout);
|
||||
|
||||
const poll = () => {
|
||||
if (predFn()) {
|
||||
clearTimeout(timeoutId);
|
||||
resolve();
|
||||
} else {
|
||||
setTimeout(poll, 500);
|
||||
}
|
||||
};
|
||||
poll();
|
||||
});
|
||||
};
|
||||
|
||||
class CapBase {
|
||||
#workerUrl = "";
|
||||
#el = null;
|
||||
@@ -9,24 +27,6 @@
|
||||
#token = null;
|
||||
|
||||
async initialize() {
|
||||
const until = (predFn, timeout = 10000) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
reject(new Error("Initialize timeout"));
|
||||
}, timeout);
|
||||
|
||||
const poll = () => {
|
||||
if (predFn()) {
|
||||
clearTimeout(timeoutId);
|
||||
resolve();
|
||||
} else {
|
||||
setTimeout(poll, 500);
|
||||
}
|
||||
};
|
||||
poll();
|
||||
});
|
||||
};
|
||||
|
||||
if (this.#workerUrl) {
|
||||
URL.revokeObjectURL(this.#workerUrl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user