fix little issues

This commit is contained in:
HF 2022-09-17 22:32:44 +02:00
parent 0ba7063d9e
commit 5b18952c27
5 changed files with 39 additions and 19 deletions

View File

@ -60,7 +60,12 @@ async function submitWatchAction(
method: 'POST',
body: data,
});
const ret = await resp.json();
let ret;
try {
ret = await resp.json();
} catch {
throw new Error(await resp.text());
}
callback(await ret);
} catch (err) {
callback({

View File

@ -32,6 +32,12 @@ import {
getIPofIID,
getIIDofIP,
} from '../data/sql/IPInfo';
import {
getIIDSummary,
getIIDPixels,
getSummaryFromArea,
getPixelsFromArea,
} from './parsePixelLog';
import canvases from './canvases';
import {
imageABGR2Canvas,
@ -258,6 +264,22 @@ export async function executeImageAction(
}
}
/*
* retgister responses on socket for Watch Actions
*/
socketEvents.onReq('watch', (action, ...args) => {
if (action === 'getIIDSummary') {
return getIIDSummary(...args);
} if (action === 'getIIDPixels') {
return getIIDPixels(...args);
} if (action === 'getSummaryFromArea') {
return getSummaryFromArea(...args);
} if (action === 'getPixelsFromArea') {
return getPixelsFromArea(...args);
}
return null;
});
/*
* Check who placed on a canvas area
* @param action if every pixel or summary should be returned

View File

@ -2,7 +2,6 @@ import fs from 'fs';
import readline from 'readline';
import { PIXELLOGGER_PREFIX } from './logger';
import socketEvents from '../socket/socketEvents';
import { getNamesToIds } from '../data/sql/RegUser';
import {
getIdsToIps,
@ -393,16 +392,3 @@ export async function getPixelsFromArea(
rows,
};
}
socketEvents.onReq('watch', (action, ...args) => {
if (action === 'getIIDSummary') {
return getIIDSummary(...args);
} if (action === 'getIIDPixels') {
return getIIDPixels(...args);
} if (action === 'getSummaryFromArea') {
return getSummaryFromArea(...args);
} if (action === 'getPixelsFromArea') {
return getPixelsFromArea(...args);
}
return null;
});

View File

@ -7,14 +7,19 @@ import mailProvider from '../../../core/MailProvider';
import { validatePassword, validateEMail } from '../../../utils/validation';
import { getHostFromRequest } from '../../../utils/ip';
import { compareToHash } from '../../../utils/hash';
import { checkIfMailDisposable } from '../../../core/isAllowed';
function validate(email, password, gettext) {
async function validate(email, password, t, gettext) {
const errors = [];
const passerror = gettext(validatePassword(password));
if (passerror) errors.push(passerror);
const mailerror = gettext(validateEMail(email));
if (mailerror) errors.push(mailerror);
if (mailerror) {
errors.push(mailerror);
} else if (await checkIfMailDisposable(email)) {
errors.push(t`This email provider is not allowed`);
}
return errors;
}
@ -22,7 +27,7 @@ function validate(email, password, gettext) {
export default async (req, res) => {
const { email, password } = req.body;
const { t, gettext } = req.ttag;
const errors = validate(email, password, gettext);
const errors = await validate(email, password, t, gettext);
if (errors.length > 0) {
res.status(400);
res.json({

View File

@ -234,6 +234,7 @@ class ProxyCheck {
this.fetching = false;
this.checkFromQueue = this.checkFromQueue.bind(this);
this.checkIp = this.checkIp.bind(this);
this.checkEmail = this.checkEmail.bind(this);
this.pcKeyProvider = new PcKeyProvider(pcKeys, logger);
this.logger = logger;
}
@ -360,6 +361,7 @@ class ProxyCheck {
let disposable = null;
if (res[value]) {
this.logger.info(`Email ${value}: ${JSON.stringify(res[value])}`);
disposable = !!res[value].disposable;
}
@ -371,7 +373,7 @@ class ProxyCheck {
let pcheck = 'N/A';
if (res[value]) {
this.logger.info(`${value}: ${JSON.stringify(res[value])}`);
this.logger.info(`IP ${value}: ${JSON.stringify(res[value])}`);
const { proxy, type, city } = res[value];
allowed = proxy === 'no';
status = (allowed) ? 0 : 1;