Skip to content

Commit

Permalink
directory upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha committed Mar 1, 2022
1 parent 7de550d commit b6d8952
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion html/management_DE.html
Expand Up @@ -243,7 +243,8 @@
<div class="input-group">
<span class="form-control" id="uploaded_file_text"></span>
<span class="input-group-btn">
<span class="btn btn-secondary" onclick="$(this).parent().find('input[type=file]').click();">Browse</span>
<span class="btn btn-secondary" onclick="let input = $(this).parent().find('input[type=file]')[0]; input.webkitdirectory=false; input.click();">Dateien</span>
<span class="btn btn-secondary" onclick="let input = $(this).parent().find('input[type=file]')[0]; input.webkitdirectory=true; input.click();">Ordner</span>
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').submit();">Upload</span>
<input name="uploaded_file" id ="uploaded_file" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());" style="display: none;" type="file" multiple>
</span>
Expand Down
3 changes: 2 additions & 1 deletion src/HTMLmanagement_DE.h
Expand Up @@ -243,7 +243,8 @@ static const char management_HTML[] PROGMEM = "<!DOCTYPE html>\
<div class=\"input-group\">\
<span class=\"form-control\" id=\"uploaded_file_text\"></span>\
<span class=\"input-group-btn\">\
<span class=\"btn btn-secondary\" onclick=\"$(this).parent().find('input[type=file]').click();\">Browse</span>\
<span class=\"btn btn-secondary\" onclick=\"let input = $(this).parent().find('input[type=file]')[0]; input.webkitdirectory=false; input.click();\">Dateien</span>\
<span class=\"btn btn-secondary\" onclick=\"let input = $(this).parent().find('input[type=file]')[0]; input.webkitdirectory=true; input.click();\">Ordner</span>\
<span class=\"btn btn-primary\" onclick=\"$(this).parent().find('input[type=file]').submit();\">Upload</span>\
<input name=\"uploaded_file\" id =\"uploaded_file\" onchange=\"$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());\" style=\"display: none;\" type=\"file\" multiple>\
</span>\
Expand Down
19 changes: 19 additions & 0 deletions src/Web.cpp
Expand Up @@ -672,6 +672,22 @@ void onWebsocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsE
}
}

void explorerCreateParentDirectories(const char* filePath) {
char tmpPath[MAX_FILEPATH_LENTGH];
char *rest;

rest = strchr(filePath, '/');
while (rest) {
if (rest-filePath != 0){
memcpy(tmpPath, filePath, rest-filePath);
tmpPath[rest-filePath] = '\0';
printf("creating dir \"%s\"\n", tmpPath);
gFSystem.mkdir(tmpPath);
}
rest = strchr(rest+1, '/');
}
}

// Handles file upload request from the explorer
// requires a GET parameter path, as directory path to the file
void explorerHandleFileUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
Expand All @@ -695,6 +711,9 @@ void explorerHandleFileUpload(AsyncWebServerRequest *request, String filename, s
Log_Println(Log_Buffer, LOGLEVEL_INFO);
Web_DeleteCachefile(utf8FilePath.c_str());

// Create Parent directories
explorerCreateParentDirectories(utf8FilePath.c_str());

// Create Ringbuffer for upload
if (explorerFileUploadRingBuffer == NULL) {
explorerFileUploadRingBuffer = xRingbufferCreate(8192, RINGBUF_TYPE_BYTEBUF);
Expand Down
2 changes: 1 addition & 1 deletion src/revision.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_H__
#define __REVISION_H__
constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20220228-1";
constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20220301-1";
#endif

0 comments on commit b6d8952

Please sign in to comment.