mv widget js from out of subdir

This commit is contained in:
realaravinth 2021-12-01 17:23:47 +05:30
parent 481246ffd5
commit 7154a309be
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
10 changed files with 84 additions and 143 deletions

View File

@ -8,7 +8,7 @@
* this program. If not, see <https://spdx.org/licenses/MIT.html> for * this program. If not, see <https://spdx.org/licenses/MIT.html> for
* MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache. * MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache.
*/ */
import LazyElement from "../../utils/lazyElement"; import LazyElement from "../utils/lazyElement";
/** mcaptcha checkbox ID **/ /** mcaptcha checkbox ID **/
export const btnId = "widget__verification-checkbox"; export const btnId = "widget__verification-checkbox";
@ -71,10 +71,6 @@ export const messageText = (): messageTextReturn => {
const after = new LazyElement(afterID); const after = new LazyElement(afterID);
const during = new LazyElement(duringID); const during = new LazyElement(duringID);
const error = new LazyElement(errorID); const error = new LazyElement(errorID);
// let before: HTMLElement;
// let after: HTMLElement;
// let during: HTMLElement;
// let error: HTMLElement;
/** runner fn to display HTMLElement **/ /** runner fn to display HTMLElement **/
const showMsg = (e: HTMLElement) => (e.style.display = "block"); const showMsg = (e: HTMLElement) => (e.style.display = "block");

View File

@ -9,7 +9,7 @@
* MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache. * MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache.
*/ */
import genJsonPayload from "../../utils/genJsonPayload"; import genJsonPayload from "../utils/genJsonPayload";
import * as CONST from "./const"; import * as CONST from "./const";
type GetConfigPayload = { type GetConfigPayload = {

View File

@ -1,55 +1,68 @@
/* /*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> * mCaptcha is a PoW based DoS protection software.
* This is the frontend web component of the mCaptcha system
* Copyright © 2021 Aravinth Manivnanan <realaravinth@batsense.net>.
* *
* This program is free software: you can redistribute it and/or modify * Use of this source code is governed by Apache 2.0 or MIT license.
* it under the terms of the GNU Affero General Public License as * You shoud have received a copy of MIT and Apache 2.0 along with
* published by the Free Software Foundation, either version 3 of the * this program. If not, see <https://spdx.org/licenses/MIT.html> for
* License, or (at your option) any later version. * MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import "./main.scss";
//import prove from './runner/prove'; import prove from "./prove";
//import fetchPoWConfig from './runner/fetchPoWConfig'; import fetchPoWConfig from "./fetchPoWConfig";
//import sendWork from './runner/sendWork'; import sendWork from "./sendWork";
//import sendToParent from './runner/sendToParent'; import sendToParent from "./sendToParent";
//import * as CONST from './runner/const'; import * as CONST from "./const";
//
///** add mcaptcha widget element to DOM */ import "../main.scss";
//export const register = () => {
// const verificationContainer = <HTMLElement>( let LOCK = false;
// document.querySelector('.widget__verification-container')
// ); /** add mcaptcha widget element to DOM */
// verificationContainer.style.display = 'flex'; export const registerVerificationEventHandler = (): void => {
// const verificationContainer = <HTMLElement>(
// CONST.btn().addEventListener('click', e => solveCaptchaRunner(e)); document.querySelector(".widget__verification-container")
//}; );
// verificationContainer.style.display = "flex";
//const solveCaptchaRunner = async (e: Event) => { CONST.btn().addEventListener("click", (e) => solveCaptchaRunner(e));
// e.preventDefault(); };
// // steps:
// export const solveCaptchaRunner = async (e: Event): Promise<void> => {
// // 1. hide --before message if (LOCK) {
// CONST.messageText().before().style.display = 'none'; e.preventDefault();
// return;
// // 1. show --during }
// CONST.messageText().during().style.display = 'block';
// // 1. get config try {
// const config = await fetchPoWConfig(); LOCK = true;
// // 2. prove work if (CONST.btn().checked == false) {
// const proof = await prove(config); CONST.messageText().before();
// // 3. submit work LOCK = false;
// const token = await sendWork(proof); return;
// // 4. send token }
// sendToParent(token); e.preventDefault();
// // 5. mark checkbox checked // steps:
// CONST.btn().checked = true;
//}; // 1. show during
// CONST.messageText().during();
//register(); // 1. get config
const config = await fetchPoWConfig();
// 2. prove work
const proof = await prove(config);
// 3. submit work
const token = await sendWork(proof);
// 4. send token
sendToParent(token);
// 5. mark checkbox checked
CONST.btn().checked = true;
CONST.messageText().after();
LOCK = false;
} catch (e) {
CONST.messageText().error();
console.error(e);
LOCK = false;
}
};
registerVerificationEventHandler();

View File

@ -1,68 +0,0 @@
/*
* mCaptcha is a PoW based DoS protection software.
* This is the frontend web component of the mCaptcha system
* Copyright © 2021 Aravinth Manivnanan <realaravinth@batsense.net>.
*
* Use of this source code is governed by Apache 2.0 or MIT license.
* You shoud have received a copy of MIT and Apache 2.0 along with
* this program. If not, see <https://spdx.org/licenses/MIT.html> for
* MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache.
*/
import prove from "./prove";
import fetchPoWConfig from "./fetchPoWConfig";
import sendWork from "./sendWork";
import sendToParent from "./sendToParent";
import * as CONST from "./const";
import "../main.scss";
let LOCK = false;
/** add mcaptcha widget element to DOM */
export const registerVerificationEventHandler = (): void => {
const verificationContainer = <HTMLElement>(
document.querySelector(".widget__verification-container")
);
verificationContainer.style.display = "flex";
CONST.btn().addEventListener("click", (e) => solveCaptchaRunner(e));
};
export const solveCaptchaRunner = async (e: Event): Promise<void> => {
if (LOCK) {
e.preventDefault();
return;
}
try {
LOCK = true;
if (CONST.btn().checked == false) {
CONST.messageText().before();
LOCK = false;
return;
}
e.preventDefault();
// steps:
// 1. show during
CONST.messageText().during();
// 1. get config
const config = await fetchPoWConfig();
// 2. prove work
const proof = await prove(config);
// 3. submit work
const token = await sendWork(proof);
// 4. send token
sendToParent(token);
// 5. mark checkbox checked
CONST.btn().checked = true;
CONST.messageText().after();
LOCK = false;
} catch (e) {
CONST.messageText().error();
console.error(e);
LOCK = false;
}
};
registerVerificationEventHandler();

View File

@ -9,7 +9,7 @@
* MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache. * MIT or <http://www.apache.org/licenses/LICENSE-2.0> for Apache.
*/ */
import genJsonPayload from "../../utils/genJsonPayload"; import genJsonPayload from "../utils/genJsonPayload";
import * as CONST from "./const"; import * as CONST from "./const";
import {Work} from "./prove"; import {Work} from "./prove";

View File

@ -1,38 +1,38 @@
'use strict'; "use strict";
const path = require('path'); const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
//const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin'); //const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin');
module.exports = { module.exports = {
//devtool: 'inline-source-map', //devtool: 'inline-source-map',
//mode: 'development', //mode: 'development',
mode: 'production', mode: "production",
entry: { entry: {
bundle: './templates/index.ts', bundle: "./templates/index.ts",
mobile: './templates/mobile.ts', mobile: "./templates/mobile.ts",
verificationWidget: './templates/widget/js/index.ts', verificationWidget: "./templates/widget/index.ts",
}, },
output: { output: {
filename: '[name].js', filename: "[name].js",
path: path.resolve(__dirname, './static/cache/bundle/'), path: path.resolve(__dirname, "./static/cache/bundle/"),
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
loader: 'ts-loader', loader: "ts-loader",
}, },
{ {
test: /\.s[ac]ss$/i, test: /\.s[ac]ss$/i,
use: [ use: [
MiniCssExtractPlugin.loader, MiniCssExtractPlugin.loader,
'css-loader', "css-loader",
{ {
loader: 'sass-loader', loader: "sass-loader",
options: { options: {
implementation: require('dart-sass'), implementation: require("dart-sass"),
}, },
}, },
], ],
@ -40,7 +40,7 @@ module.exports = {
], ],
}, },
resolve: { resolve: {
extensions: ['.ts', '.tsx', '.js'], extensions: [".ts", ".tsx", ".js"],
}, },
plugins: [ plugins: [
@ -53,7 +53,7 @@ module.exports = {
optimization: { optimization: {
minimizer: [ minimizer: [
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
`...`, "...",
new CssMinimizerPlugin(), new CssMinimizerPlugin(),
], ],
}, },