Skip to content

Commit

Permalink
File upload robustness (#956)
Browse files Browse the repository at this point in the history
Fixes issues uploading multiple files manually
  • Loading branch information
srimanachanta committed Oct 17, 2023
1 parent cd83e22 commit 1aa6bc8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions photon-client/src/components/settings/DeviceControlCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ const offlineUpdate = ref();
const openOfflineUpdatePrompt = () => {
offlineUpdate.value.click();
};
const handleOfflineUpdate = (payload: Event) => {
const handleOfflineUpdate = (payload: Event & { target: (EventTarget & HTMLInputElement) | null }) => {
if (payload.target === null || !payload.target.files) return;
const formData = new FormData();
formData.append("jarData", payload.target.files[0]);
useStateStore().showSnackbarMessage({
message: "New Software Upload in Progress...",
color: "secondary",
timeout: -1
});
const formData = new FormData();
if (payload.target == null || !payload.target?.files) return;
const files: FileList = payload.target.files as FileList;
formData.append("jarData", files[0]);
axios
.post("/utils/offlineUpdate", formData, {
headers: { "Content-Type": "multipart/form-data" },
Expand Down Expand Up @@ -138,21 +137,17 @@ enum ImportType {
HardwareSettings,
NetworkConfig
}
const showImportDialog = ref(false);
const importType = ref<ImportType | number>(-1);
const importFile = ref(null);
const importFile = ref<File | null>(null);
const handleSettingsImport = () => {
if (importType.value === -1 || importFile.value === null) return;
const formData = new FormData();
formData.append("data", importFile.value);
let settingsEndpoint;
let settingsEndpoint: string;
switch (importType.value) {
case ImportType.AllSettings:
settingsEndpoint = "";
break;
case ImportType.HardwareConfig:
settingsEndpoint = "/hardwareConfig";
break;
Expand All @@ -162,6 +157,10 @@ const handleSettingsImport = () => {
case ImportType.NetworkConfig:
settingsEndpoint = "/networkConfig";
break;
default:
case ImportType.AllSettings:
settingsEndpoint = "";
break;
}
axios
Expand Down Expand Up @@ -245,21 +244,22 @@ const handleSettingsImport = () => {
<v-card-title>Import Settings</v-card-title>
<v-card-text>
Upload and apply previously saved or exported PhotonVision settings to this device
<v-row class="mt-6 ml-4">
<v-row class="mt-6 ml-4 mr-8">
<cv-select
v-model="importType"
label="Type"
tooltip="Select the type of settings file you are trying to upload"
:items="['All Settings', 'Hardware Config', 'Hardware Settings', 'Network Config']"
:select-cols="10"
style="width: 100%"
/>
</v-row>
<v-row class="mt-6 ml-4 mr-8">
<v-file-input
v-model="importFile"
:disabled="importType === -1"
:error-messages="importType === -1 ? 'Settings type not selected' : ''"
:accept="importType === ImportType.AllSettings ? '.zip' : '.json'"
@change="(file) => (importFile = file)"
/>
</v-row>
<v-row
Expand Down

0 comments on commit 1aa6bc8

Please sign in to comment.