Fix recursive delete, add upload labels and progress
This commit is contained in:
parent
b6e24230cf
commit
3493be7757
@ -16,9 +16,10 @@
|
|||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
<hr>
|
<hr>
|
||||||
<input type="file" id="files" multiple>
|
<label>📄 <input type="file" id="files" multiple></label>
|
||||||
<input type="file" id="dirs" multiple webkitdirectory>
|
<label for="dirs">📁 <input type="file" id="dirs" multiple webkitdirectory></label>
|
||||||
<button type="submit" id="upload">Upload</button>
|
<button type="submit" id="upload">Upload</button>
|
||||||
|
<label>Upload progress:<progress value="0"></progress></label>
|
||||||
<hr>
|
<hr>
|
||||||
+📁 <input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
|
+📁 <input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@ -149,7 +149,10 @@ async function mkdir(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function upload(e) {
|
async function upload(e) {
|
||||||
|
let progress = document.querySelector("progress");
|
||||||
let made_dirs = new Set();
|
let made_dirs = new Set();
|
||||||
|
progress.max = files.files.length + dirs.files.length;
|
||||||
|
progress.value = 0;
|
||||||
for (const file of [...files.files, ...dirs.files]) {
|
for (const file of [...files.files, ...dirs.files]) {
|
||||||
let file_name = file.name;
|
let file_name = file.name;
|
||||||
if (file.webkitRelativePath) {
|
if (file.webkitRelativePath) {
|
||||||
@ -177,9 +180,11 @@ async function upload(e) {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
refresh_list();
|
refresh_list();
|
||||||
}
|
}
|
||||||
|
progress.value += 1;
|
||||||
}
|
}
|
||||||
files.value = "";
|
files.value = "";
|
||||||
dirs.value = "";
|
dirs.value = "";
|
||||||
|
progress.value = 0;
|
||||||
upload_button.disabled = true;
|
upload_button.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
// Copied from ble file_transfer.c. We should share it.
|
||||||
STATIC FRESULT _delete_directory_contents(FATFS *fs, const TCHAR *path) {
|
STATIC FRESULT _delete_directory_contents(FATFS *fs, const TCHAR *path) {
|
||||||
FF_DIR dir;
|
FF_DIR dir;
|
||||||
FRESULT res = f_opendir(fs, &dir, path);
|
|
||||||
FILINFO file_info;
|
FILINFO file_info;
|
||||||
// Check the stack since we're putting paths on it.
|
// Check the stack since we're putting paths on it.
|
||||||
if (mp_stack_usage() >= MP_STATE_THREAD(stack_limit)) {
|
if (mp_stack_usage() >= MP_STATE_THREAD(stack_limit)) {
|
||||||
return FR_INT_ERR;
|
return FR_INT_ERR;
|
||||||
}
|
}
|
||||||
|
FRESULT res = FR_OK;
|
||||||
while (res == FR_OK) {
|
while (res == FR_OK) {
|
||||||
|
res = f_opendir(fs, &dir, path);
|
||||||
|
if (res != FR_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
res = f_readdir(&dir, &file_info);
|
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') {
|
if (res != FR_OK || file_info.fname[0] == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user