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);
if (!ini) {
const msg = `Signature: "${signature}" not supported!`;
const msg = `Signature: "${signature}" not supported`;
const error = new Error(msg);
Sentry.captureException(error);

View File

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

View File

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