Handle signature not supported, closes: #402

This commit is contained in:
Piotr Rogowski 2022-10-28 17:41:55 +02:00
parent 0f8e59e6b7
commit 69fe069154
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
3 changed files with 30 additions and 7 deletions

View File

@ -24,7 +24,7 @@ const useServerStorage = () => {
const ini = await getIni(signature); const ini = await getIni(signature);
if (!ini) { if (!ini) {
const msg = `Signature: "${signature}" not supported!`; const msg = `Signature: "${signature}" not supported`;
const error = new Error(msg); const error = new Error(msg);
Sentry.captureException(error); Sentry.captureException(error);

View File

@ -9,7 +9,6 @@ import {
Divider, Divider,
Input, Input,
InputNumber, InputNumber,
notification,
Row, Row,
Select, Select,
Space, Space,
@ -48,7 +47,9 @@ import ReactMarkdown from 'react-markdown';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import { import {
emailNotVerified, emailNotVerified,
error,
restrictedPage, restrictedPage,
signatureNotSupportedWarning,
usernameNotSet, usernameNotSet,
} from './auth/notifications'; } from './auth/notifications';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
@ -139,7 +140,7 @@ const UploadPage = () => {
const shareSupported = 'share' in navigator; const shareSupported = 'share' in navigator;
const { currentUser, refreshUser } = useAuth(); const { currentUser, refreshUser } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const { fetchTuneFile } = useServerStorage(); const { fetchTuneFile, fetchINIFile } = useServerStorage();
const { createTune, updateTune, getTune, autocomplete } = useDb(); const { createTune, updateTune, getTune, autocomplete } = useDb();
const [autocompleteOptions, setAutocompleteOptions] = useState<{ [attribute: string]: { value: string }[] }>({}); const [autocompleteOptions, setAutocompleteOptions] = useState<{ [attribute: string]: { value: string }[] }>({});
@ -298,7 +299,7 @@ const UploadPage = () => {
if (!validation.result) { if (!validation.result) {
const errorName = 'Validation failed'; const errorName = 'Validation failed';
const errorMessage = validation.message; const errorMessage = validation.message;
notification.error({ message: errorName, description: errorMessage }); error(errorName, errorMessage);
onError!({ name: errorName, message: errorMessage }); onError!({ name: errorName, message: errorMessage });
return false; return false;
@ -319,8 +320,16 @@ const UploadPage = () => {
return { result, message }; return { result, message };
} }
const parsed = tuneParser.parse(await file.arrayBuffer());
try {
await fetchINIFile(parsed.getTune().details.signature);
} catch (e) {
signatureNotSupportedWarning((e as Error).message);
}
return { return {
result: tuneParser.parse(await file.arrayBuffer()).isValid(), result: parsed.isValid(),
message: 'Tune file is not valid!', message: 'Tune file is not valid!',
}; };
}); });
@ -391,9 +400,9 @@ const UploadPage = () => {
try { try {
const parser = new INI(await file.arrayBuffer()).parse(); const parser = new INI(await file.arrayBuffer()).parse();
valid = parser.getResults().megaTune.signature.length > 0; valid = parser.getResults().megaTune.signature.length > 0;
} catch (error) { } catch (e) {
valid = false; valid = false;
validationMessage = (error as Error).message; validationMessage = (e as Error).message;
} }
return { return {

View File

@ -7,6 +7,12 @@ const baseOptions = {
placement: 'bottomRight' as const, placement: 'bottomRight' as const,
}; };
const error = (message: string, description: string) => notification.warning({
message,
description,
...baseOptions,
});
const emailNotVerified = () => notification.warning({ const emailNotVerified = () => notification.warning({
message: 'Check your email', message: 'Check your email',
description: 'Your email address has to be verified before you can upload files!', description: 'Your email address has to be verified before you can upload files!',
@ -135,7 +141,14 @@ const copiedToClipboard = () => notification.success({
...baseOptions, ...baseOptions,
}); });
const signatureNotSupportedWarning = (message: string) => notification.warning({
message,
description: 'You need to upload custom INI file with your tune!',
...baseOptions,
});
export { export {
error,
emailNotVerified, emailNotVerified,
usernameNotSet, usernameNotSet,
signUpSuccessful, signUpSuccessful,
@ -158,4 +171,5 @@ export {
copiedToClipboard, copiedToClipboard,
iniLoadingError, iniLoadingError,
tuneParsingError, tuneParsingError,
signatureNotSupportedWarning,
}; };