diff --git a/src/client/client.js b/src/client/client.js index 93011cc..a9c5272 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -60,7 +60,7 @@ function uCaptchaBox(websiteKey) { captchaBox.appendChild(btn); checkbox.onclick = async function() { - /** @type {import('../shared/models/UserSession.js').UserSession} */ + /** @type {import('../models/UserSession.js').UserSession} */ const session = await initializeSession(websiteKey); const imageGrid = createElement('table', {id: 'ucaptcha-grid'}); diff --git a/src/client/helpers/getImage.js b/src/client/helpers/getImage.js index 094a928..3d82a8e 100644 --- a/src/client/helpers/getImage.js +++ b/src/client/helpers/getImage.js @@ -1,5 +1,7 @@ -import request from './util/request.js'; -import UserSession from '../../shared/models/UserSession.js'; +import request from '../util/request.js'; +/** + * @typedef { import('../../models/UserSession.js').UserSession } UserSession + */ /** * Instantiate the uCaptcha loop diff --git a/src/client/helpers/initializeSession.js b/src/client/helpers/initializeSession.js index 22d2708..f55907c 100644 --- a/src/client/helpers/initializeSession.js +++ b/src/client/helpers/initializeSession.js @@ -1,5 +1,5 @@ import request from '../util/request.js'; -import UserSession from '../../shared/models/UserSession.js'; +import UserSession from '../../models/UserSession.js'; /** * @param {string} websiteKey diff --git a/src/client/helpers/verifyImage.js b/src/client/helpers/verifyImage.js index f1bef14..5565ec2 100644 --- a/src/client/helpers/verifyImage.js +++ b/src/client/helpers/verifyImage.js @@ -1,12 +1,16 @@ -import request from './util/request.js'; -import UserSession from '../../shared/models/UserSession.js'; +import request from '../util/request.js'; + +/** + * @typedef { import('../../models/UserSession.js').UserSession } UserSession + */ + /** * Verify the image * @param {UserSession} session * @param {HTMLElement} captchaGrid */ -export default async function(session, captchaGrid) { +export async function verfiyImage(session, captchaGrid) { const tds = captchaGrid.querySelectorAll('td'); const selectedTds = []; @@ -31,3 +35,5 @@ export default async function(session, captchaGrid) { td.classList.remove('selected'); }); } + +export default verfiyImage; diff --git a/src/models/IDBSession.js b/src/models/IDBSession.js index d579da0..609804d 100644 --- a/src/models/IDBSession.js +++ b/src/models/IDBSession.js @@ -6,3 +6,4 @@ * @property {string} image Image URL for challenge * @property {number} score How likely is the user to be a human? */ +export const IDBSession = {}; diff --git a/src/shared/models/UserSession.js b/src/shared/models/UserSession.js deleted file mode 100644 index 644e18e..0000000 --- a/src/shared/models/UserSession.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * User session model - * @type {Object} Session Object. - * @property {string} _sessionId The session identifier - * @property {string} _websiteKey The website id for session - */ -export class UserSession { - /** - * Set session ID - * @param {string} id - */ - set sessionId(id) { - this._sessionId = id; - } - - /** - * Get the session ID - * @type {string} - */ - get sessionId() { - return this._sessionId; - } - - /** - * Set session ID - * @param {string} id - */ - set websiteKey(id) { - this._websiteKey = id; - } - - /** - * Get the session ID - * @type {string} - */ - get websiteKey() { - return this._websiteKey; - } - - /** - * Serialize the session into a JSON object - * @return {Array} - */ - serialize() { - const {sessionId, websiteKey} = this; - if (!sessionId || !websiteKey) { - throw Error(); - } - return [sessionId, websiteKey]; - } - - /** - * Deserialize session data from JSON object - * @param {Array} payload - */ - deserialize([sessionId, websiteKey]) { - Object.assign(this, {sessionId, websiteKey}); - } -}; - -export default UserSession -;