Skip to content

Commit

Permalink
Fixes for issue #10, cannot download any file from local FS but prefe…
Browse files Browse the repository at this point in the history
…rences.json.
  • Loading branch information
terjeio committed Apr 9, 2023
1 parent d18a9cd commit 897ed58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions commands_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
14 changes: 10 additions & 4 deletions fs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down

0 comments on commit 897ed58

Please sign in to comment.