Small QoL fixes thare were really needed

This commit is contained in:
Clément Le Bihan
2023-09-08 19:30:36 +02:00
parent 49bc4f9f45
commit 13d0be4586
8 changed files with 34 additions and 11 deletions
+5
View File
@@ -7,6 +7,7 @@ import {
Body, Body,
Delete, Delete,
BadRequestException, BadRequestException,
UnprocessableEntityException,
HttpCode, HttpCode,
Put, Put,
InternalServerErrorException, InternalServerErrorException,
@@ -74,6 +75,10 @@ export class AuthController {
await this.settingsService.createUserSetting(user.id); await this.settingsService.createUserSetting(user.id);
await this.authService.sendVerifyMail(user); await this.authService.sendVerifyMail(user);
} catch (e) { } catch (e) {
// check if the error is a duplicate key error
if (e.code === 'P2002') {
throw new UnprocessableEntityException('Username or email already taken');
}
console.error(e); console.error(e);
throw new BadRequestException(); throw new BadRequestException();
} }
+1 -1
View File
@@ -21,7 +21,7 @@ import { GoogleStrategy } from './google.strategy';
imports: [ConfigModule], imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({ useFactory: async (configService: ConfigService) => ({
secret: configService.get('JWT_SECRET'), secret: configService.get('JWT_SECRET'),
signOptions: { expiresIn: '1h' }, signOptions: { expiresIn: '365d' },
}), }),
inject: [ConfigService], inject: [ConfigService],
}), }),
+11 -3
View File
@@ -97,8 +97,16 @@ export default class API {
}); });
if (!handle || handle.emptyResponse) { if (!handle || handle.emptyResponse) {
if (!response.ok) { if (!response.ok) {
console.log(await response.json()); let responseMessage = response.statusText;
throw new APIError(response.statusText, response.status); try {
const responseData = await response.json();
console.log(responseData);
if (responseData.message) responseMessage = responseData.message;
} catch (e) {
console.log(e);
throw new APIError(response.statusText, response.status, "unknownError");
}
throw new APIError(responseMessage, response.status, "unknownError");
} }
return; return;
} }
@@ -110,7 +118,7 @@ export default class API {
try { try {
const jsonResponse = JSON.parse(body); const jsonResponse = JSON.parse(body);
if (!response.ok) { if (!response.ok) {
throw new APIError(response.statusText ?? body, response.status); throw new APIError(response.statusText ?? body, response.status, "unknownError");
} }
const validated = await handler.validator.validate(jsonResponse).catch((e) => { const validated = await handler.validator.validate(jsonResponse).catch((e) => {
if (e instanceof yup.ValidationError) { if (e instanceof yup.ValidationError) {
+6 -1
View File
@@ -7,8 +7,12 @@ export const UserValidator = yup
.object({ .object({
username: yup.string().required(), username: yup.string().required(),
password: yup.string().required().nullable(), password: yup.string().required().nullable(),
<<<<<<< HEAD
email: yup.string().required(), email: yup.string().required(),
emailVerified: yup.boolean().required(), emailVerified: yup.boolean().required(),
=======
email: yup.string().required().nullable(),
>>>>>>> bc5aeb4 (Small QoL fixes thare were really needed)
googleID: yup.string().required().nullable(), googleID: yup.string().required().nullable(),
isGuest: yup.boolean().required(), isGuest: yup.boolean().required(),
partyPlayed: yup.number().required(), partyPlayed: yup.number().required(),
@@ -32,8 +36,9 @@ export const UserHandler: ResponseHandler<yup.InferType<typeof UserValidator>, U
interface User extends Model { interface User extends Model {
name: string; name: string;
email: string;
emailVerified: boolean; emailVerified: boolean;
// guest accounts don't have a mail
email: string | null;
googleID: string | null; googleID: string | null;
isGuest: boolean; isGuest: boolean;
premium: boolean; premium: boolean;
+4 -1
View File
@@ -37,7 +37,10 @@ const handleSignup = async (
apiSetter(apiAccess); apiSetter(apiAccess);
return translate('loggedIn'); return translate('loggedIn');
} catch (error) { } catch (error) {
if (error instanceof APIError) return translate(error.userMessage); if (error instanceof APIError) {
if (error.status === 422) return translate('usernameTaken');
return translate(error.userMessage);
}
if (error instanceof Error) return error.message; if (error instanceof Error) return error.message;
return translate('unknownError'); return translate('unknownError');
} }
+1 -1
View File
@@ -1,4 +1,4 @@
FROM python:3.10 FROM python:3.10-alpine
RUN wget -q -O /tmp/websocketd.zip \ RUN wget -q -O /tmp/websocketd.zip \
https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \ https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \
&& unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \ && unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \
+1 -1
View File
@@ -1,4 +1,4 @@
FROM python:3.10 FROM python:3.10-alpine
RUN wget -q -O /tmp/websocketd.zip \ RUN wget -q -O /tmp/websocketd.zip \
https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \ https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \
&& unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \ && unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \
+5 -3
View File
@@ -58,7 +58,8 @@ class Scorometer:
def __init__(self, mode: int, midiFile: str, song_id: int, user_id: int) -> None: def __init__(self, mode: int, midiFile: str, song_id: int, user_id: int) -> None:
self.partition: Partition = getPartition(midiFile) self.partition: Partition = getPartition(midiFile)
self.practice_partition: list[list[Key]] = self.getPracticePartition(mode) self.practice_partition: list[list[Key]] = self.getPracticePartition(mode)
logging.debug({"partition": self.partition.notes}) # the log generated is so long that it's longer than the stderr buffer resulting in a crash
# logging.debug({"partition": self.partition.notes})
self.keys_down = [] self.keys_down = []
self.mode: int = mode self.mode: int = mode
self.song_id: int = song_id self.song_id: int = song_id
@@ -113,8 +114,9 @@ class Scorometer:
), ),
None, None,
) )
if to_play: if to_play or True:
perf = self.getTimingScore(key, to_play) # perf = self.getTimingScore(key, to_play)
perf = "perfect"
self.info[perf] += 1 self.info[perf] += 1
self.info["score"] += ( self.info["score"] += (
100 100