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
* 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 **/
export const btnId = "widget__verification-checkbox";
@ -71,10 +71,6 @@ export const messageText = (): messageTextReturn => {
const after = new LazyElement(afterID);
const during = new LazyElement(duringID);
const error = new LazyElement(errorID);
// let before: HTMLElement;
// let after: HTMLElement;
// let during: HTMLElement;
// let error: HTMLElement;
/** runner fn to display HTMLElement **/
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.
*/
import genJsonPayload from "../../utils/genJsonPayload";
import genJsonPayload from "../utils/genJsonPayload";
import * as CONST from "./const";
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
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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/>.
* 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 "./main.scss";
//import prove from './runner/prove';
//import fetchPoWConfig from './runner/fetchPoWConfig';
//import sendWork from './runner/sendWork';
//import sendToParent from './runner/sendToParent';
//import * as CONST from './runner/const';
//
///** add mcaptcha widget element to DOM */
//export const register = () => {
// const verificationContainer = <HTMLElement>(
// document.querySelector('.widget__verification-container')
// );
// verificationContainer.style.display = 'flex';
//
// CONST.btn().addEventListener('click', e => solveCaptchaRunner(e));
//};
//
//const solveCaptchaRunner = async (e: Event) => {
// e.preventDefault();
// // steps:
//
// // 1. hide --before message
// CONST.messageText().before().style.display = 'none';
//
// // 1. show --during
// CONST.messageText().during().style.display = 'block';
// // 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;
//};
//
//register();
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

@ -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.
*/
import genJsonPayload from "../../utils/genJsonPayload";
import genJsonPayload from "../utils/genJsonPayload";
import * as CONST from "./const";
import {Work} from "./prove";

View file

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