From 45e6d15fb3de6cfb93d72fb868b9516234babdbf Mon Sep 17 00:00:00 2001
From: HF
Date: Wed, 17 Mar 2021 11:00:58 +0100
Subject: [PATCH] continue captchas
---
src/actions/fetch.js | 21 +++++++++++++++++++--
src/actions/index.js | 4 ++--
src/actions/types.js | 2 +-
src/components/Alert.jsx | 2 +-
src/components/Captcha.jsx | 23 +++++++++++++++++++----
src/components/UserArea.jsx | 19 -------------------
src/reducers/user.js | 2 +-
src/store/rendererHook.js | 2 +-
src/ui/placePixel.js | 18 +++++-------------
9 files changed, 49 insertions(+), 44 deletions(-)
diff --git a/src/actions/fetch.js b/src/actions/fetch.js
index f42ea3a..5499869 100644
--- a/src/actions/fetch.js
+++ b/src/actions/fetch.js
@@ -34,6 +34,17 @@ async function fetchWithTimeout(resource, options) {
async function parseAPIresponse(response) {
if (!response.ok) {
const code = response.status;
+ if (code === 429) {
+ let error = t`You made too many requests`;
+ const retryAfter = response.headers.get('Retry-After');
+ if (!Number.isNaN(Number(retryAfter))) {
+ const ti = Math.floor(retryAfter / 60);
+ error += `, ${t`try again after ${ti}min`}`;
+ }
+ return {
+ errors: [error],
+ };
+ }
return {
errors: [t`Connection error ${code} :(`],
};
@@ -169,11 +180,17 @@ export async function requestLeaveChan(channelId: boolean) {
return t`Unknown Error`;
}
-export function requestSolveCaptcha(text) {
- return makeAPIPOSTRequest(
+export async function requestSolveCaptcha(text) {
+ const res = await makeAPIPOSTRequest(
'api/captcha',
{ text },
);
+ if (!res.errors && !res.success) {
+ return {
+ errors: [t`Server answered with gibberish :(`],
+ };
+ }
+ return res;
}
export function requestPasswordChange(newPassword, password) {
diff --git a/src/actions/index.js b/src/actions/index.js
index 42cf06a..062a27c 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -120,9 +120,9 @@ export function toggleOpenMenu(): Action {
};
}
-export function setPlaceAllowed(requestingPixel: boolean): Action {
+export function setRequestingPixel(requestingPixel: boolean): Action {
return {
- type: 'SET_PLACE_ALLOWED',
+ type: 'SET_REQUESTING_PIXEL',
requestingPixel,
};
}
diff --git a/src/actions/types.js b/src/actions/types.js
index 5b75cd4..9dadb69 100644
--- a/src/actions/types.js
+++ b/src/actions/types.js
@@ -29,7 +29,7 @@ export type Action =
| { type: 'SELECT_STYLE', style: string }
| { type: 'SET_NOTIFICATION', notification: string }
| { type: 'UNSET_NOTIFICATION' }
- | { type: 'SET_PLACE_ALLOWED', requestingPixel: boolean }
+ | { type: 'SET_REQUESTING_PIXEL', requestingPixel: boolean }
| { type: 'SET_HOVER', hover: Cell }
| { type: 'UNSET_HOVER' }
| { type: 'SET_WAIT', wait: ?number }
diff --git a/src/components/Alert.jsx b/src/components/Alert.jsx
index 242db59..c43c2e1 100644
--- a/src/components/Alert.jsx
+++ b/src/components/Alert.jsx
@@ -56,7 +56,7 @@ const Alert = () => {
{(alertType === 'captcha')
- ?
+ ?
: (