fix: validate the import preset

This commit is contained in:
Wentao Lyu 2023-04-05 16:16:11 +08:00
parent 8c2d577e60
commit 6abe34ee3b
3 changed files with 32 additions and 24 deletions

View file

@ -73,21 +73,23 @@ export function useManualSWR({ path, params, type, onSuccess }) {
return useSWRMutation(path, fetchFunction, options);
}
export const handleFileSelected = async (jsonData, callback) => {
export const handleFileSelected = async jsonData => {
try {
const response = await fetch('/api/presets', {
const response = await axios({
url: '/api/presets',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData),
withCredentials: true,
data: JSON.stringify(jsonData)
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
callback();
// if (!response.ok) {
// throw new Error(`Error: ${response.statusText}`);
// }
console.log(response);
return response.data;
} catch (error) {
console.error('Error uploading the preset:', error);
}