Skip to content

Commit 5809007

Browse files
committed
workaround(Upload): utf8 file correctly parsed now
1 parent 3fbb9a9 commit 5809007

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

components/Gestion/ImportForm.vue

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ValidationObserver ref="observer" tag="form"
1212
@submit.prevent="validateBeforeSubmit">
1313
<ValidationProvider tag="div"
14-
name="archive zip"
14+
name="fichier json"
1515
rules="mimes:application/json"
1616
ref="fileObserver"
1717
v-slot="{ errors }">
@@ -50,8 +50,6 @@
5050
import Icon from "~/components/Symbols/Icon.vue";
5151
import CustomSelect from "~/components/Input/CustomSelect.vue";
5252
53-
const debounce = require('lodash.debounce');
54-
5553
@Component({
5654
components: {CustomSelect, ValidationObserver, ValidationProvider, Icon}
5755
})
@@ -147,37 +145,42 @@
147145
const file: File | null = this.file();
148146
149147
if (file !== null) {
150-
151-
reader.readAsText(file, "UTF-8");
152-
reader.onload = async (evt: any) => {
153-
const text: string = evt.target.result;
154-
try {
155-
this.$nuxt.$loading.start();
156-
await this.$axios.$post("/api/bulk/create_exercises", JSON.parse(text));
157-
this.$displaySuccess("L'importation s'est correctement déroulée.");
158-
} catch (e) {
159-
const error = e as AxiosError;
160-
161-
if (error.response) {
162-
const status = error.response.status;
163-
164-
if (status === 400) {
165-
this.$displayWarning("Votre fichier ne possède pas le bon format.")
166-
} else if (status === 401) {
167-
this.$displayWarning("Vous n'êtes pas autorisé à effectuer cette action.")
168-
} else if (status === 500) {
169-
this.$displayError("Une erreur est survenue depuis nos serveurs.")
148+
reader.onloadend = async () => {
149+
if (reader.result !== null) {
150+
const buffer = reader.result as ArrayBuffer;
151+
const string: string = new TextDecoder().decode(buffer);
152+
153+
try {
154+
this.$nuxt.$loading.start();
155+
await this.$axios.$post("/api/bulk/create_exercises", JSON.parse(string));
156+
this.$displaySuccess("L'importation s'est correctement déroulée.");
157+
} catch (e) {
158+
const error = e as AxiosError;
159+
160+
if (error.response) {
161+
const status = error.response.status;
162+
163+
if (status === 400) {
164+
this.$displayWarning("Votre fichier ne possède pas le bon format.")
165+
} else if (status === 401) {
166+
this.$displayWarning("Vous n'êtes pas autorisé à effectuer cette action.")
167+
} else if (status === 500) {
168+
this.$displayError("Une erreur est survenue depuis nos serveurs.")
169+
} else {
170+
this.$displayError("Une erreur est survenue.")
171+
}
170172
} else {
171173
this.$displayError("Une erreur est survenue.")
172174
}
173-
} else {
174-
this.$displayError("Une erreur est survenue.")
175+
} finally {
176+
this.$nuxt.$loading.finish();
175177
}
176178
177-
} finally {
178-
this.$nuxt.$loading.finish();
179179
}
180180
};
181+
182+
reader.readAsArrayBuffer(file);
183+
181184
}
182185
183186
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)