Fix recursive delete, add upload labels and progress

This commit is contained in:
Scott Shawcroft 2022-08-16 17:03:09 -07:00
parent b6e24230cf
commit 3493be7757
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
3 changed files with 16 additions and 3 deletions

View File

@ -16,9 +16,10 @@
<tbody></tbody>
</table>
<hr>
<input type="file" id="files" multiple>
<input type="file" id="dirs" multiple webkitdirectory>
<label>📄 <input type="file" id="files" multiple></label>
<label for="dirs">📁 <input type="file" id="dirs" multiple webkitdirectory></label>
<button type="submit" id="upload">Upload</button>
<label>Upload progress:<progress value="0"></progress></label>
<hr>
+📁&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
</body></html>

View File

@ -149,7 +149,10 @@ async function mkdir(e) {
}
async function upload(e) {
let progress = document.querySelector("progress");
let made_dirs = new Set();
progress.max = files.files.length + dirs.files.length;
progress.value = 0;
for (const file of [...files.files, ...dirs.files]) {
let file_name = file.name;
if (file.webkitRelativePath) {
@ -177,9 +180,11 @@ async function upload(e) {
if (response.ok) {
refresh_list();
}
progress.value += 1;
}
files.value = "";
dirs.value = "";
progress.value = 0;
upload_button.disabled = true;
}

View File

@ -766,14 +766,21 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
// Copied from ble file_transfer.c. We should share it.
STATIC FRESULT _delete_directory_contents(FATFS *fs, const TCHAR *path) {
FF_DIR dir;
FRESULT res = f_opendir(fs, &dir, path);
FILINFO file_info;
// Check the stack since we're putting paths on it.
if (mp_stack_usage() >= MP_STATE_THREAD(stack_limit)) {
return FR_INT_ERR;
}
FRESULT res = FR_OK;
while (res == FR_OK) {
res = f_opendir(fs, &dir, path);
if (res != FR_OK) {
break;
}
res = f_readdir(&dir, &file_info);
// We close and reopen the directory every time since we're deleting
// entries and it may invalidate the directory handle.
f_closedir(&dir);
if (res != FR_OK || file_info.fname[0] == '\0') {
break;
}