From 897ed58e148ea7c98f82fb9519a2317c2f17fd7c Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 9 Apr 2023 18:31:25 +0200 Subject: [PATCH] Fixes for issue #10, cannot download any file from local FS but preferences.json. --- commands_v3.c | 8 ++++---- fs_handlers.c | 14 ++++++++++---- server.c | 7 ++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/commands_v3.c b/commands_v3.c index ac6f9b3..7b3b50b 100644 --- a/commands_v3.c +++ b/commands_v3.c @@ -1496,10 +1496,10 @@ static status_code_t get_firmware_spec (const struct webui_cmd_binding *command, network_info_t *network = networking_get_info(); vfs_drive_t *sdfs = fs_get_sd_drive(), *flashfs = fs_get_flash_drive(); -// strcpy(hostpath, webui_get_sys_path()); -// if(*hostpath == '\0') - strcpy(hostpath, sdfs && flashfs == NULL ? "/www" : "/"); -// vfs_fixpath(hostpath); + strcpy(hostpath, webui_get_sys_path()); + if(*hostpath == '\0') + strcpy(hostpath, sdfs && flashfs == NULL ? "/www" : "/"); + vfs_fixpath(hostpath); for(idx = 0; idx < N_AXIS; idx++) axisletters[idx] = *axis_letter[idx]; diff --git a/fs_handlers.c b/fs_handlers.c index 9f85131..8b2d063 100644 --- a/fs_handlers.c +++ b/fs_handlers.c @@ -5,7 +5,7 @@ Part of grblHAL - Copyright (c) 2020-2022 Terje Io + Copyright (c) 2020-2023 Terje Io Some parts of the code is based on test code by francoiscolas https://github.com/francoiscolas/multipart-parser/blob/master/tests.cpp @@ -227,9 +227,13 @@ const char *fs_action_handler (http_request_t *request, vfs_drive_t *drive) // return ESP_OK; *status = *path = '\0'; - strcpy(path, drive->path); http_get_param_value(request, "path", filename, sizeof(filename)); + if(strncmp(filename, drive->path, strlen(drive->path))) + strcpy(path, drive->path); + else + strcpy(path, "/"); + strcat(path, *filename == '/' ? filename + 1 : filename); http_get_param_value(request, "filename", filename, sizeof(filename)); @@ -397,10 +401,12 @@ static void fs_on_upload_name_parsed (char *name, void *data) char *drive_path = (char *)data; size_t len = strlen(name), plen = strlen(drive_path); - if(*name == '/') + if(!strncmp(name, drive_path, plen)) + plen = 0; + else if(*name == '/') plen--; - if(len + plen <= HTTP_UPLOAD_MAX_PATHLENGTH) { + if(plen && len + plen <= HTTP_UPLOAD_MAX_PATHLENGTH) { memmove(name + plen, name, len + 1); memcpy(name, drive_path, plen); } diff --git a/server.c b/server.c index ce6e69a..7d6abc6 100644 --- a/server.c +++ b/server.c @@ -758,6 +758,11 @@ const char *file_redirect (http_request_t *request, const char *uri, vfs_file_t else if(!strcmp(uri, "/ap_login.html")) file_search(path, uri, file, mode); #endif + else if(strlookup(".gz", uri, '.') == -1) { + if((*file = vfs_open(strcat(uri, ".gz"), mode)) == NULL) + *(strchr(uri, '\0') - 3) = '\0'; + } + return uri; } @@ -766,7 +771,7 @@ static void webui_options (bool newopt) on_report_options(newopt); if(!newopt) - hal.stream.write("[PLUGIN:WebUI v0.14]" ASCII_EOL); + hal.stream.write("[PLUGIN:WebUI v0.15]" ASCII_EOL); } void webui_init (void)